Was trying to do this myself and came up with this. Probably there is a simpler way, but this is what I came up with.
First, prepare pipes which will be used to make the benchmarking program communicate through the SSH connection.
$ mkfifo /tmp/up /tmp/down
Then establish a connection in ControlMaster mode without executing any remote command. This allows us to authenticate with the host interactively. After the connection is established, SSH will just "hang" here in foreground.
$ ssh $HOST -N -M -S /tmp/control
In a parallel terminal, execute remote
cat in background. It will be our echo server whose latency we will measure. Inputs and outputs are connected to FIFOs:
$ ssh $HOST -S /tmp/control cat </tmp/up >/tmp/down &
And then benchmark a small program (send a byte to
up FIFO, receive a byte from
$ python -m timeit -s 'import os' \
'os.write(3, "z"); z=os.read(4, 1); assert z=="z", "got %s" % z' \
10 loops, best of 3: 24.6 msec per loop
The measure obviously shows the round-trip latency. If you need to repeat the experiment, run the last two commands (
If something seems to go wrong, use SSH
-v flag to get more debugging output.