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
45
レーダーをつくる
bmf_san
0
35
契約テストとPactについて
bmf_san
0
81
5分でわかるSLO
bmf_san
2
110
権限について考える
bmf_san
2
120
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
400
アジャイルワークショップ
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
私はどうやって技術力を上げたのか
yusukebe
43
17k
Introducing ReActionView: A new ActionView-Compatible ERB Engine @ Kaigi on Rails 2025, Tokyo, Japan
marcoroth
3
920
Goで実践するドメイン駆動開発 AIと歩み始めた新規プロダクト開発の現在地
imkaoru
4
590
SpecKitでどこまでできる? コストはどれくらい?
leveragestech
0
520
Let's Write a Train Tracking Algorithm
twocentstudios
0
220
Back to the Future: Let me tell you about the ACP protocol
terhechte
0
130
ててべんす独演会〜Flowの全てを語ります〜
tbsten
1
220
CSC305 Lecture 02
javiergs
PRO
1
260
CSC509 Lecture 06
javiergs
PRO
0
240
CSC509 Lecture 01
javiergs
PRO
1
430
uniqueパッケージの内部実装を支えるweak pointerの話
magavel
0
920
Breaking Up with Big ViewModels — Without Breaking Your Architecture (droidcon Berlin 2025)
steliosf
PRO
1
330
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Side Projects
sachag
455
43k
Six Lessons from altMBA
skipperchong
28
4k
Speed Design
sergeychernyshev
32
1.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
It's Worth the Effort
3n
187
28k
Mobile First: as difficult as doing things right
swwweet
224
10k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
How to Ace a Technical Interview
jacobian
280
24k
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