SlideShare una empresa de Scribd logo
1 de 12
大規模Railsアプリケーションを
バージョンアップするときのハマ
りどころ
河野 那緒
自己紹介
 河野 那緒
 アカツキ新卒2期生(入社4年目)
 サーバーサイドエンジニア(Rails/AWS など)
 新卒の中で初めての子持ち
まえがき
 大規模(高負荷)なWebアプリケーションで起きること…
まえがき
 大規模(高負荷)なWebアプリケーションで起きること…
1台のサーバーでは
どんなに性能が高くても
負荷を受け止めきれない
ActiveRecord
(Rails内蔵ライブラリ)
アプリケーションサーバー
(EC2)
ロード
バランサー
データベース
水平分割/
レプリケーション
で負荷分散
Octopus
Gem
大規模Railsアプリケーションのインフラ基本構成例
大規模になると
ハマりやすい
場所
• アプリケーションの処理ロジックを書きたい!
• ユーザーIDなどの条件に合わせて
データベースの保存先を変えたい!
さらに…
• データベースの構造変更をするときは
全部同時にやってほしい!
• 万一1台のデータベースが止まっても、
関係無い処理が詰まらないようにしたい
→増える要件に合わせて、より根本から
挙動を変えるGemや独自パッチが必要になる
Rails5.2で
ハマった場所
ActiveRecordのMigration
(データベース構造変更処理)の実装が変わった
class Migrator
class MigrationContext
class Migrator
クラスメソッド
- run メソッド
インスタンスメソッド
- run メソッド
インスタンスメソッド
- run メソッド
インスタンスメソッド
- run メソッド
実際に
必要になった
修正箇所
1.Octopus側にバグがある。
データベースを作成するコマンドで、
Railsで必要なテーブル(schema_migrationsなど)
が、1つのデータベースにしか生成されない
→Octopusのライブラリで実装がバージョンアップ
対応が漏れていたので独自パッチ
マイグレーションを最初から実行すると、
Mysql2::Error: Table ‘XXX.schema_migrations’ doesn‘t exist
Rails5.2で
ハマった場所
2.独自パッチがOctopusの実装変更に阻まれる
class Migrator
class MigrationContext
class Migrator
クラスメソッド
- run メソッド
インスタンスメソッド
- run メソッド
インスタンスメソッド
- run メソッド
インスタンスメソッド
- run メソッドOctopusが複数DB対応
のため上書き
並列化のためモンキーパッチも
上書き…
データベースの接続先を共有しあって
いるので競合してしまい…失敗
対処方法
1. MigratorではなくMigrationContextクラスを上書きしたい
→Octopus側の変更を打ち消すためのモンキーパッチも必要
→難易度が高く今後の保守性が大きく低下しそう…
2.Migrator.runメソッドに合わせて、スレッドごとに
Migratorクラスを複製したい
→dupではダメ
→deep_dupでもダメ
オブジェクトが複製不可能な場合、コピーせずそのまま返す罠
→そうとなればコピー&ペースト
(Marshal.dump & Marshal.load)や
まとめ
 大規模なアプリケーションでは複数データベースの
使い分けが要
 本家がデータベースへの接続周りで実装を変えること
が多いので、対応Gemも変更やバグが起きやすい
 さらに高度な要件に応えるため独自パッチも多い。
RailsとOctopus両方の影響を受けるので、
バージョンアップのネックになりやすい。
さいごに
 次のRails6.0では公式に複数データベース対応を予定
 公式対応で嬉しい反面、既存のアプリケーションは大きな変更を伴う
→Octopus Gemとの別れ
→独自パッチ類の書き直し
次は最大の戦いが待っているかもしれない
To Be Continued…?

Más contenido relacionado

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

大規模Railsアプリケーションをバージョンアップするときのハマりどころ