[英]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.我知道有多个线程在讨论NFS挂载卷和文件修改监视问题。 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.由于大多数讨论都是旧的,有些是 8 年前的,我的目标是整理一些并再次提出来检查你们用来处理这些问题的最新解决方案是什么。
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. Linux 依赖于inotify
,一个 kernel 子系统,在文件被修改(更改/删除)时生成事件,开发人员工具最常使用这些事件来监视文件以触发某些任务。 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.核心问题是当您通过 NFS 协议共享卷/文件夹时,它不会生成事件,因此工具需要使用轮询方法而不是基于事件触发。
Polling methods often create multiple issues such as high CPU usage, delay to trigger tasks over file alterations, and so on.轮询方法通常会产生多个问题,例如高 CPU 使用率、因文件更改而延迟触发任务等。
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.我们使用 macOS 作为主机运行我们的开发环境,Vagrant(提供者 Virtualbox)以 Alpine Linux 作为来宾,Docker 容器用于服务(节点,NGINX ...),除了前端开发人员之外的所有设置都运行顺利需要使用 webpack 监视功能监视文件修改。 It works with polling but with a delay of 3-10 seconds.它适用于轮询,但有 3-10 秒的延迟。
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.我已经能够通过将actimeo NFS 选项设置为 1 来解决这个问题。这减少了 NFS 缓存文件系统属性的时间长度,这似乎使主机和来宾保持接近同步。 Webpack watch now picks up changes for me almost immediately. Webpack watch now 几乎立即为我获取更改。
Here is the VagrantFile setting I use to implement this NFS share.这是我用来实现此 NFS 共享的 VagrantFile 设置。 Note the mount_options setting注意mount_options设置
config.vm.synced_folder "./my_host_syncd_folder", "/guest/path", type: 'nfs', mount_options: ['actimeo=1']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.