简体   繁体   中英

File modification watch (Webpack, Guard...) issue over NFS in Virtual Machine (VM)

I know there are multiple threads discussing NFS mounted volumes and file modification watch issues. Since most of the discussions are old, some from 8 years ago, my goal here is to compile some and bring them up again to check what are the most recent solutions you guys have been using to handle those issues.

The core problem
Linux relies on inotify , a kernel subsystem, to generate events when files are modified (changed/deleted) and those events are most often used by developer tools to watch files to trigger some task. The core issue is that when you have a volume/folder shared via NFS protocol, it doesn't generate the events, and therefore the tools need to use polling methods instead of trigger based on events.

Polling methods often create multiple issues such as high CPU usage, delay to trigger tasks over file alterations, and so on.

Some of the watching tools:

Popular threads

Nice solution attempts

My current challenge
We run our dev env using macOS as host, Vagrant (provider Virtualbox) with Alpine Linux as the guest, and Docker containers for the services (Node, NGINX...), the setup is running smoothly for everything aside from when the frontend developers need to watch file modifications using webpack watch feature. It works with polling but with a delay of 3-10 seconds.

Any updates or any recommendations on how you solve this problem?

I've been able to work around this issue by setting the actimeo NFS option to 1. This reduces the length of time that NFS caches the file system attributes which seems to keep the host and guest in near sync. Webpack watch now picks up changes for me almost immediately.

Here is the VagrantFile setting I use to implement this NFS share. Note the mount_options setting

config.vm.synced_folder "./my_host_syncd_folder", "/guest/path", type: 'nfs', mount_options: ['actimeo=1']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM