NodeJS:如何查看服务器端的大量文件/文件夹以进行更新? [英] NodeJS: How would one watch a large amount of files/folders on the server side for updates?

查看:26
本文介绍了NodeJS:如何查看服务器端的大量文件/文件夹以进行更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型 NodeJS 应用程序,它本质上用作基于浏览器的桌面搜索,用于多个用户可以查询的基于 LAN 的服务器.LAN 上的用户都可以访问该服务器上的共享文件夹,并且传统上习惯于将文件放在该文件夹中以供所有人共享,我希望保持该过程相同.

I am working on a small NodeJS application that essentially serves as a browser based desktop search for a LAN based server that multiples users can query. The users on the LAN all have access to a shared folder on that server and are traditionally used to just placing files within that folder to sharing among everyone, and I want to keep that process the same.

我遇到的第一个解决方案是 fs.watchFile在其他 stackoverflow 问题中已经涉及到.在第一个问题中,用户Ivo Wetzel 指出在 linux 系统上 fs.watchFile 使用 inotify 但是,认为 fs.watchFile 不应该用于大量文件/文件夹.

The first solution I came across was the fs.watchFile which has been touched on in other stackoverflow questions. In the first question user Ivo Wetzel noted that on a linux system fs.watchFile uses inotify but, was of the opinion that fs.watchFile should not be used for large amounts of files/folders.

在另一个关于 fs.watchFile 用户的问题中="https://stackoverflow.com/users/538551/tjameson">tjameson 首先重申在 Linux 上 inotify 将由 fs.fileWatch 使用,并建议仅使用 node-inotify-plusplusnode-walk 但再次声明这种方法不应用于大量文件.通过评论和回复,他建议只查看目录的修改时间,然后重新扫描相关目录以查找文件更改.

In another question about fs.watchFile user tjameson first reiterated that on Linux inotify would be used by fs.fileWatch and recommended to just use a combination of node-inotify-plusplus and node-walk but again stated this method should not be used for a large number of files. With a comment and response he suggested only watching the modified times of directories and then rescanning the relevant directory for file changes.

我最大的障碍似乎是,即使有 tjameson 的建议,监控的文件夹数量仍然存在硬限制(其中有很多并且还在不断增加).此外,它必须递归完成,因为目录树有些深,并且也可能在较低的分支处发生变化,因此我必须在每个文件夹级别监视以下内容(或者监视文件夹的修改时间,然后扫描以了解发生了什么):

My biggest hurdles seem to be that even with tjameson's suggestion there is still a hard limit to the number of folders monitored (of which there are many and growing). Also it would have to be done recursively because the directory tree is somewhat deep and can also be subject to change at the lower branches so I would have to monitor the following at every folder level (or alternatively monitor the modified time of the folders and then scan to find out what happened):

  • 创建文件或子文件夹
  • 删除文件或子文件夹
  • 移动文件或子文件夹
  • 删除自己
  • 自我移动

假设 inotify 具有与上面所说的一致的限制,那么仅当我有大量嵌套子文件夹时,这对我来说似乎可能是太多监视器.真正令人敬畏的方式看起来像是涉及 kqueue随后在 google 中作为更好的 fs.fileWatch 的讨论主题组.

Assuming the inotify has limits in line with what was said above then this alone to me seems like it may be too many monitors when I have a significant amount of nested subfolders. The real awesome way looks like it would involve kqueue which I subsequently found as a topic of discussion on a better fs.fileWatch in a google group.

在我看来,保留相关文件和文件夹信息的数据库是查询方面的适当操作过程,但保持该数据库与相关目录下文件系统的实际状态同步将是挑战.

It seems clear to me that keeping a database of the relevant file and folder information is the appropriate course of action on the query side of things, but keeping that database synchronized with the actual state of the file system under the directories of concern will be the challenge.

那么社区是怎么想的?是否有更好或众所周知的解决方案来解决我不知道的这个问题?最好只是观看所有感兴趣的目录以进行单个更改,例如修改时间然后扫描找出发生了什么?查看所有相关的 inotify 警报并适当修改数据库是否更好?这不是我这种农民能解决的问题吗?

So what does the community think? Is there a better or well known solution for attacking this problem that I am just unaware of? Is it best just to watch all directories of interest for a single change e.g. modified time and then scan to find out what happened? Is it better to watch all the relevant inotify alerts and modify the database appropriately? Is this not a problem which is solvable by a peasant like me?

推荐答案

查看 monit.我用它来监控开发环境中的文件更改,并在相关项目文件更改时重新启动我的节点进程.

Have a look at monit. I use it to monitor files for changes in my dev environment and restart my node processes when relevant project files change.

这篇关于NodeJS:如何查看服务器端的大量文件/文件夹以进行更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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