ControlMaster functionality in SSH has been around for a while, but I learned about it only yesterday: it's impressive.

ControlMaster multiplexes all connections to defined hosts through a single TCP connection, dramatically lowering the time it takes to initiate a new connection. Only worthwhile doing if you set up multiple connections to the same host.

For example, from where I am at the moment, running a short command over SSH takes almost 3.5 seconds of wall-clock time:

time ssh 'uname'

real    0m3.403s
user    0m0.008s
sys     0m0.007s

I enable ControlMaster by configuring the following in ~/.ssh/config:

Host *
    ControlMaster auto
    ControlPath ~/.ssh/controlmaster/%r@%h:%p

I create the specified directory for the Unix sockets, and start the first session to the target host.

In another terminal, I then re-run the command I used above:

time ssh 'uname'

real    0m0.108s
user    0m0.003s
sys     0m0.004s

Very impressive. This is an SSH option I will keep enabled.

OpenSSH 5.5 introduces an option called ControlPersist which automatically starts a background multiplexer when connecting to a host for the first time. This background connection can stay alive indefinitely or it can be set to close after a specified duration of inactivity.


blog comments powered by Disqus