views:

39

answers:

1

Is it possible to limit the number of JMS receiver instances to a single instance? I.e. only process a single message from a queue at any one time?

The reason I ask is because I have a fairly intensive render type process to run for each message (potentially many thousands). I'd like to limit the execution of this code to a single instance at a time.

My application server is JBoss AS 6.0

Any help much appreciated

+2  A: 

You can configure the queue listener pool to have a single thread, so no more than one listener is handling requests, but this makes no sense to me.

The right answer is to tune the size of the thread pool to balance performance with memory requirements.

Many thousands? Per second, per minute, per hour? The rate at which they arrive, and the time each task takes, are both crucial. How much time, memory, CPU per request? Make sure you configure your queue to handle what could be a rather large backlog.

UPDATE: If ten messages arrive per second, and it takes 10 seconds for a single listener to process a message, then you'll need 101 listener threads to be able to keep up. (10 messages/second * 10 seconds means 100 messages arrive by the time the first listener finishes its 10 second task. The 101st listener will handle the 101st message, and subsequent listeners will finish in time to keep up.) If you need 1 MB of RAM per listener, you'll need 101 MB RAM just to process all the messages on one server. You'll need a similar estimate for CPU as well.

It might be wise to think about multiple queues on multiple servers and load balancing between them if one server isn't sufficient.

duffymo
Thanks - Just to give a rough idea, we're talking about dozens of requests per second, with a processing time of maybe between 10 and 30 seconds per message. Whilst I'd like to optimise the speed of processing as much as possible, I'm most concerned about the server resources becoming depleted if a new instance is created for every request, as was happening with my existing implementation which uses stateless session bean calls.
jumponadoughnut