Network throughput measurement using netcat

There are many network throughtput and performance measurement tools available. One of the most widely used one is “iperf”. But, I found “netcat” to be a very versatile and fantastic tool to do the same.

The only “extra” requirement is to have shell access to both sides, so that netcat could be used.

First install the required tools
apt-get install netcat-traditional bwm-ng pv

Considering “machine1” and “machine2” are the two systems on both side of the link. Do the following

machine1:$ nc -l -p 5000 | pv > /dev/null
machine2:$ dd if=/dev/zero | pv | nc ip_address_or_hostname_of_machine1 5000

Netcat of machine1 opens a TCP listening socket and dumps the data to /dev/null. machine2 reads from /dev/zero and forwards that data to machine1 through netcat. Here, flow control is done by TCP stack and keeps the throughput just below the network link speed. Normally “pv” prints the pipe throughput in bytes, so multiply the real time value of “pv” by 8 to get the throughput in bits.

Tools like “bwm-ng” could be used to monitor the througput of the the interface instead of or along with “pv” also.

Some version of of netcat does not require “-p” in listening mode, so the comment could be “nc -l 5000” instead. In the sending side “cat” or “pv” could be used instead of “dd” also. But “dd” prints a nice summary when it is interrupted.

Of course, this is not completely one directional because TCP acknowledgements would be forwarded from machine1 to machine2, but that is much smaller compared to the data flowing in the forward direction.

If we have the liberty of having more shells, one more pair of netcat sessions could be opened in the reverse direction so that simultaneous/full duplex throughput could be measured.

I used this method consistently with Gigabit Ethernet and WiFi many times.

Published by Anand Sivaram (आनन्दः )

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: