Search code examples
perlpostgresqldaemon

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 ?


Solution

    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: