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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
「ミスを許さない手順書」を作ってみた 〜 個人的にはこれ以上できることはあまりなさそう/20260827-ssmjp-operation-procedure-update
opelab
17
17k
tamachi.goを支える技術
rymiyamoto
0
120
AI駆動開発を組織で促すために
lycorptech_jp
PRO
7
9.1k
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
12
87k
When Token Pruning is Worse than Random: Understanding Visual Token Information in VLLMs
sansantech
PRO
0
210
Bet AI Day 2026丨Agentは、「金融」という巨大産業の何を変えられるのか
layerx
PRO
0
230
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
20k
AI駆動開発はどこまで来たのか? ファインディの最新実態調査で読み解く現在地 Devin Con Tokyo
akiratom
4
2.2k
Genie Code ワークショップ 基礎編 / Genie-Code-Workshop-fundamental
databricksjapan
PRO
0
240
markdown-poster Introduction
kazamori
0
450
EUDIWの枠組みを出発点に民間エコシステムの在り方を考える(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
420
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
320
Building an army of robots
kneath
306
46k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Six Lessons from altMBA
skipperchong
29
4.5k
Technical Leadership for Architectural Decision Making
baasie
3
550
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
480
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
400
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
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Խ༧ఆ