Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
大規模Mastodonインスタンスを運用するコツ / Inside Pawoo Mastodo...
Search
Harukasan
PRO
April 27, 2017
Technology
0
3.1k
大規模Mastodonインスタンスを運用するコツ / Inside Pawoo Mastodon infrastructure
実際運用してみてわかった、大規模Mastodonインスタンスを運用するコツ
2017-04-25 at pixiv night!
Harukasan
PRO
April 27, 2017
Tweet
Share
More Decks by Harukasan
See All by Harukasan
pixivを支える技術 / 技育CAMPアカデミア
harukasan
PRO
3
380
20240401 新卒研修 - ピクシブにおける技術領域
harukasan
PRO
1
690
ピクシブのコンテンツ配信基盤技術 / pixiv TECH SALON
harukasan
PRO
5
5.4k
Goにおける画像ファイル処理 / golang.tokyo #19
harukasan
PRO
7
6.5k
WebRTC動画をトランスコードする / Transcoding video streams from WebRTC
harukasan
PRO
5
1.5k
ImageFluxを支えるリモート開発 / 20171202
harukasan
PRO
2
1.8k
YAPC::Fukuoka 前夜祭LT / Yet Another Pawoo Commit logs
harukasan
PRO
0
2.9k
YAPC::Fukuoka lunch session
harukasan
PRO
1
3k
マストドン会議: Pawoo / Mastodon Kaigi2
harukasan
PRO
2
430
Other Decks in Technology
See All in Technology
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
760
TypeScript、上達の瞬間
sadnessojisan
46
13k
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
540
Taming you application's environments
salaboy
0
190
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
110
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Building an army of robots
kneath
302
43k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Embracing the Ebb and Flow
colly
84
4.5k
Thoughts on Productivity
jonyablonski
67
4.3k
Code Review Best Practice
trishagee
64
17k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Transcript
@harukasan / Shunsuke Michii ࣮ࡍӡ༻ͯ͠ΈͯΘ͔ͬͨɺେن.BTUPEPOΠϯελϯεΛӡ༻͢Δίπ
@Harukasan Shunsuke MICHII Lead engineer of pixiv Inc., Product manager
of ImageFlux, Infrastructure engineer, Kibana, Gopher
None
࣮ࡍӡ༻ͯ͠ΈͯΘ͔ͬͨɺେن.BTUPEPOΠϯελϯεΛӡ༻͢Δίπ
None
Mastodon
͍͖ͭͬ͞v1.2.2Λͩͨ͠
github.com/pixiv/mastodon:pawoo
Ruby on Rails node.js PostgreSQL Redis SendGrid Sidekiq ΫϥΠΞϯτ Websocket
(streaming) HTTP SMTP ϞμϯͳRuby on RailsΞϓϦέʔγϣϯ nginx
Ruby on Rails node.js PostgreSQL Redis SendGrid Sidekiq ΫϥΠΞϯτ Websocket
(streaming) HTTP SMTP ϞμϯͳRuby on RailsΞϓϦέʔγϣϯ nginx RESTͬΆ͍API
Ruby on Rails node.js PostgreSQL Redis SendGrid Sidekiq ΫϥΠΞϯτ Websocket
(streaming) HTTP SMTP ϞμϯͳRuby on RailsΞϓϦέʔγϣϯ nginx RESTͬΆ͍API ετϦʔϛϯάAPI
10࣌ؒͰϦϦʔε
Pawooͷߏ
None
AWSͰγϡοͱΔ • ͕࣌ؒͳ͍͚Ͳ࠷༏ઌ҆ఆੑ • RDS/ElasticaceͷϚϧνAZߏ • ϝσΟΞS3ʹอଘ • EC2ฒͯALBͰϩʔυόϥϯε •
CloudFrontͰྲྀ͢ʢ͏Ίͨʣ • ظؒݶఆαΠτΛཱͯΔ࣌ͷϊϋΛྲྀ༻
ΠϯελϯεΛฒΔ • ͯ͢ͷΠϯελϯεಉҰߏ • γϡοͱͭͬͯ͘AMIͰ૿͢ • ԣʹฒͯεέʔϧΞτ • ͦͷ͏ͪΦʔτεέʔϦϯά͍ͨ͠
Docker͔Β͕͢ • શ෦systemdαʔϏεʹஔ͖͑ͨ • ͦͷ··͏ͷͪΐͬͱ͍͜͠ͱ͕ଟ͍ • σϓϩΠͷ͜ͱΒͳΜΒߟ͍͑ͯΔͱͪΐͬͱ༨༟͕ͳ͍ • DockerͰ͙͢ΔͳΒϗοτσϓϩΠͱ͔ϦιʔεͷΈΛ ͋Β͔͡Ί༻ҙ͓ͯ͘͠ඞཁ͕͋Γͦ͏ʢͦͷ͏ͪΓ͍ͨʣ
ͦͷͷ͏ͪʹϦϦʔε͞Ε͕ͨ ͙͢ʹΤϥʔΛฦ͠͡ΊΔ ʢ͜͜ΒลͰνϟοτΛݟ࢝ΊΔʣ
nginx • ϦΫΤετόοϑΝϦϯάͷͨΊʹPumaͷલʹnginxΛ͓͘ • Τϥʔ͕ग़͍ͯͨͷͰͳ͓ͨ͠ • worker_rlimit_nofile: limitΛ૿͓ͯ͘͠ • worker_connections:
ίωΫγϣϯͨ͘͞ΜΔͷͰ • ϩάϩʔςʔτͷઃఆ͕ೖͬͯͳ͔ͬͨͷͰೖΕͨ • όϥϯγϯάEC2ͷnginx͡Όͳͯ͘ALBͰΔ
ৄ͘͜͠ͷຊʹ
PostgreSQL • PostgreSQLίωΫγϣϯ͝ͱʹfork͢Δ ʢฐࣾͯ͢MySQLͩͬͨͷͰݟͳ͠ʣ • ίωΫγϣϯϓʔϧΛ͏·͍۩߹ͷʹઃఆ͢Δ • ΠϯελϯεΛεέʔϧΞοϓͯ͠ରԠ • ίʔυʹ࠷దԽΛೖΕͯΠϯελϯεαΠζখͨ͘͞͠Γͨ͠
• Մ༻ੑͱόοΫΞοϓRDSʹ͓ͤ • PgBouncerͬͨํ͕͍͍͔ʁͱࢥ͍ͳ͕Βාͯͬͯ͘ͳ͍
͜͜ͰεέʔϧΞοϓ
None
ݟٻΉ
Ruby on Rails node.js PostgreSQL Redis SendGrid Sidekiq ΫϥΠΞϯτ Websocket
(streaming) HTTP SMTP ϞμϯͳRuby on RailsΞϓϦέʔγϣϯ nginx
Ruby on Rails node.js PostgreSQL Redis SendGrid Sidekiq ΫϥΠΞϯτ Websocket
(streaming) HTTP SMTP nginx ϢʔβʔΠϯλʔϑΣʔε ϞμϯͳRuby on RailsΞϓϦέʔγϣϯ
Ruby on Rails node.js PostgreSQL Redis SendGrid Sidekiq ΫϥΠΞϯτ Websocket
(streaming) HTTP SMTP nginx ϞμϯͳRuby on RailsΞϓϦέʔγϣϯ ϝΠϯϩδοΫ
Sidekiq • MastodonͷϝοηʔδύογϯάSidekiqͰߦΘΕΔ • τΡʔτͷ৴ • ετϦʔϛϯά • ϦϞʔτΠϯελϯεͷ৴ •
1τΡʔτ͝ͱʹϑΥϩϫʔͷ͚ͩenqueue͞ΕΔ • ϑΥϩϫʔ͕ଟ͍Ϣʔβʔͩͱ͍
ීஈͷΩϡʔͷ༷ࢠʢͪΐͬͱલʣ
ͨ·ʹ͜͏ͳΔ
ͨ·ʹ͜͏ͳΔ
Ωϡʔͷछྨ default pull push mail • ΄͔ͷશ෦ͷδϣϒ • ϦϞʔτΠϯελϯεͷ৴ •
ϝʔϧͷૹ৴
Sidekiq٧·Δ • σϑΥϧτͩͱͯ͢ͷΩϡʔΛ̍ͭͷSidekiqϓϩηεͰॲཧ͢Δ • ϦϞʔτΠϯελϯε͕٧·Δͱpull/pushͷΩϡʔ͕٧·Δ • pull/pushͷ͍ͤͰλΠϜϥΠϯ͕Ԇ͢Δʂ • ͜ͷ··ͩͱαʔϏεͱͯ͠ऴΘͬͯ͠·͏ͷͰɺϓϩηεΛ͚Δ •
Sidekiq1ϓϩηεͰ1ίΞʢ100%ʣ·Ͱ͔ͬͯ͘͠Εͳ͍ • ϓϩηεΛͨ͘͞ΜཱͯͯΧόʔ
ίϚϯυϥΠϯҾͰࢦఆ͢Δ͚ͩ [Service] Type=simple User=mastodon WorkingDirectory=/home/mastodon/live Environment="RAILS_ENV=production" Environment="DB_POOL=40" ExecStart=/usr/local/rbenv/shims/bundle exec sidekiq
-c 40 -q default TimeoutSec=15 Restart=always
SidekiqϓϩηεΛ͚Δ sidekiq-default-1.service sidekiq-default-2.service sidekiq-default-3.service sidekiq-pullpush.service sidekiq-mail.service 1Πϯελϯεʹ͜Εཱ͚ͩͯͯΔɿ σϑΥϧτ͚ͩͰ1,000εϨουҎ্ 40 40
40 10 5 εϨου
Sidekiqͷϓϩηεը໘͕ ͍ͩͿݟͮΒ͍
Sidekiq٧·Δͷ՝ • ϦϞʔτΠϯελϯε͕٧·Δͱ૬มΘΒͣpull/push͕٧·Δ • ϓϩηεΛཱͯͯΧόʔͯ͠Δ͚Ͳɺ΄͔ͷΠϯελϯε͔Β͢Δͱ ٸʹϦΫΤετ͕૿͑ͯͭΒͦ͏…… • ͍Πϯελϯεͱ͔େنΠϯελϯεͷॲཧΛͲ͏ʹ͔͍ͨ͠ • ͦͦτΡʔτ͋ͨΓͷδϣϒ͕N+1ʹͳͬͯΔͷ͕͍
ղܾͯ͠ͳ͍͚Ͳ·ͱΊ • AWSͬͯγϡοͱཱͯͯӡ༻։࢝ • ϚετυϯͷϝΠϯSidekiqδϣϒ • SidekiqͷΩϡʔΛ͏·͚͘͞ΔͱΑ͍ • SidekiqϓϩηεΛεϙοτΠϯελϯεͰ૿͢Α͏ʹ͍ͨ͠ •
Ͳ͔ͬͪͱ͍͏ͱ࠷దԽͨ͠ํ͕Αͦ͞͏