Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
40
5分でわかるSLO
bmf_san
2
59
権限について考える
bmf_san
2
71
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
270
アジャイルワークショップ
bmf_san
0
99
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
2.4k
天下一HTTPRouter武闘会.pdf
bmf_san
8
4.3k
ゆっくりHackerRank
bmf_san
0
110
ハイ__ᐛ___パァ_テキストプリプロフェッ__ᐛ___サァ_.pdf
bmf_san
0
230
Other Decks in Programming
See All in Programming
[FlutterKaigi2024] Effective Form 〜Flutterによる複雑なフォーム開発の実践〜
chocoyama
1
4k
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
160
.NET 9アプリをCGIとして レンタルサーバーで動かす
mayuki
1
760
DevTools extensions で 独自の DevTool を開発する | FlutterKaigi 2024
kokiyoshida
0
450
Vapor Revolution
kazupon
2
2.5k
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
130
競技プログラミングで 基礎体力を身につけよう / You can get basic skills through competitive programming
mdstoy
0
150
Reckoner における Datadog Browser Test の活用事例 / Datadog Browser Test at Reckoner
nomadblacky
0
190
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
640
Missing parts when designing and implementing Android UI
ericksli
0
390
PipeCDの歩き方
kuro_kurorrr
4
140
HTTP compression in PHP and Symfony apps
dunglas
2
1.5k
Featured
See All Featured
Building Your Own Lightsaber
phodgson
103
6.1k
Documentation Writing (for coders)
carmenintech
65
4.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Code Reviewing Like a Champion
maltzj
520
39k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Unsuck your backbone
ammeep
669
57k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Why Our Code Smells
bkeepers
PRO
334
57k
Building a Scalable Design System with Sketch
lauravandoore
459
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