Linux inotify API 的效率如何?
我了解 inotify 最初是为了促进某些类型的文件系统管理任务(例如索引、增量备份等)而开发的 。
话虽如此 inotify API 是否足够高效,可以用作简单但有效的进程间消息传递系统?
作为相对参考点...以这种方式使用时,它与诸如 ActiveMQ 上的 JMS 之类的东西相比如何?
I understand inotify was originally developed to facilitate certain types of filesystem management tasks like indexing, incremental backups, etc.
With that said. Is the inotify API efficient enough that it could be used as a simple but effective inter-process messaging system?
As a relative point of reference... how does it compare to something like, oh, JMS over ActiveMQ when used in this manner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您对 inotify 的具体想法,但这有点滥用它们的用途,并且存在更好的 IPC 设施。假设您传递合理大小的有界消息,消息队列在性能和易用性方面很难被击败。
我建议 POSIX MQ他建议使用 SysV 变体。它们有一个更干净的界面,队列是使用文件系统路径条目创建的,您不必弄乱 IPC 密钥;您可以从命令行 ls 或 rm 队列。它们可以与 select() 一起用作另一个要监视的文件描述符。当有新队列条目时,mq_notify() 可以发出信号或创建新线程。他们非常灵活。
I'm not sure exactly what you had in mind with inotify but that's a bit of an abuse of what they are for and better IPC facilities exist. Message queues are hard to beat on performance and ease of use assuming you are passing bounded messages of reasonable size.
I would suggest POSIX MQs over the SysV variant sehe suggests. They have an even cleaner interface, the queues are created with a file system path entry and you don't have to mess with IPC keys; you can ls or rm a queue from the command line. They can used with select() as one more file descriptor to monitor. mq_notify() can signal or create a new thread when there is a new queue entry. They are pretty darn flexible.
如果你想做简单的消息传递,只需使用
msgget
、msgsnd
和msgrcv
;man mq_overview
获取简介。这是自内核 2.6.6 和 Glibc 2.3.4 以来操作系统内置的。这将提高性能,并且界面(如果有的话)非常简单。
参考示例如下: http://www.cs.cf.ac .uk/Dave/C/node25.html
If you want to do simple messaging, just use
msgget
,msgsnd
andmsgrcv
;man mq_overview
to get an introduction. This is OS builtin since kernel 2.6.6 and Glibc 2.3.4.This is going to fly performance wise, and the interface, if anything, is ridiculously simple.
A reference example is here: http://www.cs.cf.ac.uk/Dave/C/node25.html