带有 Clojure/JVM 的守护进程

发布于 2024-09-03 18:24:31 字数 348 浏览 5 评论 0原文

我希望在一台小服务器上运行一个小型(不要做太多)守护进程,监视添加到其中的新文件的目录(以及主目录中的任何目录),并调用另一个 Clojure 程序来处理那个新文件。

理想情况下,每个文件都将添加到队列(Clojure 中由 ref 表示的列表?),并且主进程将基于 FIFO 处理队列中的这些文件。

我的问题是:让 JVM 一直运行这个小程序是否会占用太多资源?您对如何做到这一点有什么建议吗?

非常感谢!

编辑:我应该问的另一个问题:我应该将其作为自己的实例运行(使用较少的内存)并让它在看到文件时启动一个新的 JVM,还是将其与处理该文件的 Clojure 代码放在同一个 JVM 上?

I'd like to have a small (not doing too damn much) daemon running on a little server, watching a directory for new files being added to it (and any directories in the main one), and calling another Clojure program to deal with that new file.

Ideally, each file would be added to a queue (a list represented by a ref in Clojure?) and the main process would take care of those files in the queue on a FIFO basis.

My question is: is having a JVM up running this little program all the time too much a resource hog? And do you have any suggestions as to how go about doing this?

Thank you very much!

EDIT: Another question I should ask: should I run this as its own instance (using less memory) and have it launch a new JVM when a file is seen, or have it on the same JVM the Clojure code that will process the file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给妤﹃绝世温柔 2024-09-10 18:24:31

只要它现在运行良好并且没有内存泄漏,就应该没问题。

从守护进程术语来看,我认为它位于 unix 克隆上,在这种情况下,最好从 init 脚本或 rc.local 脚本启动它。不幸的是,更具体地说,细节因操作系统而异。

使用 -Xmx=64m 或其他内容限制内存,以确保在关闭其余服务之前它会失败。稍微研究一下数字,找到可靠的最低尺寸。

此外,由于 clojures 以其处理并发的能力而闻名,因此仅运行一个 JVM,并在多个线程中运行所有功能是很有意义的。生成新进程的开销已经非常大,如果是需要 JIT 并预热其内存管理的 JVM,则开销会加倍。在资源受限的机器上可能会造成问题。在资源丰富的机器上,这是一种浪费。

我总是发现 JVM 并不是为了快速运行某些脚本(例如然后再次退出)而设计的。在我看来,它确实不是为该用例而设计的

As long as it is running fine now and it has no memory leaks it should be fine.

From the daemon terminology I gather it is on a unix clone, and in this case best is to start it from an init script, or from the rc.local script. Unfortunately details differ from OS to OS to be more specific.

Limit the memry using -Xmx=64m or something to make sure it fails before taking down the rest of the services. Play a bit with the number to find the lowest reliable size.

Also, since clojures claim to fame is its ability to deal with concurrency it make a lot of sense to only run one JVM with all functionality running on it in multiple threads. The overhead of spawning new processes is already very big and if it is a JVM which needs to JIT and warm up its memory management, doubly so. On a resource constrained machine could pose a problem. and on a resource rich machine this is a waste.

I always found that the JVM is not made to quickly run something script like and exit again. It is really not made for that use case in my opinion
.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文