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.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
攻撃者がいなくてもAIエージェントはインシデントを起こす
nomizone
0
210
AIと共生する開発者プラットフォーム:バクラクのモノレポ×マイクロサービス基盤
sakajunquality
2
2.7k
次世代ランサムウェア対策の考察 / 20260704 Mitsutoshi Matsuo
shift_evolve
PRO
5
1.7k
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.4k
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
690
Control Planeで育てるBtoB SaaSの認証基盤 - SRE NEXT 2026
pokohide
1
1.7k
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
1k
環境凍結という Toil を倒す -セルフサービス型 Ephemeral テスト環境の 設計と実践
shirouz
1
1.7k
最近評価が難しくなった
maroon8021
0
260
Baseline対応のDOMの型定義を作った
uhyo
3
720
Zoom2Youtube.Claude
kawaguti
PRO
3
470
初めてのDatabricks勉強会
taka_aki
2
250
Featured
See All Featured
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
630
The Pragmatic Product Professional
lauravandoore
37
7.4k
Faster Mobile Websites
deanohume
310
32k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
250
GraphQLとの向き合い方2022年版
quramy
50
15k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
Balancing Empowerment & Direction
lara
6
1.2k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
890
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
180
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Խ༧ఆ