Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
通信の不安定さに悩んでいたらシュッとプロキシを書けて改善できちゃった話
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
SUZUKI Yoshiharu
June 06, 2024
Programming
680
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
通信の不安定さに悩んでいたらシュッとプロキシを書けて改善できちゃった話
SUZUKI Yoshiharu
June 06, 2024
More Decks by SUZUKI Yoshiharu
See All by SUZUKI Yoshiharu
マイクロサービスのローカル開発環境をTiltを使って2年運用して得た知見
bellwood4486
1
970
Other Decks in Programming
See All in Programming
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
140
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
410
How I Stole PSI from Android Studio - DroidKaigi2026
worker8
0
110
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
280
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
140
スマート反転とウェブアクセシビリティ
camiha
0
200
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
610
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
150
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
240
Webの地図
yosuke_furukawa
PRO
6
4.3k
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
6
1.6k
Featured
See All Featured
Practical Orchestrator
shlominoach
191
12k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
700
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
First, design no harm
axbom
PRO
2
1.3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
510
Navigating Weather and Climate Data
rabernat
0
510
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
530
How to build a perfect <img>
jonoalderson
1
6k
Navigating Team Friction
lara
192
16k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
The agentic SEO stack - context over prompts
schlessera
0
930
Done Done
chrislema
186
16k
Transcript
通信の不安定さに悩んでいたら シュッとプロキシを書けて 改善できちゃった話 鈴⽊ 善晴 / 株式会社HRBrain 2024.06.08 Go Conference
2024
2 ⾃⼰紹介 ▪名前 鈴⽊ 善晴 / Yoshiharu Suzuki ▪所属 株式会社
HRBrain テックリード 兼 バックエンドエンジニア ▪Go歴 4年
3 本LTのアウトカム🎁 「HTTP通信を制御するプロキシ」のGoの実装例 を知ることができる
4 アジェンダ 01 背景とアプローチ 02 プロキシの説明 03 まとめ
5 アジェンダ 01 背景とアプローチ 02 プロキシの説明 03 まとめ 0:50
6 弊社は、⼈事領域のSaaSを開発しています!
リクエストが集中すると、SSHトンネルで通信が失敗する…。 7 開発環境が不安定問題😢
プロキシを挟んで制御を試みる 8 同時通信を抑えれば改善できるのでは?🤔
9 アジェンダ 01 背景とアプローチ 02 プロキシの説明 03 まとめ 1:50
10 構成技術 標準(または準標準)の技術だけで、2⽇程度でプロキシを実現! • http.RoundTripper インターフェース … 「⼀回のHTTP通信」を表すインターフェース • golang.org/x/sync/semaphore
パッケージ … セマフォの提供 💡セマフォとは? • コンピュータの並行処理において、共有リソースのアクセスを制御し、 競合を防ぐための機構 • カウンターを用いて、特定のリソースの利用可能数を管理する
11 ⼟台となるリバースプロキシを⽤意する func main() { target, _ := url.Parse("http://localhost:8080") //
リバースプロキシの作成 proxy := httputil.NewSingleHostReverseProxy(target) // サーバ起動 srv := &http.Server{ Addr: ":9999", Handler: proxy, } _ = srv.ListenAndServe() }
12 通信に⼿を⼊れる余地を作る http.RoundTripperを加える // カスタマイズするための構造体 type c struct{} func (c
*c) RoundTrip(r *http.Request) (*http.Response, error) { // 標準で用意されているデフォルト実装へ移譲するだけ return http.DefaultTransport.RoundTrip(r) } func main() { ... proxy := httputil.NewSingleHostReverseProxy(target) // プロキシの動きをカスタマイズ proxy.Transport = &c{} ... } 2:50
13 同時通信に上限を設定して完成🙌 semaphoreも加える type c struct { sem *semaphore.Weighted //
同時通信を制御するセマフォ } func (c *c) RoundTrip(r *http.Request) (*http.Response, error) { _ = c.sem.Acquire(r.Context(), 1) // 1通信につき1つ使う defer c.sem.Release(1) // 最後に解放 return http.DefaultTransport.RoundTrip(r) } func main() { ... proxy := httputil.NewSingleHostReverseProxy(target) proxy.Transport = &c{ sem: semaphore.NewWeighted(1), // 同時通信の上限が1の例 } ... } 3:35
14 同時通信に上限を設定して完成🙌 semaphoreも加える type c struct { sem *semaphore.Weighted //
同時通信を制御するセマフォ } func (c *c) RoundTrip(r *http.Request) (*http.Response, error) { _ = c.sem.Acquire(r.Context(), 1) // 1通信につき1つ使う defer c.sem.Release(1) // 最後に解放 return http.DefaultTransport.RoundTrip(r) } func main() { ... proxy := httputil.NewSingleHostReverseProxy(target) proxy.Transport = &c{ sem: semaphore.NewWeighted(1), // 同時通信の上限が1の例 } ... }
15 アジェンダ 01 背景とアプローチ 03 まとめ 02 プロキシの説明 4:20
16 まとめ 1. プロキシで同時通信を制御する事例を紹介 ◦ 実際のソースコードはこちら https://github.com/bellwood4486/flow-limit-proxy 2. 標準(+準標準)パッケージで⽤意されていることも多い。 なので公式ドキュメントに⽬を通すのは⼤事!
◦ http.RoundTripper ◦ golang.org/x/sync/semaphore 3. ⼀つのことをうまくやるツールをシュッと作れるのは ”便利!” “楽しい!”
We are hiring! ご清聴ありがとうございました!