Logging into a Vagrant machine using vagrant ssh takes several seconds, while logging in using a direct invocation of ssh only takes tenths of milliseconds (see below for details). The slowness of vagrant ssh is especially annoying in interactive use with repeated logins/logouts, where it is immediately noticeable (and reflects badly on Vagrant as looking slow). Is there any way of getting the vagrant ssh execution time on par with plain ssh?
$ time vagrant ssh -c :
Connection to 127.0.0.1 closed.
Time: 1.72s real 1.38s user 0.23s system 93.87 cpu
$ vagrant ssh-config > config && time ssh -F config default :
Time: 0.04s real 0.01s user 0.00s system 35.31 cpu
$ vagrant version
Installed Version: 1.6.3
Latest Version: 1.6.3
Possibly something similar to #2462.
It's probably mostly Ruby startup time. I dare say you'd see similar time for, say vagrant help.
There is a lot going on in vagrant ssh that we've sped up but its hard to get much faster without just plain caching the connection data and ssh-ing to it. We might do that.
When you invoke vagrant ssh it does a lot of things that ssh doesn't:
ssh directly)exec into ssh.Your comparison of vagrant ssh to ssh would be more correct if you timed both vagrant ssh-config + ssh vs. vagrant ssh, because that is what is going on.
By writing vagrant ssh-config to a file you're caching that data, and vagrant ssh does not cache this data.
That should explain things.
This has generally always been the tradeoff between vagrant ssh-config and vagrant ssh: the former you can cache, the latter promises to SSH to the write place and error if it doesn't exist.
Thanks for the thorough explanation. If there is any way of finding a solution that despite the issues mentioned above would speed up SSH:ing into a Vagrant machine (for example using some kind of caching of the SSH configuration), that would be appreciated. Everything, including fast SSH, that makes Vagrant more convenient to use helps its adoption among new users.
@vsipuli Yes, you can use vagrant ssh-config and periodically just refresh the information. The caveat (with any caching) is that the information could be wrong. The checks to verify the information is correct is really the extremely expensive step.
We'll implement caching one day, but not yet. Closing for now. I hope this illuminates some internals!
A while ago, I've written a simple shell-wrapper that boils everything that vagrant ssh can do (with multiple boxes and providers and ..) down to a stupid _ssh-into-default-virtualbox_: https://github.com/filex/vagrant-ssh.
It's by no means a general replacement for vagrant ssh. But it can handle direct commands like vagrant-ssh -- whoami.
Most helpful comment
A while ago, I've written a simple shell-wrapper that boils everything that
vagrant sshcan do (with multiple boxes and providers and ..) down to a stupid _ssh-into-default-virtualbox_: https://github.com/filex/vagrant-ssh.It's by no means a general replacement for
vagrant ssh. But it can handle direct commands likevagrant-ssh -- whoami.