Overview

Chapter 13. Tuning ActiveMQ for performance

ActiveMQ performance depends on the broader environment, including network design, transport choices, hardware, operating system, and the JVM, but the chapter emphasizes that there are also practical tuning steps that can help in almost any deployment. The most important theme is to reduce unnecessary work: avoid persistence when guaranteed delivery is not required, batch messages when transactions make sense, and consider embedding the broker with the application to reduce serialization and network overhead. The chapter frames tuning as a balance between speed, reliability, and the costs of moving data through the broker.

Several core configuration areas are explored. On the broker and transport side, the text explains how OpenWire and TCP settings can influence throughput, especially for small messages or slower networks, with options such as caching, buffer sizing, and TCP no-delay behavior. On the producer side, asynchronous sending can improve throughput even for persistent messages, while producer flow control protects broker resources but may slow applications unless tuned with limits or timeout-based failure behavior. On the consumer side, prefetch settings, dispatch strategy, and acknowledgment behavior have major impact: larger prefetch can increase speed, message listeners are faster than synchronous receive calls, and batched acknowledgments such as optimizeAcknowledgement can significantly improve consumption rate.

The chapter then pulls these ideas together in a real-time data feed example that uses an embedded broker, nonpersistent producer delivery, disabled message copying, disabled producer flow control, a high consumer prefetch limit, and optimized acknowledgments. This example illustrates the central lesson that the fastest ActiveMQ applications are usually those that minimize persistence, reduce coordination overhead, and keep producers and consumers from blocking one another unnecessarily. At the same time, the chapter repeatedly warns that every performance gain comes with tradeoffs such as possible duplicates, reduced durability, or greater memory use, so tuning should always reflect the needs of the application rather than chasing speed alone.

Confirmation of persistent message delivery in ActiveMQ
Embedding an ActiveMQ broker with a service
MessageProducer feedback with producer flow control enabled
What the broker does with producer flow control disabled
How messages are passed through an ActiveMQ connection to a MessageConsumer in multiple steps using multiple threads
Optimized message passing to a message consumer in an ActiveMQ connection with alwaysSessionAsync=false
The sample tuned data feed application

FAQ

What are the main factors that influence ActiveMQ performance?ActiveMQ performance depends on several environmental and architectural factors, including broker network topology, transport choice, network quality and speed, hardware, operating system, and the Java Virtual Machine. Tuning should take all of these into account.
What are the quickest ways to improve JMS messaging performance?The simplest performance gains usually come from using nonpersistent messaging when guaranteed delivery is not required, or batching messages inside transactions when persistent delivery is needed. Both reduce the overhead of synchronous broker communication.
Why is nonpersistent messaging faster than persistent messaging?Nonpersistent messages are faster because the producer can send asynchronously without waiting for broker confirmation, and the broker does not need to write the message to disk before dispatching it. Disk persistence adds significant latency compared with network transfer alone.
How does ActiveMQ improve the reliability of nonpersistent messages?ActiveMQ can cache asynchronous messages in the failover transport using the trackMessages property, so messages can be resent after a transport failure. It also uses message auditing on both the client and broker to reduce duplicate delivery.
How do transactions improve message performance?When messages are sent in a transaction, only Session.commit() requires synchronous communication with the broker. This lets you batch message production or consumption, reducing the number of acknowledgments and round trips.
Why would you use an embedded broker?An embedded broker reduces serialization and network overhead because messages can be passed within the same JVM. This is useful for tightly coupled services that need fast request/response handling or co-location with the broker.
What is the purpose of the copyMessageOnSend setting?ActiveMQ normally copies messages on send to protect the producer from later changes. If you know the sent message will never be reused, setting copyMessageOnSend(false) removes that copy overhead and can improve performance.
Which OpenWire and TCP settings can help with performance?Useful OpenWire settings include tcpNoDelayEnabled, cacheEnabled, cacheSize, and tightEncodingEnabled. For TCP transport, socketBufferSize and tcpNoDelay are common tuning options. Their benefit depends on the network, hardware, and workload.
What is producer flow control, and when should it be adjusted?Producer flow control slows producers when broker resources are low, preventing memory or temporary store exhaustion. It is useful for stability, but can reduce throughput. You can tune it with producerWindowSize, or change broker settings such as sendFailIfNoSpace and sendFailIfNoSpaceAfterTimeout to avoid indefinite blocking.
How can message consumers be optimized for higher throughput?Consumer throughput improves with a larger prefetch size, using MessageListener.onMessage() instead of receive(), enabling optimizeAcknowledge, and, in some cases, disabling alwaysSessionAsync for straight-through dispatch. These reduce queueing and acknowledgment overhead, but may increase duplicate-message risk.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • ActiveMQ in Action ActiveMQ in Action ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • ActiveMQ in Action ActiveMQ in Action ebook for free