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
700
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
210
入門 再発防止策
ryuichi1208
17
7.8k
SREの組織構造と実践.
ryuichi1208
0
320
信頼性・システムの観測・障害対応.pdf
ryuichi1208
1
4
障害対応からの学びと体制づくり
ryuichi1208
0
1.2k
金曜日デプロイ、するかしないか.pdf
ryuichi1208
1
490
会話で作る信頼性
ryuichi1208
0
200
シグナル(Unix)と仲良くなる
ryuichi1208
1
210
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Why Our Code Smells
bkeepers
PRO
340
58k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
320
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
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 参考資料