Multiple Instances of iperf in Linux

iperf, the network performance testing software, by default runs a single test from a client to server (e.g. a single TCP connection). Using the -P or --parallel option in the client, you can run multiple parallel tests from the client to a single server. However sometimes you may want to use different configurations or run tests in serial, e.g. one after another. Of course you can manually do this in a terminal. The following gives some example Bash scripts to automate some of the tasks.

The three example scripts are:

The scripts are examples that I quickly prepared. They are by no means perfect and only have been tested briefly between two Ubuntu 12.04 computers. You should be able to modify them to suit your needs.

Using the Scripts

Download and save the scripts. They don't need an extension. I'll assume you save them as: iperf-parallel-servers, iperf-parallel-clients and iperf-serial-clients. To execute the scripts, make sure you have eXecute permissions by running:

$ chmod u+x iperf-parallel-servers iperf-parallel-clients iperf-serial-clients

To execute the scripts simply type its name, preceeded by ./ (meaning in the current directory) and followed by any options (see next sections). This assumes the scripts are in your current working directory. If you want to be able to execute the scripts from any directory then you'll need to add them to a directory in your path.

Multiple Parallel iperf Servers

It is not too hard to manually start multiple instances of the iperf server with different ports in different terminals and leave them running for clients to connect to. The script iperf-parallel-servers automates this process. Here is an example:

$ ./iperf-parallel-servers 3 server-report

By default it takes two input arguments:

  1. Number of instances of the server. By default it starts each server on a different port, starting at 5001. So in the example the servers will be running on ports 5001, 5002 and 5003.
  2. Base file name of server report. Rather than outputing to standard output, the results from iperf are saved in a file. In this case, each server will save a file, giving: server-report-5001.txt, server-report-5002.txt, server-report-5003.txt.

Each server instance runs in the background. How do you stop it later? Use pgrep and pkill. To see the process running with iperf in the name run:

$ pgrep iperf
2812
2813
2814

This shows the process ID's for the three iperf instances. You can leave the servers running for multiple tests. Once you've finished, you can kill them:

$ pkill iperf

Multiple Parallel iperf Clients

Assuming you have multiple iperf server instances already running on computer with IP 1.1.1.1, then you can use iperf-parallel-clients to start the same number of iperf clients.

$ ./iperf-parallel-clients 1.1.1.1 3 10 client-report

By default it takes four input arguments:

  1. IP address of the server.
  2. Number of instances of the client. By default it starts each client to connect to a different server port, starting at 5001. So in the example the servers must be running on ports 5001, 5002 and 5003.
  3. Duration of the test, in seconds.
  4. Base file name of client report. Rather than outputing to standard output, the results from iperf are saved in a file. In this case, each client will save a file, giving: client-report-1.1.1.1-5001-10.txt, client-report-1.1.1.1-5002-10.txt, client-report-1.1.1.1-5003-10.txt.

The clients are run in the background, so you see no output on the terminal. How do you know when the clients are finished? Again use pgrep:

$ pgrep iperf
6403
6404
6405

The above shows there are currently three instances of iperf running (the clients). When the clients have finished, then pgrep iperf will return no results, meaning no instances of iperf are running.

Using UDP (instead of TCP)

By default, iperf uses TCP. If you want to use UDP instead, then both iperf-parallel-servers and iperf-parallel-clients take additional iperf options as optional command line inputs. Just add the exact iperf options you want to the end of the script command line input. For example, for the server to use UDP add the -u option:

$ ./iperf-parallel-servers 3 server-report-udp -u

For the client to use UDP, add the -u option and set the sending rate with the -b option:

$ ./iperf-parallel-clients 1.1.1.1 3 10 client-report-udp -u -b 10M

You can add any iperf options to the end, not just for UDP.

Multiple Serial iperf Clients

The final script assumes there is a single iperf server running, and starts multiple iperf clients in serial, i.e. one after another. Between each iperf, the script sleeps (does nothing) for a random period. The general result is something: do nothing for 7 seconds; run iperf client; do nothing for 12 seconds; run iperf client; do nothing for 8 seconds; run iperf client; ...

To run the clients:

$ iperf-serial-clients 192.168.0.104 5010 10 5 15
Sun Feb  3 11:25:02 ICT 2013
Sleeping for 21 seconds
Running iperf for 10 seconds
------------------------------------------------------------
Client connecting to 192.168.0.104, TCP port 5010
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.103 port 47795 connected with 192.168.0.104 port 5010
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.2 sec  7.88 MBytes  6.49 Mbits/sec
Sleeping for 2 seconds
Running iperf for 10 seconds
------------------------------------------------------------
Client connecting to 192.168.0.104, TCP port 5010
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.103 port 47796 connected with 192.168.0.104 port 5010
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.5 sec  6.12 MBytes  4.91 Mbits/sec
Sleeping for 17 seconds
Running iperf for 10 seconds
------------------------------------------------------------
Client connecting to 192.168.0.104, TCP port 5010
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.103 port 47797 connected with 192.168.0.104 port 5010
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.4 sec  4.12 MBytes  3.32 Mbits/sec
Sleeping for 10 seconds
Running iperf for 10 seconds
------------------------------------------------------------
Client connecting to 192.168.0.104, TCP port 5010
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.103 port 47798 connected with 192.168.0.104 port 5010
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.5 sec  6.00 MBytes  4.81 Mbits/sec
Sleeping for 13 seconds
Running iperf for 10 seconds
------------------------------------------------------------
Client connecting to 192.168.0.104, TCP port 5010
TCP window size: 23.5 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.103 port 47799 connected with 192.168.0.104 port 5010
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.6 sec  5.88 MBytes  4.67 Mbits/sec
Sun Feb  3 11:26:57 ICT 2013

By default it takes four input arguments:

  1. IP address of the server.
  2. Port number of the server.
  3. Time of each iperf test, e.g. 10 seconds.
  4. Number of iperf tests.
  5. Average time of sleeping between tests, in seconds.

In the above example there are 5 iperf tests, each running for 10 seconds. Each test is preceeded by a random sleep time. The average sleep time is 15 seconds. The random number is chosen between 0 and 30 seconds. So you see at the start the script sleeps for 21 seconds, then runs a 10 second iperf test. Then it sleeps for 2 seconds and then runs another iperf test.

If you don't want to sleep between tests, i.e. run one test immediately after the other, then set the average sleep time to 0.

Note the output of this script is to the terminal, not to a file. Also the output gives some information about the sleep time as well as a the start time and finish time. As with the previous two scripts, other iperf options (like UDP) can be added at the end.