iperf icon indicating copy to clipboard operation
iperf copied to clipboard

Systemd-based socket activation

Open schaten opened this issue 4 years ago • 6 comments

  • Version of iperf3 (or development branch, such as master or 3.1-STABLE) to which this pull request applies: master

  • Issues fixed (if any): #742

  • Brief description of code changes (suitable for use as a commit message): Allow iperf3 to receive sockets from systemd.

This patch enables systemd-based socket activation of iperf3. To test, build and install this fork, then:

  • mv contrib/iperf3_@.* /etc/systemd/system/
  • systemctl daemon-reload
  • systemctl start iperf3_5201

This will make systemd listen on port 5201. As soon as a client tries to connect, iperf3 is started and takes over.

I originally wanted to add multi-user support, but this is not as easy due to the separate control / data connections. In combination with loadbalancing (i.e. based on the IP address, client could be NATted to a socket-activated iperf3 instance) it might still be useful.. Also, as the socket-activation was a separate issue, maybe it's useful to others. :)

schaten avatar Jun 19 '21 21:06 schaten

This is very helpful. Absent multiple simultaneous client support in iperf3, this allows me to have systemd monitor, say, 24 ports and dynamically launch one-off iperf3 servers to service client requests on those ports. I've built iperf3 from schaten's fork and it works perfectly. It took me a bit to realize that libsystemd-dev was a dependency. I guess that should have been obvious.

Edit: I think schaten's fork requires libsystemd-dev > version 237 in order to work. I.e. won't work on Ubuntu 18.04, but works fine on Ubuntu 20.04 which has version 245.

gharris999 avatar Dec 30 '21 18:12 gharris999

Cool! Yes, it's very helpful!

friesen-hbk avatar Jan 05 '22 11:01 friesen-hbk

what's blocking the merge of this?

mikelpr avatar Aug 29 '24 02:08 mikelpr

@schaten Thanks for implementing this functionality!

I would like to use a current esnet:master (https://github.com/esnet/iperf/commits/master/) with the socket activation functionality added. To achieve that I created a git merge commit https://github.com/eriksjolund/iperf/commit/807d33e942cb008ebd7c2f7e8a4f1e76757d1a63 in https://github.com/eriksjolund/iperf/tree/support-socket-activation

I don't know how to properly do git merges, especially the question of which name to write for author. I hope I got it right. Anyway, a better solution would be to rebase schaten:master on to esnet:master

@schaten could you rebase on to esnet:master and resolve the trivial conflicts?

eriksjolund avatar Sep 25 '24 18:09 eriksjolund

Glad to hear this was useful. Thanks everyone. :) I rebased the branch. Maybe someone (@bmah888) is interested in merging it.

Somehow it took me way too long to test it afterwards, because of the following things. Leaving it here as a reference:

  • Don't forget to regenerate the configure script by running autoconf... Probably very obvious but I don't use autotools so often. The configure script in the git repo should be updated before merging this also. I didn't include that because it changes other stuff that seems unrelated.
  • The socket is started with systemctl start [email protected] (note the '@'), sorry I got this wrong in the initial post here.
  • In the service file under the Unit section, the line Environment=LD_LIBRARY_PATH=/usr/local/lib might be needed if iperf was installed manually with sudo make install.
  • Install libsystemd-dev before building, as @gharris999 mentioned.

schaten avatar Sep 25 '24 23:09 schaten

Hi 👋 , Are there plans to merge this?

Zerka30 avatar Jul 10 '25 13:07 Zerka30