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.8k
自作HTTPルーターから新しいServeMuxへ
bmf_san
June 08, 2024
Tweet
Share
More Decks by bmf_san
See All by bmf_san
AAPについて調べてみた
bmf_san
0
39
レーダーをつくる
bmf_san
0
30
契約テストとPactについて
bmf_san
0
76
5分でわかるSLO
bmf_san
2
100
権限について考える
bmf_san
2
120
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
390
アジャイルワークショップ
bmf_san
0
160
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
2.8k
天下一HTTPRouter武闘会.pdf
bmf_san
8
4.4k
Other Decks in Programming
See All in Programming
Microsoft Orleans, Daprのアクターモデルを使い効率的に開発、デプロイを行うためのSekibanの試行錯誤 / Sekiban: Exploring Efficient Development and Deployment with Microsoft Orleans and Dapr Actor Models
tomohisa
0
210
AIエージェント開発、DevOps and LLMOps
ymd65536
1
340
The State of Fluid (2025)
s2b
0
200
フロントエンドのmonorepo化と責務分離のリアーキテクト
kajitack
2
140
CSC305 Summer Lecture 05
javiergs
PRO
0
110
DockerからECSへ 〜 AWSの海に出る前に知っておきたいこと 〜
ota1022
5
1.8k
MLH State of the League: 2026 Season
theycallmeswift
0
160
マイコンでもRustのtestがしたい その2/KernelVM Tokyo 18
tnishinaga
2
2.3k
AIレビュアーをスケールさせるには / Scaling AI Reviewers
technuma
2
230
STUNMESH-go: Wireguard NAT穿隧工具的源起與介紹
tjjh89017
0
380
Constant integer division faster than compiler-generated code
herumi
2
690
LLMOpsのパフォーマンスを支える技術と現場で実践した改善
po3rin
8
980
Featured
See All Featured
It's Worth the Effort
3n
187
28k
Building Adaptive Systems
keathley
43
2.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.4k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Documentation Writing (for coders)
carmenintech
73
5k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
A designer walks into a library…
pauljervisheath
207
24k
Code Review Best Practice
trishagee
70
19k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
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