Grunt watch detects file changes only after 5 seconds with Vagrant and NFS
Asked Answered
C

1

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.

Comptroller answered 20/11, 2014 at 9:14 Comment(2)
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: kieronhoward.co.uk/…Qatar
When I have this issue I find ctrl + c and running grunt again is faster - but for most changes the wait is fine.Desuetude
T
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.

Tedmann answered 23/1, 2015 at 21:4 Comment(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.Comptroller
@realtebo config.vm.synced_folder "./", "/vagrant", type: "nfs", mount_options: ['actimeo=1']Homothallic
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.Renfroe

© 2022 - 2024 — McMap. All rights reserved.