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
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
3
1.8k
自律型AIエージェントは何を破壊するのか
kojira
0
130
関西に縁あるMicrosoft MVPsが語るCopilotの未来
kasada
0
1.2k
Microsoft Build Keynoteふりかえり
tomokusaba
0
120
なぜ Platform Engineering の土台に Kubernetes を選ぶのか
r4ynode
1
390
OCI Oracle AI Database Services新機能アップデート(2026/03-2026/05)
oracle4engineer
PRO
0
320
小さくはじめるSLI/SLO ~育てながら組織に定着させる実践知~ / Starting Small with SLI/SLOs: Building Adoption Through Continuous Growth
nari_ex
1
640
Rancherの紹介&Update情報(RancherJP Online Meetup #09)
yoshiyuki_kono
0
140
非定型業務をAI slackbotで自動化する ~ 社内要望を自動壁打ちするbotを作った ~/automating-ad-hoc-work-with-ai-slackbot
shibayu36
0
540
もりもり新機能を一挙紹介! AgentCoreに入門して、AWS上にAIエージェントを構築しよう
minorun365
PRO
6
870
Agentic ERPをどう設計するか ー 受発注エージェントを動かす、現場の知見と設計思想ー
recerqainc
1
2k
サイバーセキュリティ概論 / Introduction to Cybersecurity
ks91
PRO
0
170
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
600
My Coaching Mixtape
mlcsv
0
140
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
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Խ༧ఆ