Skip to content
Logo Theodo

Speed up Vagrant Synced Folders

Hugo Lime3 min read

Do you wish your vagrant synced folders to have better performance? Especially if your host machine is running Linux. Here are some tricks to speed it up.

Set up a synced folder

Vagrant is a convenient tool for quickly setting up your dev server, with just one vagrant up from the command-line, every team member can test new features locally.

For me, it is also essential to have a shared folder for the app’s source code so that I can test my feature by simply saving the file from my favorite IDE and not having to deploy the code into the virtual machine every time.

Setting up a basic synced folder is ridiculously easy as it only requires to add the following line in the Vagrantfile:

config.vm.synced_folder "src/", "/srv/website"

with:

Without additional options, Vagrant will delegate the set up to your virtualization backend, e.g Virtualbox or VMware. Unfortunately, it is sometimes very slow.

Vagrant synced folders provides three alternatives:

Using NFS is therefore the best alternative in most situations.

Vagrant NFS

To set up an NFS synced folder you need to have nfsd (NFS server daemon) installed on your host and to specify it in your Vagrantfile as:

config.vm.synced_folder "src/", "/srv/website", type: "nfs"

When you reload your VM with vagrant reload, vagrant will do three things:

  1. It will add an entry in the nfsd’s configuration file /etc/exports on your host.
  2. It will reload the NFS server daemon which will read the /etc/exports and accept connections.
  3. It will connect to your guest machine and mount the remote folder.

Boost your NFS

Now, you might be happy with the default options. But sometimes, especially if you are a Linux user, you might feel that it is too slow. Luckily, Vagrant has a set of available options so let’s tweak the NFS configuration a bit.

The NFS options that impact the speed of the synced folder can be separated in two categories:

If you want to override one option, you also need to write all the other default options. The optimal configuration in my situation is therefore:

config.vm.synced_folder "src/", "/srv/website", type: "nfs",
 mount_options: ['rw', 'vers=3', 'tcp'],
 linux__nfs_options: ['rw','no_subtree_check','all_squash','async']

Feel free to test which options work best for you.

With this setup, reloading a page of my app went from 9 to 2 seconds, making my work much easier. Moreover, I can finally access the legacy part of my application which timed out before.
Vincent Langlet, agile web developer at Theodo

Note: File transfer speed can be easily measured with the dd utility :

dd if=/dev/zero of=./test bs=1M count=100

Liked this article?