12

Grunt watch (grunt-contrib-watch) is used to trigger reload of web app in browser. However, it is slow to notice file changes when running in a Vagrant virtual machine using NFS for synced folders. Changing a file triggers a reload only after about 5 seconds although it is expected to happen almost instantly. Why is grunt watch so slow to detect changes? Is there any way to make it faster?

With VirtualBox synced folders grunt watch detects file changes almost instantly. However, as VirtualBox synced folders are unacceptably slow for certain other operations on large amounts of files it is unfortunately not an option to revert back to it in this case.

Markus Miller
  • 3,695
  • 2
  • 29
  • 33
  • I had the same problem when using NFS w/ Vagrant. I finally decided to use Samba and now Grunt detects file changes almost instantly. Here's a handy guide for setting up Samba on the Vagrant box: http://www.kieronhoward.co.uk/vagrant-windows-improve-slow-performance-using-smb-instead-nfs/ – nanook Dec 16 '14 at 13:54
  • When I have this issue I find `ctrl + c` and running grunt again is faster - but for most changes the wait is fine. – ArleyM Dec 17 '14 at 20:02

1 Answers1

26

Try these mount options in your Vagrantfile:

type: "nfs", mount_options: ['actimeo=1']

This will greatly reduce the NFS file attribute caching timeout. I was having similar troubles, seeing large delays with Vagrant/NFS when waiting for gulp and Django server reloads. This fixed it; file changes are now detected instantly.

Daniel Hawkins
  • 1,165
  • 13
  • 12
  • 3
    Thanks, this is the same solution that I arrived at independently after writing this question. Hope others will not have to spend as much time on debugging this. – Markus Miller Jan 24 '15 at 12:46
  • 1
    @realtebo config.vm.synced_folder "./", "/vagrant", type: "nfs", mount_options: ['actimeo=1'] – Strake Jul 25 '17 at 21:58
  • I don't comment here really often, but this problem has been plaguing my team for a while with django runserver not reloading properly... This setting makes it so much faster, I can't thank you enough for posting it here. – Remiz May 01 '20 at 16:27