tftd
tftd

Reputation: 17042

Writing a daemon in perl

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:

  1. 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.

  2. What should I be aware of when writing such daemons ?

Upvotes: 1

Views: 1165

Answers (3)

DVK
DVK

Reputation: 129433

  1. 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.

  2. As far as writing Perl daemons, some resources:

Upvotes: 5

Paul Nathan
Paul Nathan

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

zoul
zoul

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

Related Questions