Vagrant,共享文件夹:利用inotify over NFS [英] Vagrant, shared folder: take advantage of inotify over NFS
问题描述
我们的Symfony2 webapp在开发模式中使用Assetic观察器来随时重新编译资产。
Our Symfony2 webapp uses the Assetic watcher in development mode to re-compile assets on the go.
webapp在一个运行在Vagrant VM中的Docker容器中运行(Ubuntu 12.04精确)。
主机是OSX 10.9小牛,它通过NFS(v3)共享与VM共享代码文件夹,代码通过Docker中的主机/客户机卷装载到容器中。
The webapp runs in a Docker container which runs in a Vagrant VM (Ubuntu 12.04 Precise). The host is OSX 10.9 Mavericks and it shares the code folder with the VM through a NFS (v3) share and the code is mounted in the container via a host/guest volume in Docker.
由于inotify似乎无法通过NFSv3检测文件修改,观察者工作在轮询模式,这可能非常慢(约1/2分钟来检测修改)。
Since inotify seems to not be able to detect file modifications over NFSv3, the watcher works in polling mode which can be very slow (~1/2 minutes to detect the modification).
我已经阅读了NFSv4是否符合标准,但我没有发现任何好的资源。
I've read that NFSv4 is inotify compliant but I did not found any good ressource on that.
有没有办法使NFS / inotify一起工作?
Is there a way to make NFS/inotify works together?
推荐答案
不幸的是,inotify 不能在NFS上工作。在内核中的VFS(虚拟文件系统)层中挂起自己的inotify工作。每当修改发生时,inotify都知道它,因为修改发生在同一台机器上,因此在同一个内核中 - 这使整个事情成为可能。
Unfortunately, inotify cannot work on NFS. inotify works by hooking itself in the VFS (virtual filesystem) layer, in the kernel. Whenever a modification happens, inotify knows about it, because the modification happens on the same machine, therefore in the same kernel — which makes the whole thing possible.
使用NFS,修改发生在服务器上,并且客户端需要通知。但是,在进行更改时,NFS不会通知客户端。否则,它不会扩展。 NFS已经被设计(和操作)在单个服务器上拥有数千个客户端。想象一下,如果你做了一个微小的变化,服务器必须推送给所有客户端!
With NFS, modifications happen on the server, and notifications are expected on the client. But the NFS doesn't notify the clients when a change is made. Otherwise, it wouldn't scale. NFS has been designed (and operated) to have thousands of clients on a single server. Imagine if you do a tiny change, and the server has to push it to all clients!
当然可以说嘿,应该有一个订阅机制NFS协议,以便客户端可以告诉服务器他们想知道特定位置发生的更改。那么,NFS是30年前设计的,所以原谅他们不包括这个订阅/通知系统: - )
Of course, you could say "hey, there should be a subscription mechanism in the NFS protocol, so that clients can tell the server that they want to know about changes happening in a specific location". Well, NFS was designed 30 years ago, so forgive them for not including this subscription/notification system :-)
我不熟悉Assetic,但也许你可以有一个自定义脚本来手动监视更改,并在每次检测到更改时重新编译资源。只需浏览包含资源的目录,跟踪关联数组中每个文件的mtime,并且每次检测到新文件(或新的mtime)时,重新编译。 Boom!
I'm not familiar with Assetic, but maybe you could have a custom script to watch for changes manually, and re-compile assets each time you detect a change. Just walk through the directory containing the source for the assets, keep track of the mtime of each file in an associative array, and each time you detect a new file (or a new mtime), recompile. Boom!
另请参见关于inotify和NFS 。
这篇关于Vagrant,共享文件夹:利用inotify over NFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!