Reputation: 17042
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 ?
Upvotes: 1
Views: 1165
Reputation: 129433
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.Upvotes: 5
Reputation: 40319
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
Upvotes: 2
Reputation: 104065
One thing to watch for are memory leaks. There’s a very nice thread about memory leaks in Perl already on SO.
Upvotes: 1