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
A Shallow Dive into the World of TCP
Search
ryuichi1208
April 13, 2025
690
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
A Shallow Dive into the World of TCP
ryuichi1208
April 13, 2025
More Decks by ryuichi1208
See All by ryuichi1208
そのasync、止まってない? ”鉄板”イベントループ ブロッキング処理検出術
ryuichi1208
1
2.2k
AIでサービス運用はどう変わるのか
ryuichi1208
0
200
入門 再発防止策
ryuichi1208
17
7.7k
障害対応からの学びと体制づくり
ryuichi1208
0
2
金曜日デプロイ、するかしないか.pdf
ryuichi1208
1
89
会話で作る信頼性
ryuichi1208
0
200
シグナル(Unix)と仲良くなる
ryuichi1208
1
200
LiteLLM Proxyの紹介
ryuichi1208
1
24
AI前提のサービス運用について再考する
ryuichi1208
6
1.5k
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
41k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Evolving SEO for Evolving Search Engines
ryanjones
0
290
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
Dealing with People You Can't Stand - Big Design 2015
cassininazir
368
27k
The browser strikes back
jonoalderson
0
1.7k
Mind Mapping
helmedeiros
1
360
Faster Mobile Websites
deanohume
310
32k
Code Review Best Practice
trishagee
74
20k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Transcript
A Shallow Dive into the World of TCP 渡部⿓⼀ Road
to SRE NEXT@仙台
⼊⾨TCP
• RFC9293 Transmission Control Protocol ◦ 2022年に40年越しに改定された • IPネットワーク上のコネクション型‧⾼信頼性‧ストリーム指向 •
3ウェイハンドシェイクで接続を確⽴し、信頼できる通信を保証 • 順序制御と再送制御でパケットロスや順序の乱れを回避 • 使わない⽇はないプロトコル TCP
None
完全に理解した
TCPクイズ1
• NGINXで処理が詰まってしまってしまった • アプリケーションコンテナの処理時間はどうなる? 1. ⻑くなる 2. 変わらない
答え: どちらの可能性もある
• Nginxもアプリケーションもソケットバッファを持っている可能性がある • ソケットバッファとはソケット通信において送受信されるデータを⼀時 的に保存するメモリ領域 • ソケットバッファに書き込んだ時点で処理は終了となって処理時間が計算 される(ソケットバッファ>0) 解説
• ALBとかダウンストリームで全体の処理時間は伸びてるのにアプリケー ションの処理時間だけ短いみたいなケースはこう⾔うことが起きている 可能性がある ◦ Ingress Nginxとかで⼤量のルールがあったり • バッファーサイズとかは⼤量トラフィックを捌く必要がないならば⼤体 はデフォルトで事⾜りるがいざという時のチューニングポイントになる
• 処理時間がどこからどこまでかを正確に把握することは⽇々の運⽤でも ⼤事 ポイント
TCPクイズ2
• OSはどちらもLinux、TCPクライアント/サーバで通信 • あるタイミングでサーバ側がソケットをclose • その後にクライアントがサーバに対してデータ送信 • クライアント側のプログラムはどうなる? 1. 成功する
2. 失敗する
答え: どちらの可能性もある https://github.com/ryuichi1208/tcp-syn-flood/tree/master/srv
• TCPは4 way-handshakeで通信を終了 • FINパケットが来ても対向がソケットを読み取りしてる可能性がある • closeしている可能性もあり、FINパケットを受け取ったOS側で通信相⼿がどちら の状態なのか判断できない • アプリからのwriteはsocket
bufferに乗るとその時点ではエラーにならず次回の write/readでエラーになる 解説
まとめ
• TCPに詳しくなることで⽇々の運⽤に活かせることはたくさんある • アプリケーションから何が起きてるかわからないトラブルとか • 信頼性を向上させるノウハウはたくさんあるのでこういったレイヤーか ら学んでみるのも良い まとめ
参考資料
• [書籍] UNIXネットワークプログラミング Vol.1 第2版 • [書籍] TCP/IPソケットプログラミング (C⾔語編) •
未知の領域でのSYNパケット処理 ◦ https://blog.cloudflare.com/ja-jp/syn-packet-handling-in-the-wild/ • Socket migration for SO_REUSEPORT (Part 1) ◦ https://kuniyu.jp/ja/blog/6/ • tcpの仕様上、接続先がコネクションをcloseしているかはパケットを⼀度は実際に送る までわからないよという話 ◦ https://qiita.com/behiron/items/3719430e12cb770980f3 参考資料