Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How efficient is Chokidar (Node.js)?

Tags:

node.js

npm

fs

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?

like image 450
Jon Avatar asked Oct 13 '13 09:10

Jon


1 Answers

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

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

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.

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

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

like image 56
es128 Avatar answered Oct 21 '22 12:10

es128