Here's a fairly simple technique to do what you want with only minor modifications to your mod_perl code: create a mod_perl cleanup handler that will check for any unsent messages in the database and send them. Make it loop until there are none left. This will mean that whenever messages come in, all of the processes that took the messages will stick around to send messages until the queue is cleaned out. The only danger of this approach is that you could end up tying up all of your processes sending messages and leave none to receive. To get around this, you could keep track of how many processes are in "send mode" at any given time, and have new processes skip the sending step if too many are already doing it. That may be unnecessary though.
The advantage of using apache (via mod_perl) as your daemon is that it's fast, stable, secure, handles SSL, has flexible logging, speaks HTTP, etc. Don't switch to something else without a really good reason.
If you need really great performance (it doesn't sound like you do), you would probably want to use some kind of single process non-blocking I/O approach, since most of the work is just waiting for I/O to complete. You could look at POE, although I'm not sure how well it performs under load.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.