Jumat, 27 Agustus 2010

Wishlist for a service framework and/or manager

I maintain code for a few daemons/services written in Perl (most of them serve requests by forking/preforking). Reading post on Ubic, I started to feel that I am reinventing a lot of wheels. Currently I am doing these by writing my own code, as much as which I hope can be offloaded to CPAN in the future:

  • Autorestart when process size is becoming too big. We need to do this gracefully, meaning wait until there is no more clients being serviced, unless process size really gets too big in which case we need to restart immediately. Checking period can be configured.

  • Autorestart if script or modules change on disk. Also needs to be done gracefully. This is usually being recommended to be used only on development environment, but I use this too in production, for ease of deployment. But we need to check first (e.g. via "perl -c" or "eval + require" whether the new code from disk is okay.

  • Avoid duplicate instance (currently always using Proc::PID::File, but I'm open to better mechanism).

  • Limit clients concurrency. Sometimes this is simple (a single limit for all clients) and sometimes not so much (different limits for different IP/IP blocks/authenticated users/groups/etc).

  • Reap dead child processes and maintain a count of child processes.

  • Handle timed out clients. This is rather cumbersome with blocking I/O.

  • Write init script. This is the part I dislike the most, since there are tons of different OS flavors out there, and with more recent efforts like upstart, launchd, systemd, sooner or later I will certainly have to write different init scripts. I wish there is something equivalent to PSGI/Plack for general services, which can plug my code to whatever service manager might be out there.

4 komentar:

  1. > Autorestart if script or modules change on disk.

    I create Linux::Inotify2::Recur http://github.com/mj41/perl-inotify recently .

  2. LSB has standardized init scripts now. Write for the standard and let unstandard distro's deal with it themselves.

  3. I would love to see either a single dist with all this functionality, or a family of dists for each piece.

    Also, I second what xeno said as to the LSB. I tend to extend things to fulfill Debian's policy standards as well, but I do my best to keep things RH & LSB compatible. Doing so may also allow your init script to work as expected under Solaris as well... IIRC, Solaris can play nice with the LSB (or vice-versa)

  4. @mj41: sounds useful, and I'm surprised Linux::Inotify2 is not recursive already (I usually use Dave Rolsky's File::ChangeNotify and it already watches directories recursively by default).