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
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
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
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
$ 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