Search code examples
jmsmessagingspring-jms

Optimal value of concurrency for jms container


<jms:listener-container container-type="default"
    connection-factory="testConnectionFactory"
    acknowledge="auto"
    concurrency="10">
    <jms:listener destination="test_queue" ref="testRequestHandler" method="getMessage" />
</jms:listener-container>

So, i have jms connection factory defined with concurrency set to 10 and my consumer can consume 10 messages concurrently at a time. Now, the problem is producer is queuing messages faster than consumer can consume, as a result half of my messages are getting expired in the queue.

  1. I can increase message TTL so that they remain longer in queue without expiring.
  2. Increase concurrency value for concurrent consumers.

The problem I'm facing is:

  1. I don't know how increasing concurrency value will affect the system?
  2. To what value i can increase its value? Is the concept is similar to no.of threads in thread pool?

Solution

  • I think the only way you're going to reach an optimal value is by:

    • Establishing clear performance goals (e.g. in terms of message throughput). Without clear goals performance tuning can turn into an endless exercise with diminishing relative improvements.
    • Developing a benchmark which mimics your real-world data-set and application environment.
    • Carefully running your benchmark with different configuration settings and recording the results. In this step I strongly recommend profiling your application in order to identify bottlenecks. The bottleneck will clarify where you should focus your tuning efforts.

    Nobody on the Internet is going to be able to just give you an optimal value. There are too many variables at work.

    Lastly, one option you didn't list was imposing flow-control on your producers to limit the amount of messages they can send so that the consumers keep up and you don't get a lot of expired messages. Most modern message brokers provide flow-control to push back on producers so they don't overwhelm them.