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
自作HTTPルーターから新しいServeMuxへ
Search
bmf_san
June 08, 2024
Programming
3
1.6k
自作HTTPルーターから新しいServeMuxへ
bmf_san
June 08, 2024
Tweet
Share
More Decks by bmf_san
See All by bmf_san
契約テストとPactについて
bmf_san
0
38
5分でわかるSLO
bmf_san
2
55
権限について考える
bmf_san
2
67
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
260
アジャイルワークショップ
bmf_san
0
94
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
2.3k
天下一HTTPRouter武闘会.pdf
bmf_san
8
4.2k
ゆっくりHackerRank
bmf_san
0
110
ハイ__ᐛ___パァ_テキストプリプロフェッ__ᐛ___サァ_.pdf
bmf_san
0
220
Other Decks in Programming
See All in Programming
CSC509 Lecture 09
javiergs
PRO
0
140
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
Click-free releases & the making of a CLI app
oheyadam
2
110
CSC509 Lecture 12
javiergs
PRO
0
160
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Better Code Design in PHP
afilina
PRO
0
120
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
297
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Code Review Best Practice
trishagee
64
17k
BBQ
matthewcrist
85
9.3k
Adopting Sorbet at Scale
ufuk
73
9.1k
The Invisible Side of Design
smashingmag
298
50k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
It's Worth the Effort
3n
183
27k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Transcript
ࣗ࡞HTTPϧʔλʔ͔Β ৽͍͠ServeMux @bmf_san Go Conference 2024 2024.6.8
Who am Iʁ • Kenta Takeuchi • @bmf_san • bmf-san
• https://bmf-tech.com/
ࣗ࡞HTTPϧʔλʔ IUUQTHJUIVCDPNCNGTBOHPCMJO
͢͜ͱ • Go1.22ͰՃ͞ΕͨServeMuxͷػೳ • ServeMuxͱαʔυύʔςΟͷൺֱ • ServeMuxͷੑೳ • GoͷHTTPϧʔλʔબఆʹ͍ͭͯࢲݟ
ServeMuxͱʁ • net/http͕͍࣋ͬͯΔϚϧνϓϨΫα • ύεύλʔϯͱϦΫΤετΛϚονϯά͢Δϩ δοΫΛ࣋ͪɺϋϯυϥΛݺͼग़͢ • ServeMuxߏମ • cf.
https://cs.opensource.google/go/go/+/refs/ tags/go1.22.2:src/net/http/server.go;l=2432
Go1.22ͰՃ͞ΕͨServeMuxͷػೳ • HTTPϝιουʹΑΔϧʔςΟϯάͷఆ͕ٛ Մೳʹͳͬͨ
Go1.22ͰՃ͞ΕͨServeMuxͷػೳ • ϫΠϧυΧʔυʹΑΔϧʔςΟϯάͷఆٛ ͕Մೳʹͳͬͨ
Go1.22ͰՃ͞ΕͨServeMuxͷػೳ • ϫΠϧυΧʔυʹϚονͨ͠ɺ http.RequestͷPathValueϝιουͰऔಘՄ ೳ
Go1.22ͰՃ͞ΕͨServeMuxͷػೳ • શҰகͱ͍ͨ͠߹{$}Λ͏
ServeMuxͱαʔυύʔςΟͷൺֱ • ServeMuxͱαʔυύʔςΟͷੑೳൺֱΛ࣮ࢪ • https://github.com/bmf-san/go-router-benchmark • ύεύλʔϯͷϚονϯάͷΈͰɺύεύλʔ ϯͷొʢϧʔςΟϯάͷఆٛʣܭଌର֎ • gin-gonic/gin,
go-chi/chi, gorilla/mux, labstack/ echoͳͲ
ServeMuxͱαʔυύʔςΟͷൺֱ • ServeMuxฏۉҎ্ͷύϑΥʔϚϯεΛ ͍࣋ͬͯΔ • ϫΠϧυΧʔυͷʢ/foo/{bar}/{baz}/ {baz}/…ʣ͕૿͑ΔͱੑೳྼԽ͕ݦஶ • ࣮ࡍͷϢʔεέʔεͱͯ͠ϨΞέʔε ͳͷͰؾʹ͢Δ͜ͱͰͳͦ͞͏
ServeMuxͷੑೳ • ੑೳͷྑ͍HTTPϧʔλʔϝϞϦޮͷྑ͍ߏ ʢex. Radix TreeʣΛ࠾༻͍ͯ͠Δ • ServeMuxͰɺ࣮͕ෳࡶԽ͍͢͠σʔλߏ ࠾༻͞Ε͍ͯͳ͍ •
→༨ఔ࠷ѱͳσʔλߏΛ࠾༻͠ͳ͍ݶΓɺ HTTPϧʔλʔ͕ϨΠςϯγCPU༻ʹେ͖ ͳӨڹΛٴ΅͞ͳ͍ʢͨͿΜʣ
GoͷHTTPϧʔλʔબఆʹ͍ͭͯࢲݟ
͏ͪΐͬͱਅ໘ͳͭ
GoͷHTTPϧʔλʔબఆʹ͍ͭͯࢲݟ • HTTPϧʔλʔͷҠߦΛݕ౼͢ΔͳΒɾɾ • ͍ͬͯΔHTTPϧʔλʔͷnet/httpͱͷޓੑ ʁ • ServeMuxʹͳ͍ػೳੑೳ͕ඞཁ͔ʁ • ϧʔςΟϯάͷ༏ઌॱҐʹಠࣗͷϩδοΫ͕͋
Δ͔ʁ
·ͱΊ • ϫΠϧυΧʔυΛͬͨϧʔςΟϯά͕Ͱ͖ΔΑ͏ʹ ͳͬͨ • αʔυύʔςΟͱൺֱͯ͠ѱ͘ͳ͍ੑೳ • σʔλߏͱΞϧΰϦζϜͷબอकੑͱੑೳͷό ϥϯε͕େࣄͦ͏ •
৽نʹબఆ͢ΔͳΒServeMuxɺطଘΓ͑৭ʑݕ ౼͢Δͷ͕ྑͦ͞͏
ࣗ࡞HTTPϧʔλʔ͔Β৽͍͠ServeMux • ࠓޙࣗ࡞HTTPϧʔλʔʢ≠αʔυύʔ ςΟʣͰͳ͘ServeMuxΛ͍͍ͨͱࢥͬ ͍ͯ·͢ • αʔυύʔςΟέʔεόΠέʔε
5IBOLZPVGPSZPVSXBUDIJOHʂ
Appendix • ࣗ࡞HTTPϧʔλʔ͔Β৽͍͠ServeMux • https://bmf-tech.com/posts/ %e8%87%aa%e4%bd%9cHTTP%e3%83%ab%e3%8 3%bc%e3%82%bf%e3%83%bc%e3%81%8b%e3%82 %89%e6%96%b0%e3%81%97%e3%81%84ServeMu x%e3%81%b8#14- HTTP%E3%83%AB%E3%83%BC%E3%82%BF%E3
%83%BC%E3%81%AE%E3%83%91%E3%83%95% E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3 %E3%82%B9%E3%81%AB%E3%81%A4%E3%81% 84%E3%81%A6