Speed up a vagrant machine on windows
Vagrant is a great tool for developing a SilverStripe site, it's easy to set up a new VM for each project. Unfortunately it's really really slow on windows, even on an up-to-date workstation laptop with good CPU, much RAM and SSD.
The bottleneck is VirtualBox's shared folder, it's a never ending coffee break. And SilverStripe has a lot of small files, so it's really a lot to to sync.
But windows doesn't have NFS, does it? Well, there are NFS servers for Win, and even a vagrant nfs plugin, that delivers it out of the box.
So let's install that plugin:
$ vagrant plugin install vagrant-winnfsd
On an issue I was told to enable Windows 8 compatibility mode when I'm running this on Windows 10. I dunno if this is really necessary, but it won't hurt.
After some struggeling I found a config that works, now my VagrantFile looks like this:
Vagrant.configure(2) do |config| config.vm.box = "zauberfisch/silverstripe-wheezy64" #nfs setup config.vm.network "private_network", type: "dhcp" config.vm.synced_folder ".", "/vagrant", :nfs => true, :mount_options => [ 'nfsvers=3', 'vers=3', 'actimeo=1', 'rsize=8192', 'wsize=8192', 'timeo=14', :nolock, :udp, :intr, # :user, #activating this mounts noexec! :auto, :exec, :rw ], group: nil, owner: nil # config.vm.provider "virtualbox" do |vb| vb.memory = "1024" vb.cpus = 2 end end
How much speed does that setting bring? It feels fast, but can you measure it?
Last week i measured a plain SilverStripe installation for my xdebug talk at StripeCon 2016. A normal, cached page needed - take a seat - 3234ms. That's half of a lunch break.
With nfs we only need 357ms when all caches are warm. That's a lot faster and I really look forward enjoying the new speed while developing with my zauberfisch vagrant VM.
I had troubles with the original settings, because it was always mounting as noexec, no matter i defined :exec in the config. For a normal webserver that's no problem, but if you want to run unit tests inside your VM with a composer installed phpunit, it doesn't work, cause you are not allowed to execute /vendor/bin/phpunit.
I searched for a solution and... found it. It's basically the user setting overwriting exec with noexec if it's called afterwards. I guess vagrant is ordering the settings alphabetically, dunno, but commenting out :user fixed it for me.