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

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

问题描述

我正在研究一个小型的NodeJS应用程序,它基本上是一个基于浏览器的桌面搜索,用于多用户查询的基于局域网的服务器。局域网用户都可以访问该服务器上的共享文件夹,传统上习惯于将文件夹内的文件分享给每个人,我希望保持这个过程相同。

我遇到的第一个解决方案是 fs.watchFile 在其他计算器问题中已经被触及。在第一个问题 user

在另一个问题关于fs.watchFile用户 tjameson 首先重申在Linux上inotify将被fs.fileWatch使用并推荐只需使用 node-inotify-plusplus node-walk ,但是再次声明这种方法不应该用于大量的文件。有了评论和回应,他建议只查看目录的修改时间,然后重新扫描相关目录以更改文件。

我的最大障碍似乎是,即使有tjameson的建议,监控文件夹的数量仍然有很大的限制(其中有很多不断增长的文件夹)。此外,它将不得不做递归,因为目录树是有点深,也可能会受到更改在较低的分支机构,所以我将不得不监视以下每个文件夹级别(或者监视文件夹的修改时间,然后扫描以查明发生了什么情况):


  • 创建文件或子文件夹

  • 删除文件或子文件夹
  • 移动文件或子文件夹

  • 自我删除
  • 移动自己



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

    在我看来,保持相关文件和文件夹信息的数据库是在查询方面的事情的适当的行动方面,但是将数据库与文件系统的实际状态保持同步在所关心的目录下将是挑战。

    那么社区如何看待?有没有一个更好的或众所周知的解决方案来攻击这个问题,我只是不知道?最好只是观看所有感兴趣的目录,例如一次更改。修改时间,然后扫描发现发生了什么?观察所有相关的inotify警报并适当地修改数据库是否更好?这不是像我这样的农民可以解决的问题吗?

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

    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.

    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.

    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.

    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):

    • creation of file or subfolder
    • deletion of file or subfolder
    • move of file or subfolder
    • deletion of self
    • move of self

    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.

    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?

    解决方案

    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天全站免登陆