Persistent SSH Connections

In this article we will see the performance of SSH connections when making connections from a LINUX machine to another LINUX machine, and potential methods to enhance the performance by making cached connections in case there is a need for a large number of repeated SSH connections to be made.

Experimental Scenario and Baseline Measurement

Following is the sample ssh command used for benchmarking:

% time ssh -F ~/.ssh/config my_vm 'exit' ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.182 total

Above example shows the total duration as 1.182s for the ssh command to establish connection to the VM my_vm and run the command exit .

Baseline Establishment

The above command was repeated 10 times to establish the baseline time for ssh connection.

% for i in {{1..10}}; do time ssh -F ~/.ssh/cloudconfig analysis 'exit'; done ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.080 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 3% cpu 1.249 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.143 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.130 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.085 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.165 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.046 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.069 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.160 total ssh -F ~/.ssh/cloudconfig analysis 'exit' 0.04s user 0.01s system 4% cpu 1.065 total

The average of the total CPU time from above 10 operations is computed as follows:

% cat ssh_times.txt | awk '{total += $12} END {print total/10}' 1.1192

ControlMaster

This is a feature in Openssh library that allows reuse of ssh connections