Performance Tuning
Using ActiveMQ Classic > Performance Tuning
For a more complete overview see Performance.
There are trade-offs between performance and reliability. By default, ActiveMQ Classic strikes a balance between the two, so there are some things you can change to increase throughput.
Async Publishing
First some background:
When an ActiveMQ Classic message producer sends a non-persistent message, its dispatched asynchronously (fire and forget) - but for persistent messages, the publisher will block until it gets a notification that the message has been processed (saved to the store - queued to be dispatched to any active consumers etc) by the broker. messages are dispatched with delivery mode set to be persistent by default (which is required by the JMS spec). So if you are sending messages on a Topic, the publisher will block by default (even if there are no durable subscribers on the topic) until the broker has returned a notification.
So if you looking for good performance with topic messages, either set the delivery mode on the publisher to be non-persistent, or set the useAsyncSend
property on the ActiveMQ Classic ConnectionFactory to be true.
Pre-fetch Sizes for Consumers
ActiveMQ Classic will push as many messages to the consumer as fast as possible, where they will be queued for processing by an ActiveMQ Classic Session. The maximum number of messages that ActiveMQ Classic will push to a Consumer without the Consumer processing a message is set by the pre-fetch size. You can improve throughput by running ActiveMQ Classic with larger pre-fetch sizes. Pre-fetch sizes are determined by the ActiveMQPrefetchPolicy
bean, which is set on the ActiveMQ Classic ConnectionFactory
.
Default values:
Consumer Type | Default Value |
---|---|
queue | 1000 |
queue browser | 500 |
topic | 32767 |
durable topic | 1000 |
Optimized Acknowledge
When consuming messages in auto acknowledge mode (set when creating the consumers’ session), ActiveMQ Classic can acknowledge receipt of messages back to the broker in batches (to improve performance). The batch size is 65% of the prefetch limit for the Consumer. Also if message consumption is slow the batch will be sent every 300ms. You switch batch acknowledgment on by setting optimizeAcknowledge=true
on the ActiveMQ Classic ConnectionFactory
.
Straight through Session Consumption
By default, a Consumer’s session will dispatch messages to the consumer in a separate thread. If you are using Consumers with auto acknowledge, you can increase throughput by passing messages straight through the Session to the Consumer by setting alwaysSessionAsync=false
on the ActiveMQ Classic ConnectionFactory
.
File based Persistence
We have a file based persistence store that can be used to increase throughput for the persistent messages
Performance guides
If you’re not convinced by performance reports then please do try running performance tests yourself. You might wanna check out our overview of Performance or try using out the ActiveMQ Classic Performance Module Users Manual
Commercial providers may also be able to help diagnose performance issues, suggest changes, etc…