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
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
1.1k
AIでサービス運用はどう変わるのか
ryuichi1208
0
190
入門 再発防止策
ryuichi1208
17
7.7k
金曜日デプロイ、するかしないか.pdf
ryuichi1208
1
86
会話で作る信頼性
ryuichi1208
0
200
シグナル(Unix)と仲良くなる
ryuichi1208
1
65
LiteLLM Proxyの紹介
ryuichi1208
1
24
AI前提のサービス運用について再考する
ryuichi1208
6
1.5k
入門リトライ
ryuichi1208
20
8.5k
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
410
Designing for humans not robots
tammielis
254
26k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
A Modern Web Designer's Workflow
chriscoyier
698
190k
Leo the Paperboy
mayatellez
8
2.2k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
230
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
Accessibility Awareness
sabderemane
1
200
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
510
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
410
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
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 参考資料