On Mon, 19 Dec 2005, Perrin Harkins wrote:
On Mon, 2005-12-19 at 13:43 -0600, Chase Venters wrote:
What was happening? The application had been taking
messages into the queue, promising the call generator to handle them. Thus
the queue kept growing, and growing, and growing...
That is what a queue is supposed to do when the demand exceeds the
capacity.
Indeed. And that's why using a queue is sometimes wrong.
A queue is just a method for handling bursty demand in applications
where it would be too expensive to always provide enough throughput to
handle all requests immediately. You have to build the system with
enough throughput to handle the common load level without backing up.
If you don't need to handle bursts that exceed capacity, or you don't
mind telling clients to go away when capacity is full, there's no good
reason to use a queue.
To be fair, it depends a bit on what your application is. In handling
calls, it's particularly nasty because a user expects a call to complete
rather quickly and if they're simply put on some line tens of thousands of
calls long, to be addressed several minutes from now, they'll just hang
up and complain.
An example application for a queue in a web application would be to set up
a request to send out an e-mail. (Simple apps simply invoke sendmail
directly, but the MTA can elect to queue the outgoing message as qmail
does [Sendmail might too, I've just never been a fan or a user :P])
The advantage here is interactive response - the user doesn't have to wait
for the SMTP client to look up the MX records, initiate a session, send
the message...
So if your server can handle 10 mails per second and you never *ask* it to
do more, you have no problems. But let's suppose you start asking it for
15 mails per second. This spike lasts five seconds. You've now built your
load up by 25 messages (more if you factor in that spending the time
accepting the extra five takes time away from sending the 10).
If you were to continue from that point forward with 10 mails per second,
you'd be permanently 25 messages behind, until your activity dips low
enough to catch back up. In this case, the queue has done its job.
I don't want to imply that queues are bad or wrong... just that you have
to be careful when you consider accepting work while busy a good property
to have. If you spend much of your time close to capacity, queues can bite
you in the ass. And if you do happen to spend much time over your capacity
limits, the problem will at best be nasty and at worst be a damn nightmare,
depending on what it is you're using the queues for.
- Perrin
Cheers,
Chase