Chokidar(Node.js)的效率如何? [英] How efficient is Chokidar (Node.js)?

查看:223
本文介绍了Chokidar(Node.js)的效率如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上有一个缓存引擎,该引擎缓存在根目录下访问的所有文件.我正在考虑使用Chokidar来(递归地)查看整个目录树中的文件更改,并相应地更新缓存.但是我担心如果子目录包含成千上万个文件会发生什么-Chokidar的效率如何?

I have a caching engine on the server which caches all files accessed under a root directory. I'm thinking of using Chokidar to watch the entire directory tree (recursively) for file changes and update the cache accordingly. But I'm concerned about what would happen if a sub directory contained hundreds of thousands of files - How efficient would Chokidar be?

推荐答案

Chokidar的效率取决于它所运行的操作系统.

Chokidar's efficiency depends on which operating system it's running on.

在OS X上,它使用一个模块,该模块提供对本机fsevents API的访问,该模块非常高效.

On OS X, it uses a module that provides access to the native fsevents API, which is extremely efficient.

在其他系统上,它使用node.js的 fs.watch fs.watchFile API.在后台,fs.watch使用各种系统API来通知更改,这可能是相当有效的. fs.watchFile使用统计信息轮询,这绝对不适用于您所描述的目录.

On other systems, it uses node.js's fs.watch or fs.watchFile APIs. Under the hood, fs.watch uses various system APIs to be notified of changes, which may be reasonably efficient. fs.watchFile uses stat polling, which would definitely be inappropriate for directories as large as you're describing.

我的建议是您设置chokidar选项usePolling: false并尝试一下,以监视您的CPU负载.

My suggestion is that you set the chokidar option usePolling: false and give it a try, monitoring your cpu load.

更新(2015年7月):自最初编写以来,Chokidar已得到实质性改进,并且轮询不再是任何平台上的默认设置.

Update (July 2015): Chokidar has been substantially improved since this was originally written, and polling is no longer the default on any platform.

这篇关于Chokidar(Node.js)的效率如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆