

TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control
TCP (Transmission Control Protocol) เป็น transport layer protocol ที่ให้ reliable, ordered delivery ของ data TCP ใช้ 3-way handshake สร้าง connection, flow control (sliding window) ป้องกัน receiver overwhelm และ congestion control (slow start, congestion avoidance) ป้องกัน network congestion การเข้าใจ TCP internals สำคัญมากสำหรับ troubleshooting performance
TCP performance problems เป็น สาเหตุอันดับ 1 ของ application slowness ที่ network engineers ต้องแก้ เช่น slow file transfers, web page load times สูง หรือ database timeouts การเข้าใจ TCP window size, retransmissions และ congestion control ช่วยระบุ bottleneck ว่าอยู่ที่ network, server หรือ application
TCP Header
| Field | Size | Purpose |
|---|---|---|
| Source Port | 16 bits | Sender’s port number |
| Destination Port | 16 bits | Receiver’s port number |
| Sequence Number | 32 bits | Byte position ของ first data byte ใน segment |
| Acknowledgment Number | 32 bits | Next expected byte (cumulative ACK) |
| Window Size | 16 bits | Receiver’s available buffer (flow control) |
| Flags | 6 bits | SYN, ACK, FIN, RST, PSH, URG |
| Checksum | 16 bits | Error detection |
TCP 3-Way Handshake
| Step | Client | Server | Flags |
|---|---|---|---|
| 1 | SYN (seq=x) → | SYN | |
| 2 | ← SYN-ACK (seq=y, ack=x+1) | SYN+ACK | |
| 3 | ACK (ack=y+1) → | ACK | |
| 4 | Connection ESTABLISHED — data transfer begins | – | |
TCP Connection Termination (4-Way)
| Step | Initiator | Responder | Flags |
|---|---|---|---|
| 1 | FIN (seq=x) → | FIN+ACK | |
| 2 | ← ACK (ack=x+1) | ACK | |
| 3 | ← FIN (seq=y) | FIN+ACK | |
| 4 | ACK (ack=y+1) → | ACK | |
| 5 | TIME_WAIT (2×MSL) | CLOSED | – |
TCP States
| State | ความหมาย | Side |
|---|---|---|
| LISTEN | Server waiting for SYN | Server |
| SYN_SENT | SYN sent, waiting for SYN-ACK | Client |
| SYN_RECEIVED | SYN-ACK sent, waiting for ACK | Server |
| ESTABLISHED | Connection active, data transfer | Both |
| FIN_WAIT_1 | FIN sent, waiting for ACK | Initiator |
| FIN_WAIT_2 | FIN ACKed, waiting for peer’s FIN | Initiator |
| CLOSE_WAIT | FIN received, waiting for app to close | Responder |
| TIME_WAIT | Waiting 2×MSL before fully closing | Initiator |
| CLOSED | Connection fully closed | Both |
Flow Control (Sliding Window)
| Concept | รายละเอียด |
|---|---|
| Window Size | จำนวน bytes ที่ receiver ยอมรับได้โดยไม่ต้องรอ ACK |
| Receive Window (rwnd) | Receiver advertise buffer space ใน TCP header |
| Window Scaling | TCP option ที่ขยาย window size > 64KB (shift count, up to 1GB) |
| Zero Window | Receiver buffer เต็ม → advertise window=0 → sender หยุดส่ง |
| Window Update | Receiver ประมวลผล data → advertise window > 0 → sender ส่งต่อ |
| Silly Window Syndrome | Receiver advertise tiny windows → inefficient small segments |
Congestion Control
| Phase | วิธีทำงาน | cwnd Growth |
|---|---|---|
| Slow Start | เริ่ม cwnd=1 MSS → double ทุก RTT (exponential) | 1 → 2 → 4 → 8 → 16… |
| Congestion Avoidance | เมื่อ cwnd ≥ ssthresh → เพิ่ม 1 MSS per RTT (linear) | 16 → 17 → 18 → 19… |
| Fast Retransmit | 3 duplicate ACKs → retransmit lost segment ทันที (ไม่รอ timeout) | – |
| Fast Recovery | หลัง fast retransmit: ssthresh = cwnd/2, cwnd = ssthresh + 3 | Halve + 3 (ไม่กลับ slow start) |
| Timeout | RTO expired → ssthresh = cwnd/2, cwnd = 1 MSS (กลับ slow start) | Reset to 1 |
Modern Congestion Control Algorithms
| Algorithm | วิธีทำงาน | เหมาะกับ |
|---|---|---|
| Reno | AIMD (Additive Increase Multiplicative Decrease) | Traditional (legacy) |
| Cubic | Cubic function สำหรับ window growth (aggressive recovery) | Linux default, general purpose |
| BBR (Google) | Model-based: estimate bandwidth + RTT (not loss-based) | High bandwidth, long RTT links |
| BBR v2 | Improved fairness + reduced bufferbloat | Google services, CDNs |
| DCTCP | ECN-based (react to congestion marks, not loss) | Data center (low latency) |
TCP Performance Factors
| Factor | ผลกระทบ | วิธีแก้ |
|---|---|---|
| High RTT | Slow start ใช้เวลานาน, throughput ต่ำ | Window scaling, BBR, CDN (reduce RTT) |
| Packet Loss | Retransmissions, cwnd reduction | Fix network issues, BBR (loss-tolerant) |
| Small Window | Sender ส่งได้น้อย (bottleneck) | Window scaling, tune buffer sizes |
| Bufferbloat | Excessive queuing → high latency | AQM (CoDel, fq_codel), ECN |
| BDP (Bandwidth-Delay Product) | Max throughput = window / RTT | Window ≥ BDP สำหรับ full utilization |
BDP Calculation
| Parameter | Value |
|---|---|
| Bandwidth | 100 Mbps = 12.5 MB/s |
| RTT | 50 ms = 0.05 s |
| BDP | 12.5 MB/s × 0.05 s = 625 KB |
| Required Window | ≥ 625 KB สำหรับ full 100 Mbps utilization |
| Default Window (64KB) | Throughput = 64 KB / 0.05 s = 1.28 MB/s = 10.24 Mbps (only 10%!) |
TCP Tuning
| Parameter | Linux sysctl | Recommended |
|---|---|---|
| TCP Window Scaling | net.ipv4.tcp_window_scaling | 1 (enabled, default) |
| Receive Buffer Max | net.core.rmem_max | 16777216 (16MB) |
| Send Buffer Max | net.core.wmem_max | 16777216 (16MB) |
| TCP Buffer Auto-tuning | net.ipv4.tcp_rmem / tcp_wmem | “4096 87380 16777216” |
| Congestion Algorithm | net.ipv4.tcp_congestion_control | bbr (or cubic) |
| ECN | net.ipv4.tcp_ecn | 1 (enable for DC) |
ทิ้งท้าย: TCP = Reliable + Flow + Congestion Control
TCP Deep Dive 3-way handshake: SYN → SYN-ACK → ACK Flow control: receiver window (rwnd) ป้องกัน receiver overwhelm Congestion control: slow start → congestion avoidance → fast retransmit/recovery BDP = bandwidth × RTT → window ≥ BDP สำหรับ full throughput Modern: BBR (model-based), CUBIC (loss-based), DCTCP (ECN-based)
อ่านเพิ่มเติมเกี่ยวกับ Network Traffic Analysis Wireshark และ QoS Classification Marking ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com
อ่านเพิ่มเติม: เทรด Forex | EA Semi-Auto ฟรี
FAQ
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control คืออะไร?
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control เป็นหัวข้อสำคัญในวงการเทคโนโลยีที่ช่วยให้การทำงานมีประสิทธิภาพมากขึ้น ไม่ว่าจะเป็นด้าน IT, Network หรือ Server Management
ทำไมต้องเรียนรู้เรื่อง TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control?
เพราะ TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control เป็นทักษะที่ตลาดต้องการสูง และช่วยให้คุณแก้ปัญหาในงานจริงได้อย่างมืออาชีพ การเรียนรู้ตั้งแต่วันนี้จะเป็นประโยชน์ในระยะยาว
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control เหมาะกับผู้เริ่มต้นไหม?
ได้แน่นอนครับ บทความนี้เขียนให้เข้าใจง่าย เหมาะทั้งผู้เริ่มต้นและผู้มีประสบการณ์ มี step-by-step guide พร้อมตัวอย่างให้ทำตามได้ทันที
สิ่งที่คุณจะได้เรียนรู้จากบทความนี้
บทความ TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control นี้ครอบคลุมทุกอย่างที่คุณต้องรู้ ตั้งแต่พื้นฐานไปจนถึงการนำไปใช้จริง เขียนจากประสบการณ์จริง ไม่ใช่แค่ทฤษฎี มีตัวอย่างและ step-by-step guide ให้ทำตามได้ทันที
ทำไม TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control ถึงน่าสนใจ?
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control เป็นหัวข้อที่กำลังได้รับความสนใจสูงมากในปี 2569 ทั้งจากมือใหม่และผู้เชี่ยวชาญ เพราะมีการเปลี่ยนแปลงและพัฒนาใหม่ๆ อยู่ตลอด การติดตามข้อมูลล่าสุดเป็นสิ่งสำคัญ
FAQ
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control คืออะไร?
อ่านรายละเอียดทั้งหมดในบทความนี้ ครอบคลุมตั้งแต่พื้นฐานไปจนถึงขั้นสูง
iCafeForex | SiamLanCard | Siam2R | XM Signal
สิ่งที่ควรรู้เพิ่มเติมเกี่ยวกับ TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control ยังมีมิติอื่นที่น่าสนใจ การศึกษาเพิ่มเติมจะช่วยให้เข้าใจภาพรวมได้ดีขึ้น แนะนำให้อ่านบทความที่เกี่ยวข้องเพิ่มเติมและฝึกปฏิบัติจริง
อ่านเพิ่มเติม: iCafeForex | XM Signal EA ฟรี | SiamLanCard | Siam2R
สิ่งที่ควรรู้เพิ่มเติมเกี่ยวกับ TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control ยังมีมิติอื่นที่น่าสนใจ การศึกษาเพิ่มเติมจะช่วยให้เข้าใจภาพรวมได้ดีขึ้น แนะนำให้อ่านบทความที่เกี่ยวข้องเพิ่มเติมและฝึกปฏิบัติจริง
อ่านเพิ่มเติม: iCafeForex | XM Signal EA ฟรี | SiamLanCard | Siam2R
สิ่งที่ควรรู้เพิ่มเติมเกี่ยวกับ TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control ยังมีมิติอื่นที่น่าสนใจ การศึกษาเพิ่มเติมจะช่วยให้เข้าใจภาพรวมได้ดีขึ้น แนะนำให้อ่านบทความที่เกี่ยวข้องเพิ่มเติมและฝึกปฏิบัติจริง
อ่านเพิ่มเติม: iCafeForex | XM Signal EA ฟรี | SiamLanCard | Siam2R
สิ่งที่ควรรู้เพิ่มเติมเกี่ยวกับ TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control ยังมีมิติอื่นที่น่าสนใจ การศึกษาเพิ่มเติมจะช่วยให้เข้าใจภาพรวมได้ดีขึ้น แนะนำให้อ่านบทความที่เกี่ยวข้องเพิ่มเติมและฝึกปฏิบัติจริง
อ่านเพิ่มเติม: iCafeForex | XM Signal EA ฟรี | SiamLanCard | Siam2R
สิ่งที่ควรรู้เพิ่มเติมเกี่ยวกับ TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control
TCP/IP Deep Dive: TCP Handshake, Flow Control และ Congestion Control ยังมีมิติอื่นที่น่าสนใจ การศึกษาเพิ่มเติมจะช่วยให้เข้าใจภาพรวมได้ดีขึ้น แนะนำให้อ่านบทความที่เกี่ยวข้องเพิ่มเติมและฝึกปฏิบัติจริง
อ่านเพิ่มเติม: iCafeForex | XM Signal EA ฟรี | SiamLanCard | Siam2R