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
A Shallow Dive into the World of TCP
Search
ryuichi1208
April 13, 2025
680
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
AIでサービス運用はどう変わるのか
ryuichi1208
0
170
入門 再発防止策
ryuichi1208
17
7.5k
金曜日デプロイ、するかしないか.pdf
ryuichi1208
1
78
会話で作る信頼性
ryuichi1208
0
190
シグナル(Unix)と仲良くなる
ryuichi1208
1
53
AI前提のサービス運用について再考する
ryuichi1208
6
1.5k
入門リトライ
ryuichi1208
20
8.4k
超入門SRE 2025
ryuichi1208
4
1.6k
Goで作って学ぶWebSocket
ryuichi1208
5
4.3k
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
450
Thoughts on Productivity
jonyablonski
76
5.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Abbi's Birthday
coloredviolet
3
8.9k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
380
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.3k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
280
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Designing Powerful Visuals for Engaging Learning
tmiket
1
470
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 参考資料