Python for Network Engineers

Using Iperf to Measure Network Bandwidth

by: George El., November 2018, Reading time: 4 minutes

“iPerf3 is a tool for active measurements of the maximum achievable bandwidth on IP networks. It supports tuning of various parameters related to timing, buffers and protocols (TCP, UDP, SCTP with IPv4 and IPv6). For each test it reports the bandwidth, loss, and other parameters”

you need to run one instance on one machine as server and another instance on second machine as client. to run as server you write

iperf3 -s

to run as client

iperf -c remote-addr-ip

the default setting is to use tcp. if you want to use udp you have to specify -u and the bandwidth target with -b. the default is 1Mbit for UDP.

iperf3 -u -b 10M -c remote-addr-ip

other useful options

  -w, --window    #[KMG]    set window size / socket buffer size
  -M, --set-mss   #         set TCP/SCTP maximum segment size (MTU - 40 bytes)
  -N, --no-delay            set TCP/SCTP no delay, disabling Nagle's Algorithm
  -t, --time      #         time in seconds to transmit for (default 10 secs)
  -n, --bytes     #[KMG]    number of bytes to transmit (instead of -t)

the w parameter is not the tcp window size, it is the application buffer that iperf uses

So I have iperf running as a server on 192.168.1.78 and I run the iperf on another machine on the same network as client

$ ./iperf3 -c 192.168.1.78
Connecting to host 192.168.1.78, port 5201
[  4] local 192.168.1.73 port 2600 connected to 192.168.1.78 port 5201
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.01   sec  11.6 MBytes  96.8 Mbits/sec
[  4]   1.01-2.00   sec  11.1 MBytes  94.0 Mbits/sec
[  4]   2.00-3.01   sec  11.5 MBytes  95.8 Mbits/sec
[  4]   3.01-4.00   sec  11.2 MBytes  95.0 Mbits/sec
[  4]   4.00-5.00   sec  11.2 MBytes  94.2 Mbits/sec
[  4]   5.00-6.00   sec  11.4 MBytes  95.5 Mbits/sec
[  4]   6.00-7.01   sec  11.4 MBytes  94.9 Mbits/sec
[  4]   7.01-8.00   sec  11.2 MBytes  94.9 Mbits/sec
[  4]   8.00-9.01   sec  11.4 MBytes  94.9 Mbits/sec
[  4]   9.01-10.00  sec  11.2 MBytes  94.9 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-10.00  sec   113 MBytes  95.1 Mbits/sec                  sender
[  4]   0.00-10.00  sec   113 MBytes  95.1 Mbits/sec                  receiver

iperf Done.

It reached 95Mbit/sec which is expected as the local switch is 100M

Lets try also udp

$ ./iperf3 -u -b 100M -c 192.168.1.78
Connecting to host 192.168.1.78, port 5201
[  4] local 192.168.1.73 port 57411 connected to 192.168.1.78 port 5201
[ ID] Interval           Transfer     Bandwidth       Total Datagrams
[  4]   0.00-1.00   sec  10.4 MBytes  87.2 Mbits/sec  1331
[  4]   1.00-2.00   sec  11.4 MBytes  95.8 Mbits/sec  1462
[  4]   2.00-3.00   sec  11.4 MBytes  95.8 Mbits/sec  1462
[  4]   3.00-4.00   sec  11.4 MBytes  95.9 Mbits/sec  1463
[  4]   4.00-5.00   sec  11.4 MBytes  95.8 Mbits/sec  1461
[  4]   5.00-6.00   sec  11.4 MBytes  95.9 Mbits/sec  1463
[  4]   6.00-7.00   sec  11.4 MBytes  95.8 Mbits/sec  1462
[  4]   7.00-8.00   sec  11.4 MBytes  95.9 Mbits/sec  1463
[  4]   8.00-9.00   sec  11.4 MBytes  95.8 Mbits/sec  1462
[  4]   9.00-10.00  sec  11.4 MBytes  95.9 Mbits/sec  1462
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Jitter    Lost/Total Datagrams
[  4]   0.00-10.00  sec   113 MBytes  95.0 Mbits/sec  1.597 ms  0/14490 (0%)
[  4] Sent 14490 datagrams

iperf Done.

So I have 0% loss which says that my network works fine

If I change the socket buffer to 100

$ ./iperf3 -c 192.168.1.78 -w 100
Connecting to host 192.168.1.78, port 5201
[  4] local 192.168.1.73 port 2644 connected to 192.168.1.78 port 5201
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec   119 KBytes   975 Kbits/sec
[  4]   1.00-2.00   sec   122 KBytes  1.00 Mbits/sec
[  4]   2.00-3.00   sec   121 KBytes   992 Kbits/sec
[  4]   3.00-4.00   sec   125 KBytes  1.03 Mbits/sec
[  4]   4.00-5.00   sec   122 KBytes   996 Kbits/sec
[  4]   5.00-6.00   sec   119 KBytes   972 Kbits/sec
[  4]   6.00-7.00   sec   123 KBytes  1.00 Mbits/sec
[  4]   7.00-8.00   sec   125 KBytes  1.02 Mbits/sec
[  4]   8.00-9.00   sec   125 KBytes  1.03 Mbits/sec
[  4]   9.00-10.00  sec   123 KBytes  1.01 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-10.00  sec  1.19 MBytes  1.00 Mbits/sec                  sender
[  4]   0.00-10.00  sec  1.19 MBytes  1.00 Mbits/sec                  receiver

iperf Done.

I get barely 1Mbit, so the application buffer plays an important role in the application performance.

comments powered by Disqus