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
距離関数を極める! / SESSIONS 2024
gam0022
0
280
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
880
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Outline View in SwiftUI
1024jp
1
330
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Quine, Polyglot, 良いコード
qnighy
4
640
みんなでプロポーザルを書いてみた
yuriko1211
0
260
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
180
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
初めてDefinitelyTypedにPRを出した話
syumai
0
420
Click-free releases & the making of a CLI app
oheyadam
2
120
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
40
2.4k
GraphQLとの向き合い方2022年版
quramy
43
13k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
A better future with KSS
kneath
238
17k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Site-Speed That Sticks
csswizardry
0
27
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Building Adaptive Systems
keathley
38
2.3k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
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