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
High Performance Backend For Mercari
Search
Tatsuhiko Kubo
March 21, 2015
Technology
25k
28
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
High Performance Backend For Mercari
Tatsuhiko Kubo
March 21, 2015
More Decks by Tatsuhiko Kubo
See All by Tatsuhiko Kubo
Mackerel in さくらのクラウド
cubicdaiya
1
1k
Handling a tremendous amount of images with Fastly / Yamagoya Traverse 2020
cubicdaiya
2
1.6k
System Integration with Fastly
cubicdaiya
0
680
実例で学ぶ画像最適化集 with ImageFlux / ImageFlux meetup#2
cubicdaiya
4
20k
Software Engineer, Infrastructure
cubicdaiya
4
3.3k
High Performance Count Up!
cubicdaiya
0
430
ImageFluxを利用した画像配信の最適化 / ImageFlux meetup 201801
cubicdaiya
0
3.2k
Building high performance push notification server in Go
cubicdaiya
5
3.4k
メルカリのデータ分析基盤 / mercari data analysis infrastructure
cubicdaiya
11
12k
Other Decks in Technology
See All in Technology
サイバー捜査員研修(後半)
nomizone
1
850
20260807_第6回_関東kaggler会LT_claw系bot xangiと始める、"寂しくない" kaggle
sugupoko
0
260
ホームラボ紹介
y_sera15
0
150
Genie Codeハンズオン基礎編
taka_aki
1
110
OSPN.JPバージョンアップ作業進捗のご報告 / 20260801-osc26kyoto
akkiesoft
0
470
Service Connect 上のサービスに ECS Service の外側から到達できなかった話
ota1022
1
220
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
モダンフロントエンド 開発研修
recruitengineers
PRO
4
610
【CEDEC2026】ゲームシナリオライターを支援するAIツール開発の実践 ― 設計とプロンプトの工夫 ―
cygames
PRO
1
790
20260608_Codexの可能性_ノンプログラマー向け_大城追記
doradora09
PRO
0
790
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
210
QAエンジニア起点で進める、SmartHRにおける信頼性向上について
kaomi_wombat
1
130
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
430
The SEO Collaboration Effect
kristinabergwall1
1
520
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
400
The Curse of the Amulet
leimatthew05
2
14k
Balancing Empowerment & Direction
lara
6
1.2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
200
Code Reviewing Like a Champion
maltzj
528
40k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
25k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
380
Evolving SEO for Evolving Search Engines
ryanjones
0
250
Transcript
High Performance Backend For Mercari Tatsuhiko Kubo@cubicdaiya ࣌Ӎࡇ@2015/03/21
ࣗݾհ • ٱอୡ(Tatsuhiko Kubo) • bokko@cubicdaiya • Software Engineer in
Infrastructure Engineering • Mercari, Inc.
OSS࡞ͬͨΓίϯτϦϏϡʔτͨ͠Γ
None
None
ओཁKPIσʔλ μϯϩʔυ ߪೖֹۚ ग़ 1000ສDLಥഁ ݄ؒेԯԁ 1ेສҎ্
ͷେࡶͳγεςϜߏ ͘͞ΒͱAWSͷϋΠϒϦου
ৄͪ͘͜͠Β http://bit.ly/18Os1Dc
Agenda • High performance API server with PHP!!! • High
performance networking with nginx • High performance Application with Go
Agenda • High performance API server with PHP!!! • High
performance networking with nginx • High performance Application with Go
ͱ͋ΔAPIαʔόͷฏۉϨεϙϯελΠϜ(1ؒ) ϐʔΫ࣌Ͱ30msʂ
࣮ࡍʹͬͱ࣮ߦ࣌ؒͷ͍API͋Γ·͢ e.g. ߪೖτϥϯβΫγϣϯ
Why API server very fast? • ܰྔͰߴͳPHPϑϨʔϜϫʔΫ(DietCake) • Ωϟογϡ •
ඇಉظॲཧ • ۚͷؙMySQL on ioDrive • ͦͦϨεϙϯε͕JSON onlyͳͷͰ͍ܰ
http://dietcake.github.io/
None
Ωϟογϡ • memcachedͱRedisΛซ༻ • ௨ৗͷΩϟογϡجຊతʹmemcached • RedisϦετܕ͕ޮՌతͳՕॴ͕͋ͬͯͦ͜ Ͱར༻͍ͯ͠Δ • ͦͷલஈͰ͞ΒʹmemcachedͰΩϟογϡ
ΩϟογϡͷΥʔϜΞοϓ • ΞΫηε͕ଟ͍ & ߋ৽ස͕ߴ͍ & Ωϟογϡͷύλʔϯ͕ଟ͍ & ݁ߏॏ͍API •
Ϣʔβ͔ΒͷΞΫηεͷࡍʹΩϟογϡΛੜͯ͠ ޮՌ͕ബ͍ • ཪͰͻͨ͢ΒΩϟογϡΛੜ͢ΔσʔϞϯΛಈ͔͢ • ޙड़
ඇಉظॲཧ • APIαʔόͳΔͰϨεϙϯεΛฦ͍ͨ͠ • ͔͠͠ɺதʹͲ͏ͯ͠ॏ͍ॲཧ͕͋Δˣ • ΩϟογϡɺݕࡧΠϯσοΫεͷߋ৽ • ϝʔϧɺSMSͷૹ৴ •
δϣϒΩϡʔ&ϫʔΧʔͰඇಉظʹॲཧ͢Δ
δϣϒΩϡʔͱϫʔΧʔ • δϣϒΩϡʔQ4M • ϫʔΧʔphp-Parallel-Prefork • PHPͰpreforkσʔϞϯ͕؆୯ʹ࡞ΕΔ
None
Agenda • High performance API server with PHP!!! • High
performance networking with nginx • High performance Application with Go
OHJOY
ϝϧΧϦʹ͓͚Δnginxͷओͳׂ • APIϦΫΤετͷϩʔυόϥϯε • SSLλʔϛωʔγϣϯ & SPDYήʔτΣΠ • େྔಉ࣌ଓͷඋ͑(C10K) •
HTTPS௨৴ͷߴԽ • TLS Session (Cache|Tickets)
TLS Session Cache • TLSϋϯυγΣΠΫͷηογϣϯใΛαʔόʹ Ωϟογϡ • nginxͰڞ༗ϝϞϦ্ʹΩϟογϡ͞ΕΔ • ࣍ճͷTLSϋϯυγΣΠΫΛলུ
• CPUϦιʔεͷݮϨΠςϯγղফͷޮՌ͕͋Δ
TLS Session Cache with nginx
TLS Session Tickets • ҉߸Խͨ͠ηογϣϯใ(νέοτ)ΛΫϥ ΠΞϯτʹ͢ • νέοτΛݩʹTLSηογϣϯΛ࠶։ • HTTPSαʔόෳͰηογϣϯΩϟογϡ
Λڞ༗Ͱ͖Δ • αϙʔτ͍ͯ͠Δ͕গͳ͍ͷ͕
TLS Session Tickets with nginx
SPDY • ࠷৽ͷiOSAndroidͰαʔό͕ରԠͯ͠ ͍ΕࣗಈతʹSPDY/3.1͕ར༻͞ΕΔ • ΫϥΠΞϯτଆͰରԠ͠ͳͯ͘Α͍
SPDY with nginx
TLS Session (Cache|Tickets) ಋೖλΠϛϯά
TLS Session (Cache|Tickets) ಋೖλΠϛϯά
SPDY 41%:ಋೖͨ͠ͷϐʔΫ
Agenda • High performance API server with PHP!!! • High
performance networking with nginx • High performance Application with Go
mercari.go • ϝϧΧϦͷϝΠϯ։ൃݴޠPHP • ΠϯϑϥνʔϜͩͱGoɺNodeɺRubyɺPerl͍ Ζ͍Ζ(ΈΜͳಘҙ͕ҧ͏) • ࠷ۙͪΐͬͱͨ͠CLIσʔϞϯɺύϑΥʔϚϯ ε͕ཁٻ͞ΕΔίϯϙʔωϯτΛGoͰ։ൃ͢Δػ ձ͕૿͑ͯΔ
mercari.go • nginx-build • cachectl • slackboard • Ϋϩʔζυ •
Gaurun, refreshcache
cɺconsulͬͯΔ͔Β(͑)
ͳ͓ɺόάͬͯΔ༷ ઌि͜ͷόάΛճආ͢Δίʔυॻ͍ͯ·ͨ͠
mercari.go • nginx-build • cachectl • slackboard • Ϋϩʔζυ •
Gaurun, refreshcache
Gaurun • ൚༻ϓογϡ௨αʔό • ࣌ؒͰेɺඦສ݅ͷϓογϡ௨͕Մೳ • HTTPͱJSONΛϕʔεʹͨ͠γϯϓϧͳAPI • ϝϧΧϦͷϓογϡ௨ɺେମGaurunͰஔ ͖͑ͨ
൚༻ϓογϡ௨γεςϜͷΞʔΩςΫνϟ PS CBUDIαʔό
Gaurun HTTP API "1* ղઆ 1045QVTI ϓογϡ௨ϦΫΤετड (&5TUBUHP (PϥϯλΠϜͷ׆ಈঢ়گΛऔಘ (&5TUBUBQQ
෦Ωϡʔ νϟωϧ ͷ༻ྔ ϓογϡͷޭࣦഊͷऔಘ (&5DPOpHBQQ αʔόઃఆ 50.- Λऔಘ
POST /pushͷϦΫΤετϘσΟ
GET /stat/go $ curl -s http://127.0.0.1:1056/stat/go { "time": 1423270089195474419, "go_version":
"go1.4", "go_os": "linux", "go_arch": "amd64", "cpu_num": 24, "goroutine_num": 55, "gomaxprocs": 24, "cgo_call_num": 124016, "memory_alloc": 10309424, "memory_total_alloc": 295474683712, "memory_sys": 25557240, "memory_lookups": 214058, "memory_mallocs": 2118264299, "memory_frees": 2118230111, ɾ ɾ
GET /stat/app $ curl -s http://127.0.0.1:1056/stat/app { "queue_max": 40960, //
෦ΩϡʔͷαΠζ "queue_usage": 0, // ෦Ωϡʔͷ༻ྔ(͙͢ࡹ͚ΔͷͰେମ0) "ios": { "push_success": 31804, // iOSϓογϡ௨ͷޭ "push_error": 17 // iOSϓογϡ௨ͷࣦഊ }, "android": { "push_success": 18683, // Androidϓογϡ௨ͷޭ "push_error": 233 // Androidϓογϡ௨ͷࣦഊ } $
GaurunΛ࣮ߦ͍ͯ͠Δ༷ࢠͰ͢
mercari.go • nginx-build • cachectl • slackboard • Ϋϩʔζυ •
Gaurun, refreshcache
refreshcache • ࠷ॳͷํͰݴͬͯͨಛఆAPIͷϨεϙϯεͷ ΩϟογϡΛੜ͢ΔσʔϞϯ • ҰఆִؒͰฒྻʹ݁ߏͳྔͷHTTPϦΫΤετ ΛૹΓଓ͚Δ • ݩʑRubyͰॻ͔Ε͍ͯͨ(͔ͬͨ)
ݩͷRubyίʔυ Parallel.map(params_list, :in_processes => in_processes) do |params| (தུ) res =
http_request('GET', url, params) (தུ) end.compact params_listͷαΠζ͕େ͖͍ ↓ େྔʹfork͢ΔͷͰॏ͍
GoͰॻ͖ͨ͠ done := make(chan error) size := len(paramCombs.Params) var errors
[]error for i := 0; i < size; i++ { go makeCache(URL, paramCombs.Params[i], done) } for i := 0; i < size; i++ { err := <-done if err != nil { errors = append(errors, err) } }
࣮ߦαʔόͷάϥϑ(CPU) ϦϥΠτͨ͠λΠϛϯά
࣮ߦαʔόͷάϥϑ(LA) ϦϥΠτͨ͠λΠϛϯά
·ͱΊ • ϝϧΧϦͷߴͳόοΫΤϯυͷΈʹ͍ͭͯ ͍͔ͭ͘ղઆ͠·ͨ͠ • ϝΠϯPHP͚ͩͲ࠷ۙGoͷར༻ࣄྫ૿͑ͯΔ • Goૣ͍ɾ͍ɾ͍ܰ • Gaurunͦͷ͏ͪOSSԽ༧ఆ