Conclusions:
During the experiment, two sets of data were collected for trials with different hosts. The first set of data was collected for the client and server with Nagle's algorithm enabled. The second set of data was collected with Nagle's algorithm disabled. The observations show that with Nagle's algorithm disabled, the latency of packets of larger sizes (i.e., 100,000 bytes and 1,000,000 bytes) was halved. For 10,000-byte packets, there was no significant change, but for smaller packets, the latency decreased significantly.
Nagle's algorithm was made to avoid packet congestion in a network. In small packet size cases, the echo client in this experiment is an example of an application repeatedly emitting data in small chunks. This is the exact situation that Nagle's algorithm was made to handle, which would explain the significant increase in latency as the packet sizes become very low. TCP packets have a 40-byte header, so for 10-byte and 100-byte packets, the overhead of sending these chunks individually is 400% and 40% respectively. These percentages of overhead seem to correlate with the commensurate latency increases.
For the same host trials, the packets are looped back to the machine in the kernel. This may be the reason why the effects of Nagle's algorithm in the different host trials are unseen in the same host trials. Considering how low the latency is for 10-byte, 100-byte, 1,000-byte, and 10,000-byte packets on the same host, it seems more likely that this may be a lower bound for same host latency. From sizes of 10,000 bytes to 1,000,000 bytes, it is clear to see the proportional increase in latency again.
Compilation:
The attached code can be compiled without the use of additional flags. The TCP_NODELAY option is enabled through code. The host name is hard-coded into the echo client, and the port number is hard-coded into both the client and the server. The byte-sizes of the packets are hard-coded into the echo client, so for each trial, the code must be recompiled. However, the echo server is not dependent on this hard-coded packet size, so it can stay running while the echo client is recompiled. Logs from Wireshark for the different host low packet size trials have also been attached.