Skip to content

Instantly share code, notes, and snippets.

@EnergeticPixels
Last active May 22, 2019 02:01
Show Gist options
  • Save EnergeticPixels/4c62fa3eb71fc04812221c7fe107a367 to your computer and use it in GitHub Desktop.
Save EnergeticPixels/4c62fa3eb71fc04812221c7fe107a367 to your computer and use it in GitHub Desktop.
Speeding up Vagrant Synced folders

Setting basic synced folder is easy:

[code] config.vm.synced_folder 'src/' '/srv/website' [/code]

This can be very slow and might get in the way if you are developing on host machine and allowing the sync to happen to see results in the guest machine (vue.js with webpack).

Vagrant synced folders has three 'alternatives':

  • NFS (Network File System). default remote file system for *nix.
  • RSync: Slower than NFS, but this might serve as a failsafe. But remember this is a one-way sync.
  • SMB (Server Message Block): only works with Windows Host.

An upgrade idea is to have a nfsd (NFS serverdaemon) installed on host and then specify it in your vagrantfile as: [code] config.vm.synced_folder 'src/', '/srv/website' type: "nfs" [/code]

Then do a vagrant reload. This will cause three things to happen:

  1. Add anentry in the nfsd's configuration file "/etc/exports" on your host.
  2. reload the NFS server daemon which readsthe location and accepts connections.
  3. Connectto your guest machine and mount the remote folder.

To kick it up a notch, you can use one of two categories:

  • Mount options (guest side only)
    • "udp" -> "tcp": seems that performance is slightly better with TCP in this particular case (speed increase of 1.5)
  • NFSd option (host side)
    • "sync" -> "async": in async mode, hostwill acknoledge write requests before they are actually written to disk. With a VM, the network link between the host and guest is perfect so that there is no risk of data corruption (speed incrwase of x3)

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

Untested when using both options at the same time, so use at your own risk. Works ok with either option by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment