用 Perl 编写守护进程
我正在用 Perl 为时事通讯编写一个守护进程。
该守护进程将在服务器上 24/7 运行。它几乎始终与 postgresql 数据库保持活动连接。
我对 Perl 没有太多经验,所以如果你们中的一些人能够分享以下信息,我会很高兴:
如何限制 RAM。我不想离开公羊。正如我所说,这个程序将作为守护进程一直运行而不会被停止。
编写此类守护进程时应该注意什么?
I'm writing a daemon for a newsletter in Perl.
The daemon will be running 24/7 on the server. It'll have an active connection to postgresql database almost all the time.
I don't have that much experience with Perl so I would love if some of you can share information about the following:
How to limit the RAM. I don't want to get out of ram. As I said this program will be running all the time as a daemon without being stopped.
What should I be aware of when writing such daemons ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就 SQL 连接而言 - 确保不会泄漏内存。从查询中检索所需的最少量数据,并确保存储数据的数据结构立即超出范围,以便垃圾收集器可以回收它们
请注意,可能存在您无法控制的内存泄漏(例如在 Postgresql 连接代码中)。众所周知它会发生。解决这个问题的最佳解决方案(缺乏精确的内存分析和修复底层库中的泄漏)是让你的守护进程拉出一个 Phoenix - 停止做它正在做的事情,并
exec()
一个新的副本本身。就编写 Perl 守护进程而言,一些资源:
Proc::Daemon
- 将 Perl 程序作为守护进程运行。As far as SQL connection - make sure you don't leak memory. Retrieve the least amount of data you need from the query, and ensure that the data structures storing the data go out of scope immediately so garbage collector can reclaim them
Please note that there may be memory leaks you have no control over (e.g. in Postgresql connectivity code). It's been known to happen. The best solution for that problem (short of doing precise memory profiling and fixing the leaks in underlying libraries) is for your daemon to pull a Phoenix - stop doing what it's doing and
exec()
a new copy of itself.As far as writing Perl daemons, some resources:
Proc::Daemon
- Run Perl program(s) as a daemon process.关于#1:Perl 是垃圾收集的。
其有效含义是,您应该确保在使用完数据后清除所有对数据的引用,从而允许垃圾收集器运行。
http://perldoc.perl.org/perlobj.html#Two-Phased -垃圾收集
Regarding #1: Perl is garbage collected.
The effective meaning of that is you should ensure all references to data are cleaned up when you are done with them, thus allowing the garbage collector to run.
http://perldoc.perl.org/perlobj.html#Two-Phased-Garbage-Collection
需要注意的一件事是内存泄漏。 SO 上已经有一个关于 Perl 内存泄漏的非常好的线程。
One thing to watch for are memory leaks. There’s a very nice thread about memory leaks in Perl already on SO.