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
WebシステムのパフォーマンスとGo
Search
karupanerura
November 01, 2019
Programming
3
1.7k
WebシステムのパフォーマンスとGo
DeNA.go #3
karupanerura
November 01, 2019
Tweet
Share
More Decks by karupanerura
See All by karupanerura
Use Perl as Better Shell Script
karupanerura
0
750
GoでParserを書く
karupanerura
4
940
マイ隙間家具OSSたちのご紹介
karupanerura
2
260
Mustache Template 話 2024
karupanerura
0
31
1つの言語を原点に色々な言語を学ぶということ
karupanerura
4
2.9k
Javaの実装をPerlでテストする
karupanerura
0
1.2k
Go Generics Overview
karupanerura
0
1.3k
Japan.pm 2021 開催まで至る道
karupanerura
0
2.1k
Perl MongersのためのAWS_CDK入門
karupanerura
0
140
Other Decks in Programming
See All in Programming
CSC305 Summer Lecture 05
javiergs
PRO
0
110
LLMOpsのパフォーマンスを支える技術と現場で実践した改善
po3rin
8
990
WebAssemblyインタプリタを書く ~Component Modelを添えて~
ruccho
1
920
Google I/O recap web編 大分Web祭り2025
kponda
0
2.9k
Flutter로 Gemini와 MCP를 활용한 Agentic App 만들기 - 박제창 2025 I/O Extended Seoul
itsmedreamwalker
0
150
Laravel Boost 超入門
fire_arlo
1
130
オープンセミナー2025@広島LT技術ブログを続けるには
satoshi256kbyte
0
130
KessokuでDIでもgoroutineを活用する / Go Connect #6
mazrean
0
120
Langfuseと歩む生成AI活用推進
licux
3
300
GUI操作LLMの最新動向: UI-TARSと関連論文紹介
kfujikawa
0
1k
GitHub Copilotの全体像と活用のヒント AI駆動開発の最初の一歩
74th
8
3.2k
[FEConf 2025] 모노레포 절망편, 14개 레포로 부활하기까지 걸린 1년
mmmaxkim
0
1.1k
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Balancing Empowerment & Direction
lara
2
590
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Art, The Web, and Tiny UX
lynnandtonic
302
21k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Statistics for Hackers
jakevdp
799
220k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Done Done
chrislema
185
16k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Designing for humans not robots
tammielis
253
25k
Code Review Best Practice
trishagee
70
19k
Transcript
WebγεςϜͷ ύϑΥʔϚϯεͱGo DeNA.go #3 id:karupaneura
id:karupanerura • ιϑτΣΞΤϯδχΞ @ DeNA, Co,. LTD. • ͓ࣄ: ϓϥοτϑΥʔϜ։ൃ
(Perl/Go/Java/etc..) • ISUCON8: ༧બग़νʔϜ (࡞ɺϕϯνϚʔΧʔ) • αϚʔΠϯλʔϯγοϓ2019: ΤϯδχΞ͚ίʔε։ൃ • දཧࣄ @ Japan Perl Association
Goal
WebγεςϜʹ͓͚ΔຊͷGoͷڧΈ Λߟ͑ͯ͠Β͏
ҙࣝ • ʮͱΓ͋͑ͣGoͰॻ͍͓͚͍ͯΜͰ͠ΐʁʯ • ͍͘ΒLLͱൺͯϕϯνϚʔΫ͕༏ल͔ͩΒͱ͍ͬͯͦΓΌ… • ʮͰISUCONͰ༧બ௨աͯ͠ΔͷGoͷνʔϜ͔Γ͡ΌΜʯ • ༗རͳଆ໘ͨ͘͞Μ͋Δ͚Ͳ…είΞ͕͍νʔϜ…
ݱ࣮ΛݟΑ͏
ͱ͔ͬ͠Γ͖߹͓͏
ࠓճ͢͜ͱ • WebγεςϜʹ͓͚ΔύϑΥʔϚϯεͱͳʹ͔ • Ͳ͏͍ͬͨͷ͕ϘτϧωοΫʹͳΔͷ͔ • ͦͷͨΊʹGoͷػೳΛͲͷΑ͏ʹ׆༻͢Δͱྑ͍ͷ͔
ࠓճ͞ͳ͍͜ͱ • DeNAαϚʔΠϯλʔϯγοϓͷৄࡉ • ͲͷΑ͏ʹܭଌͯ͠ϘτϧωοΫΛൃݟ͢ΔͱΑ͍͔
ͦͦύϑΥʔϚϯεͬͯͳΜ͚ͩͬʁ
WebγεςϜʹ͓͚ΔཧతύϑΥʔϚϯε • γεςϜશମͰߟ͑ͨͱ͖... • ୯Ґ࣌ؒͨΓʹͨ͘͞ΜͷϦΫΤετΛॲཧͰ͖Δ • ಉ࣌ʹෳͷϦΫΤετΛޮΑ͘ॲཧͰ͖Δ • ϦΫΤετ୯ҐͰඞཁͱ͢ΔϦιʔε͕গͳ͘ࡁΉ •
͋·ΓແବʹϦιʔεΛফඅ͠ͳ͍
ҰํͰݱ࣮ͷγεςϜͷଟ͘ ཧతͳύϑΥʔϚϯεͰͳ͍
ͳͥύϑΥʔϚϯεԼ͢Δ͔ • γεςϜશମͰߟ͑ͨͱ͖ʹ... • ୯Ґ࣌ؒͨΓʹͨ͘͞ΜͷϦΫΤετΛॲཧͰ͖ͳ͍ • ಉ࣌ʹෳͷϦΫΤετΛॲཧ͢Δޮ͕ѱ͍ • ϦΫΤετ୯ҐͰඞཁͱ͢ΔϦιʔε͕ଟ͍ •
ແବʹϦιʔεΛফඅͯ͠͠·͏
ύϑΥʔϚϯεͷԼཁҼΛഉআ͢Ε ύϑΥʔϚϯε্Ͱ͖Δ
ύϑΥʔϚϯεͷԼཁҼΛഉআ͢Ε ύϑΥʔϚϯε্Ͱ͖Δ γεςϜશମͷϘτϧωοΫʹ͢Δ͖
۩ମྫΛҎͯߟ͑ͯΈΔ
DeNA αϚʔΠϯλʔϯγοϓ2019 ΤϯδχΞίʔε
՝: ΞϓϦέʔγϣϯΛ͍͍ײ͡ʹͤΑ (͍͍ײ͡ʹύϑΥʔϚϯεؚ·ΕΔ)
ΞϓϦέʔγϣϯհ (demo)
ύϑΥʔϚϯεཁ݅ ʮ֨҆εϚϗͷൃചΛه೦͠CMʹग़ԋதͷਓؾܳਓ͕ϦΞϧλ ΠϜͰ࣭Λड͚͚ΔઐνϟϯωϧΛ։ઃ͠·͢ɻʯ ͜͜·Ͱ͑ΒΕΕޚͷࣈɺഒͰେৎͳΒ҆Մೳɿ • 5000ൃݴ/ඵ (x2: 10000ൃݴ/ඵ) • 5ສਓͷಉ࣌ଓ
(10ສಉ࣌ଓ)
γεςϜߏਤ • EC2 1 • AppͱDBಉډ • ALBͰTLSΛॲཧ • S3/Cloud
Frontະ༻
ύϑΥʔϚϯεվળͷྲྀΕ for { • ܭଌ • ϘτϧωοΫΛಛఆ • ϘτϧωοΫΛղফ }
ύϑΥʔϚϯεվળͷྲྀΕ for { • ܭଌ • ϘτϧωοΫΛಛఆ • ϘτϧωοΫΛղফɹˡɹࠓճ͜͜ʹ }
࣮ࡍͷύϑΥʔϚϯεվળ
վળޙͷγεςϜߏਤ • App/DB • S3/Cloud Front׆༻ • ΄͔MySQLνϡʔχϯά
ൃݴ͕ଟ͘ͳΔͷରࡦ
ൃݴ͕ଟ͘ͳΔͷରࡦ • νϟοταʔϏεͷൃݴ͕ଟ͍ͱͲ͏ͳΔ͔ • DBͷinsert͕٧·Δ (MySQLͷνϡʔχϯάͰҰఆվળ͢Δ) • insert͕ͳͥ٧·Δ͔ • DBͷϩοΫΛಉ࣌ଟൃతʹऔΔ͜ͱʹͳΔ͔Β
insertͷϩοΫڝ߹ʹͲ͏ରॲ͢Δ͔ • insertDBͷϩοΫΛऔΔ͜ͱʹͳΔ • ϩοΫΛऔΔػձΛΒ͢͜ͱʹΑͬͯϩοΫڝ߹ΛݮΒͤΔ • ෳͷൃݴΛ·ͱΊͯinsert͢Δͱ... • 1ճͷϩοΫͰෳͷൃݴ͕insertͰ͖͓ͯಘ
insertΛbufferingͯ͠·ͱΊͯΔ • ൃݴΛόοϑΝϦϯάͯ͠insert͢Δworker goroutineΛ࡞ • ϦΫΤετΛॲཧ͢Δgoroutine͔Βchannelܦ༝Ͱ͛Δ • channelͰinsertͷ݁ՌΛड͚औΔ • workerbuffer͕Ұఆ݅ཷ·ͬͨͱ͖͔ҰఆͷintervalͰॲཧ
࣮ࡍͷίʔυ • ʢDBνϡʔχϯά͚ͩͰΛղফͯ͠͠·ͬͨͷͰະ࣮ʣ • DeNA.goͷͨΊʹॻ͖ԼΖͦ͏ͱࢥ͚ͬͨͲؒʹ߹Θͳ͔ͬͨ
ಉ࣌ଓ͕ଟ͘ͳΔͷରࡦ
ಉ࣌ଓ͕ଟ͘ͳΔͱ • ൃݴͷऔಘ͕ଟ͘ͳΔ • ͚ࠩͩऔಘ͍ͨ͠ • ͔͠͠৽ணΛpolling͢Δͱൃݴͷগͳ͍νϟϯωϧ͕ਏ͍ • ʢॳظ࣮શൃݴΛऔΔAPIΛpollingͯ͠Δʣ
Server Sent Events • ҰੲલͷComet͕༷Λཧͯ͠ਖ਼نԽ͞Ε·ͨ͠తͳͭ • WebSocketΑΓѻ͍͕؆୯ • αʔόʔͱΫϥΠΞϯτͰίωΫγϣϯΛషΓଓ͚Δ •
αʔόʔ͔ΒΫϥΠΞϯτʹσʔλΛpushͰ͖Δ (ٯෆՄ)
DBʹϦΫΤετΛඈ͞ͳ͍ • ͖ͬ͞ͷͭͱಉ͡ཁྖͰworker͕࠷৽ͷൃݴΛbuffering͢Δ • DBworker͚͕ͩpollingͯ͠bufferΛߋ৽͍ͯ͘͠ • client͝ͱʹ࠷ޙͷൃݴΛอ͓͍࣋ͯͯͦ͠ΕҎ߱ͷΛ௨ • ௨͞ΕͨͷΛServer Sent
EventsͰclientʹૹΔ
࣮ࡍͷίʔυ (worker goroutine)
࣮ࡍͷίʔυ (worker goroutine)
࣮ࡍͷίʔυ (worker goroutine)
࣮ࡍͷίʔυ (http handler)
ͦͷଞ
sync.Pool • ϦΫΤετͷbytes.BufferͳͲΛৗʹ࡞ΔͱGC͕ਏ͍ • sync.PoolΛ͏ͱgoroutine͝ͱʹڝ߹͠ͳ͍Pool͕࡞ΕΔ • ϝϞϦޮྑ͍͕ϝϞϦফඅ͍ͯ͘͠ͷͰѻ͍ʹҙ
encoding/json • ϨεϙϯεΛ࡞Δͷʹඞͣͦ͠ΕͱಉαΠζͷόοϑΝΛ࡞ Δඞཁͳ͍ • ࡞ͬͨͿΜ͔Βૹ͍͚ͬͯΑ͍ • ͨͩ͠ (*json.Encoder).Write ్தͰerrorΛฦ͠ࢭ·Δ͜ͱ
͕͋Δ • ਖ਼͘͠ϨεϙϯεΛฦͨ͢Ίʹbufferඞཁ
io • sync.PoolͰอ࣋ͨ͠bytes.BufferΛhttp.ResponseWriter • bytes.Bufferio.WriterToΛ࣮͍ͯ͠ΔͷͰWriteToͰ͖Δ • bytes.BufferͷWriteTobytes.Bufferͷposition͚ͩม͍͑ͯ ͖ޮΑ͘WriteͰ͖Δ • io.CopyBufferͳͲศར
database/sql • σϑΥϧτͰDBͱͷଓΛόοϑΝϦϯάͯ͘͠ΕΔ • SetMaxIdleConns/SetMaxOpenConns/SetConnMaxLifetime • ࣮ࡍͷنʹ͋Θͤͯௐ͢Δͱଓ͕࠷దԽͰ͖Δ • SetMaxIdleConnsͷσϑΥϧτ2
·ͱΊ
·ͱΊ • Goʹ͚ͨͩ͠Ͱ͘ͳΒͳ͍ͷͰϦιʔεΛޮΑ͓͘͏ • ಛʹϘτϧωοΫʹͳΓ͍͢Ϧιʔεʹҙ • ༨༟͕͋ΔϦιʔεΛ׆༻ͯ͠͠Α͏ • جຊػೳio, syncͳͲศརͳඪ४ύοέʔδΛ·ͣ׆༻͠Α͏
• ݶΓ͋ΔϦιʔεΛޮΑ͘׆༻͢Δϊϋͷๅݿ