Apr 20 2006
Speeding up SSH: fsh vs. OpenSSH v4
I have been using fsh to speed up SSH operations for a few years, and it’s mostly worked well. An SSH tunnel is opened, and is reused for all operations. The two drawbacks are:
- You need fsh installed on the machine you connect to.
This means that you cannot always use fsh, and you sometimes need to use ssh instead. I solved this by writing a wrapper to pick between fsh and ssh depending on which machine I connect to. - It sometimes choke, and fshd needs to be restarted.
Thanks to Quick-Tip: Reusing OpenSSH connections to the same host, I got OpenSSH v4 to do this natively, using its multiplexing capability. You don’t need extra software on the machine you’re connecting to.
It’s even slightly faster:
hugo@jibboom ~% time fsh localhost ls >/dev/null fsh localhost ls > /dev/null 0.05s user 0.01s system 39% cpu 0.141 total hugo@jibboom ~% time ssh localhost ls >/dev/null ssh localhost ls > /dev/null 0.01s user 0.00s system 10% cpu 0.082 total
And it even works for remotely logging in, while fsh is only designed for running commands remotely.
There is one drawback though. fsh, when ran for the first time, spawns a daemon (fshd) which takes care of the multiplexing. The daemon times out if fsh has not been used for a certain amount of time. So you basically run fsh without wondering if you have fshd running: it will take care of it on its own.
With OpenSSH v4, you need to have one SSH session open that is the master in order for other SSH sessions to use it. If you have a tunnel running, then you’re all set: this tunnel will be started manually and will stay up for a long time, and will be used as the master. However, if you just use SSH for say Subversion access, then it’s likely that when you run your svn commit, there will not be an SSH connection up to this machine already and a new SSH connection will be created. So you won’t gain anything.
The ideal solution seems to be a daemon alla-fshd which uses OpenSSH’s native multiplexing capability instead of coming up with its own like fsh does.


April 25th, 2006 at 0:24
Excellent tip, thanks!!
One minor issue I found is that it doesn’t know that foo.example.org is the same as foo, so if you have a tunnel open to foo.example.org and later run “ssh foo”, the tunnel connection doesn’t get reused.
Similarly for machines with multiple names, e.g. cvs.example.org and realhostname.example.org.
I found an easy workaround for this: create symlinks in the temp dir used to track open connections, e.g.
cd $HOME/tmp
ln -s gerald@foo.example.org\:22 gerald@cvs.example.org\:22
October 29th, 2008 at 18:46
[...] fshがpython-2.4以降にちゃんと対応していないので、fshを使ったシステム構成は後で困ることになるなあ、となんとなく悩んでいたのだが、ふと調べてみると「Speeding up SSH: fsh vs. OpenSSH v4 」という記事を見つけた。そのエントリにリンクされている「Quick-Tip: Reusing OpenSSH connections to the same host 」という記事によれば、OpenSSHのバージョン4以降であればfshのようなコネクションプーリング用のプログラムなしでもコネクションの再利用が出来るらしい。やり方はいたって簡単。$HOME/.ssh/configを編集して下のような行を追加する。 [...]