Exercises and code from Hussein Nasser's Course Fundamentals of Networking for Effective Backend Design.
Install the latest Go version on your computer if it is not already installed. Also, if running the Nodejs servers, install the LTS Version.
Then, go to the udpserver
or tcpserver
respective directories and execute the following command:
Go:
go run main.go
Nodejs:
node index.mjs
In your terminal, use the Netcat utility to make the requests.
# TCP
nc -t 127.0.0.1 5500
# UDP
nc -u 127.0.0.1 5500
Note: I have improved the TCP and UDP servers in Go after reading this article from Linode.
This algorithm can affect network performance and to understand it better this article explains the problems with it.
Run tcpdump
to observe the behavior.
sudo tcpdump -X -i lo0 'port 8000'
Go to the tcp-nodelay-go
directory and execute the client and servers.
go run client.go
go run server.go
Then, disable TCP_NODELAY
to see it in action in the client.go
file.
conn.SetNoDelay(false) // Disable TCP_NODELAY; Nagle's Algorithm takes action.
It is also important to know the Delayed Acknowledgement algorithm, because when it works together with Nagle's Algorithm, we may have 400ms delays. The TCP_QUICKACK
is the socket option to disable it. Read more.
- Read how to Build a TCP Connection Pool From Scratch With Go
MIT © André Brandão