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
SUZUKI Yoshiharu
June 06, 2024
Programming
700
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
1k
Other Decks in Programming
See All in Programming
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
240
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
140
SODA - FACT BOOK(JP)
sodainc
1
40k
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
110
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.7k
Getting Started with Vibe Coding
miccheng
0
190
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
16
8.9k
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
210
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
540
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
320
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
330
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
240
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
970
A better future with KSS
kneath
240
18k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Making Projects Easy
brettharned
120
6.9k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
660
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
440
Into the Great Unknown - MozCon
thekraken
41
2.8k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
350
New Earth Scene 8
popppiees
4
2.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
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! ご清聴ありがとうございました!