A demo of "slow-start" in TCP, a congestion control concept. Written in Go.
This repository contains a simple simulation of TCP's slow-start congestion control mechanism, implemented in Go. It demonstrates how the congestion window (cwnd) grows exponentially during the slow-start phase and how the server reacts to packet loss by reducing the window size.
This is inspired by https://hpbn.co/building-blocks-of-tcp/#slow-start
It's a brilliant piece on the building blocks of TCP and how "slow start" works.
The server sends data packets based on the current congestion window size and waits for ACKs from the client. On receiving ACKs, the congestion window increases. If a packet loss is detected, the window size is reduced.
Start the server, which listens for incoming client connections and begins sending packets while applying TCP slow-start behavior.
go run server.go
The client connects to the server and receives data while sending ACKs back for each batch of packets received.
go run client.go
Both server and client log events such as packet transmissions, ACKs, congestion window updates, and packet loss. Logs include timestamps to show the progression of each round-trip time (RTT) cycle.
Server:
2024-10-19 12:30:01 - Server is listening on localhost:8080
2024-10-19 12:30:05 - Current congestion window (cwnd): 1
2024-10-19 12:30:06 - Sent: Packet 1
2024-10-19 12:30:06 - Received ACK from client.
2024-10-19 12:30:06 - ACK successful, increasing cwnd. New cwnd = 2
...
Client:
2024-10-19 12:30:05 - Connected to server. Waiting for data...
2024-10-19 12:30:05 - Received: Packet 1
2024-10-19 12:30:05 - Sent: ACK
...
No comments yet.
Sign in to be the first to comment.