Increase performance of Vagrant + VirtualBox synced folders

The standard synced folders set up in Vagrant uses the VirtualBox’s shared folders feature. Unfortunately, the performance of shared folders leaves a lot to be desired. There is a solution to this poor performance, which involves switching to an NFS-based solution.

This can be done simply by adding the nfs flag to the config.vm.synced_folder setting in your Vagrantfile:

config.vm.synced_folder '.', '/vagrant', nfs: true

You also need to make sure you are using Vagrant’s private_network networking option:

config.vm.network "private_network", ip: "192.168.56.101"

Once you have done this, you can vagrant up (if your VM is not currently running) or vagrant reload (if you VM is currently running) to get NFS up and running. When you do this for the first time, you’ll likely be prompted to enter your administrator’s password so that the NFS details can be saved to /etc/exports:

==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
Password:

The performance increase you experience will vary, but on my 1.3 GHz Intel Core i5 MacBook Air, I experienced a 6x performance boost. I used wrk to benchmark the VM web server performance before and after:

Using VirtualBox shared folders:

$ wrk http://localhost:8000
Running 10s test @ http://localhost:8000
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.00us    0.00us   0.00us     nan%
    Req/Sec     4.11      3.22     9.00     55.56%
  10 requests in 10.04s, 1.22MB read
  Socket errors: connect 0, read 0, write 0, timeout 10
Requests/sec:      1.00
Transfer/sec:    124.20KB

Using NFS:

$ wrk http://localhost:8000
Running 10s test @ http://localhost:8000
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.38s   214.51ms   1.86s    63.24%
    Req/Sec     5.33      3.83    19.00     71.43%
  68 requests in 10.05s, 8.40MB read
Requests/sec:      6.76
Transfer/sec:    855.64KB

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.