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
980
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.1k
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
MIERUNE JCT 発表資料「宇宙から伊能忠敬ごっこ」
syuchimu
0
190
Claude code Orchestra
ozakiomumkj
3
1k
protovalidate-es を導入してみた
bengo4com
0
150
AgentGatewayを試してみたかった
tkikuchi
0
120
AI活用を推進するために ファインディが下した、一つの小さな決断
starfish719
0
270
チームで実践する AI-DLC 思考の軌跡を残すチェックポイント設計
belongadmin
0
3k
Agentic ERPをどう設計するか ー 受発注エージェントを動かす、現場の知見と設計思想ー
recerqainc
1
1.9k
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
Diagnosing performance problems without the guesswork
elenatanasoiu
0
170
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
4
1.3k
Agentic Web
dynamis
1
180
DevOps Agentで始めるAWS運用 〜フロンティアエージェントが変える運用の現場〜
nyankotaro
1
320
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Context Engineering - Making Every Token Count
addyosmani
9
950
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
160
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
200
Why Our Code Smells
bkeepers
PRO
340
58k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Music & Morning Musume
bryan
47
7.2k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
130
Bash Introduction
62gerente
615
210k
Practical Orchestrator
shlominoach
191
11k
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Խ༧ఆ