Chapter 13: Chapter 13. Tuning ActiveMQ for performance
This introduction outlines factors affecting ActiveMQ performance and describes two architectural choices that can improve it.
After this chapter you will be able to
- Nonpersistent Delivery Tradeoff. Explain when nonpersistent messaging can improve performance and what delivery requirement makes it an option.
- Performance and delivery tradeoffs. Distinguish when nonpersistent messaging and transactional batching can improve JMS messaging performance. Describe the stated reliability limitation of nonpersistent delivery in ActiveMQ.
- Message delivery mode trade-offs. Distinguish persistent and nonpersistent delivery and state how a producer selects nonpersistent delivery.
- Nonpersistent delivery performance. Explain why nonpersistent messages are significantly faster than persistent messages.
- Nonpersistent message reliability. Explain how ActiveMQ improves the reliability of nonpersistent messages and when that may be sufficient.
- Transaction Batching for Performance. Explain how transaction boundaries allow message operations to be batched to improve persistent-message performance.
- Embedded broker performance benefits. Explain how co-locating a service with an embedded broker affects availability and why the VM transport can improve performance.
- Message copy tuning tradeoff. Explain why ActiveMQ copies sent messages by default and when to disable that copy using the connection factory.
- OpenWire protocol role. Describe OpenWire’s role in transporting commands to the broker and give examples of those commands.
- OpenWire tuning approach. Explain how OpenWire performance parameters are supplied and why choosing their settings requires experimentation.
- TCP socket buffer sizing. Explain how socketBufferSize affects TCP transport buffering and why its performance should be tested.
- TCP no-delay behavior. Explain what enabling tcpNoDelay changes and why its performance effect should be tested.
- Producer Rate and Performance. Explain why the rate at which producers send messages to the broker matters to overall application performance.
- Asynchronous Send Performance. Explain how to enable asynchronous sends for persistent messages and why they can improve producer performance.
- Producer flow control purpose. Explain why producer flow control slows producers and how it protects broker resources.
- Asynchronous producer window. Describe how producerWindowSize enables flow control for asynchronous publishing and why it matters for shared connections.
- Disabling flow control trade-offs. Explain the effects of disabling producer flow control and the role of the system usage memory limit.
- Send failure tuning options. Distinguish the two options for preventing a producer send from blocking indefinitely when broker space is unavailable.
- Consumer Work and Acknowledgment. Explain why consumers play a significant role in ActiveMQ performance and typically have more work to do than producers.
- Broker Delivery and Session Queuing. Trace the typical path of messages from the ActiveMQ broker to the consumer’s session.
- Prefetch Delivery Control. Explain how the prefetch limit controls message delivery to a consumer, including what happens when it is zero.
- Prefetch Performance Tradeoffs. Explain how prefetch size affects consumer speed, queue distribution, and client memory considerations.
- Listener versus receive delivery. Explain why delivery through MessageListener.onMessage() is faster than calling MessageConsumer.receive() in ActiveMQ.
- Acknowledgment and prefetch accounting. Describe why the broker tracks acknowledgments and when acknowledgments occur with transactions and auto-acknowledgment.
- Batched acknowledgment tradeoff. Explain how DUPS_OK_ACKNOWLEDGE or optimizeAcknowledge can improve consumption speed and what duplicate-delivery risk accompanies that improvement.
- Asynchronous session dispatch overhead. Explain how disabling alwaysSessionAsync changes message dispatch and why it can improve consumption performance.
- Embedded Data Feed Architecture. Describe the example’s producer, embedded broker, and remote consumer, including the producer’s tuning choices.
- Broker Memory and Policy. Explain how the example configures broker and destination memory limits and disables producer flow control using a default policy.
- Consumer Delivery Configuration. Describe the example consumer’s straight-through delivery and acknowledgment settings.
What it builds on
- How are messages stored by ActiveMQ? (chapter 5) · Message storage by ActiveMQ
- Surviving network or broker failure with the failover protocol (chapter 12) · The failover protocol for surviving network or broker failure
- Connecting to ActiveMQ inside the virtual machine (VM connector) (chapter 4) · Connections to ActiveMQ inside the virtual machine
- Embedding ActiveMQ using Java (chapter 7) · Embedding ActiveMQ using Java
- Configuring transport connectors (chapter 4) · Configuring transport connectors
- Transmission Control Protocol (TCP) (chapter 4) · The TCP transport used for network connections to ActiveMQ.
- Understanding connector URIs (chapter 4) · Connector URIs used to connect to ActiveMQ.
- JMS clients (chapter 2) · The role of a JMS client as a message consumer.
Section by section
Introduction
This introduction outlines factors affecting ActiveMQ performance and describes two architectural choices that can improve it.
- Environmental Performance Factors: Describe the environmental factors that influence ActiveMQ performance.
Why it matters: Performance results depend on more than the broker's configuration. - Nonpersistent Delivery Tradeoff: Explain when nonpersistent messaging can improve performance and what delivery requirement makes it an option.
Why it matters: Delivery requirements shape whether a faster messaging choice is appropriate. - Embedded Broker Serialization: Explain why embedding a broker may help performance.
Why it matters: Broker placement can affect the work messages undergo.
Key terms: broker network topology, transport, quality of service, Java Virtual Machine, guaranteed delivery, nonpersistent messaging, embedded brokers, serialization
13.1 General techniques
This section introduces two performance approaches and their applicability to different messaging reliability needs.
- Performance and delivery tradeoffs: Distinguish when nonpersistent messaging and transactional batching can improve JMS messaging performance. Describe the stated reliability limitation of nonpersistent delivery in ActiveMQ.
Why it matters: Choosing a performance approach depends on whether your application can tolerate message loss and whether batching fits its needs.
Key terms: nonpersistent messaging, transactions, guaranteed messaging, reliable delivery
13.1.1 Persistent versus nonpersistent messages
This section compares persistent and nonpersistent message delivery, their performance trade-offs, and ActiveMQ’s additional reliability measures.
- Message delivery mode trade-offs: Distinguish persistent and nonpersistent delivery and state how a producer selects nonpersistent delivery.
Why it matters: The delivery mode determines the protection a message receives and whether nonpersistent delivery must be explicitly requested. - Nonpersistent delivery performance: Explain why nonpersistent messages are significantly faster than persistent messages.
Why it matters: Understanding both sources of the speed difference helps you evaluate the performance cost of persistence. - Nonpersistent message reliability: Explain how ActiveMQ improves the reliability of nonpersistent messages and when that may be sufficient.
Why it matters: These ActiveMQ measures can broaden the situations where the faster nonpersistent mode is appropriate.
Key terms: persistent delivery, nonpersistent delivery, message store, MessageProducer, asynchronously, receipt, failover transport, trackMessages, message auditing, guaranteed message delivery
13.1.2 Transactions
This section explains how transaction boundaries and embedded brokers can improve ActiveMQ performance.
- Transaction Batching for Performance: Explain how transaction boundaries allow message operations to be batched to improve persistent-message performance.
Why it matters: Batching can reduce synchronous communication when your application can use transactions. - Embedded Broker Performance Benefits: Describe why embedding a broker can reduce ActiveMQ communication overhead.
Why it matters: Keeping broker communication in the same JVM can avoid some messaging overhead.
Key terms: transaction boundary, Session.commit(), synchronous communication, persistent messages, embedded broker, serialization, network traffic, JVM
13.1.3 Embedding brokers
This section explains how embedding an ActiveMQ broker and tuning message copying can improve performance for co-located applications.
- Embedded broker performance benefits: Explain how co-locating a service with an embedded broker affects availability and why the VM transport can improve performance.
Why it matters: Embedding can couple service availability to the broker while avoiding network serialization overhead. - Embedded broker connection options: Describe how local and TCP clients can connect to the same embedded broker, including its default VM address.
Why it matters: An embedded broker can support local service communication and TCP clients at the same time. - Message copy tuning tradeoff: Explain why ActiveMQ copies sent messages by default and when to disable that copy using the connection factory.
Why it matters: Avoiding an unnecessary message copy can reduce overhead when the application will not reuse the sent message.
Key terms: embedded broker, VM transport, co-locate, transport connector, TCP transport, vm://<broker name>, QueueRequestor, copyMessageOnSend, ActiveMQConnectionFactory, message producer
13.1.4 Tuning the OpenWire protocol
This section introduces OpenWire’s role in broker communication and explains how to approach its performance tuning.
- OpenWire protocol role: Describe OpenWire’s role in transporting commands to the broker and give examples of those commands.
Why it matters: This distinguishes the wire format from the transport carrying it. - OpenWire tuning approach: Explain how OpenWire performance parameters are supplied and why choosing their settings requires experimentation.
Why it matters: Tuning is more effective when settings are tested in the environment where the application runs.
Key terms: OpenWire protocol, commands, transport, TCP, OpenWire wire format parameters, URI, tight encoding
13.1.5 Tuning the TCP transport
This section explains two TCP transport settings that can affect ActiveMQ performance and recommends testing their effects on the operating system.
- TCP socket buffer sizing: Explain how socketBufferSize affects TCP transport buffering and why its performance should be tested.
Why it matters: Buffer sizing can affect TCP performance, but the best choice needs testing on your operating system. - TCP no-delay behavior: Explain what enabling tcpNoDelay changes and why its performance effect should be tested.
Why it matters: Sending sooner may improve performance, but the result is not guaranteed across operating systems.
Key terms: TCP transport, socketBufferSize, tcpNoDelay, TCP socket
13.2 Optimizing message producers
This section introduces the importance of producer-to-broker message rates for overall application performance.
- Producer Rate and Performance: Explain why the rate at which producers send messages to the broker matters to overall application performance.
Why it matters: Producer send rates are an important part of assessing messaging application performance.
Key terms: producers, message broker, overall application performance
13.2.1 Asynchronous send
This section explains how asynchronous sends improve producer performance and relates delivery choices to reliability requirements.
- Asynchronous Send Performance: Explain how to enable asynchronous sends for persistent messages and why they can improve producer performance.
Why it matters: This setting lets a producer avoid waiting for disk storage between sends. - Delivery Reliability Choices: Distinguish the stated reliability of nonpersistent delivery from the recommendation for applications requiring guaranteed delivery.
Why it matters: The delivery choice should reflect the application’s reliability requirements.
Key terms: useAsyncSend, connection factory, MessageProducer, persistent messages, nonpersistent delivery, failover transport cache, persistent delivery, transactions, guaranteed delivery
13.2.2 Producer flow control
This section explains how producer flow control protects broker resources and how to configure its performance and blocking trade-offs.
- Producer flow control purpose: Explain why producer flow control slows producers and how it protects broker resources.
Why it matters: This explains why a producer may slow down even when it can generate messages quickly. - Asynchronous producer window: Describe how producerWindowSize enables flow control for asynchronous publishing and why it matters for shared connections.
Why it matters: A producer window can keep a slow broker from blocking every user of a shared connection. - Disabling flow control trade-offs: Explain the effects of disabling producer flow control and the role of the system usage memory limit.
Why it matters: This trade-off helps prevent one slow consumer from setting the pace for the whole application. - Send failure tuning options: Distinguish the two options for preventing a producer send from blocking indefinitely when broker space is unavailable.
Why it matters: These options let a producer handle a full broker rather than waiting indefinitely.
Key terms: producer flow control, usage limits, temporary store space, producerWindowSize, asynchronous publishing, send buffer, transport, destination policy, temporary storage, system usage memory limit
13.3 Optimizing message consumers
This section introduces consumers’ role in ActiveMQ performance and describes how messages reach and wait in consumer sessions.
- Consumer Work and Acknowledgment: Explain why consumers play a significant role in ActiveMQ performance and typically have more work to do than producers.
Why it matters: Consumer work can affect the performance of the whole application. - Broker Delivery and Session Queuing: Trace the typical path of messages from the ActiveMQ broker to the consumer’s session.
Why it matters: This path shows where messages can wait between the broker and the consumer.
Key terms: message consumers, message producers, acknowledge, consumer connections, transport, session, queued
13.3.1 Prefetch limit
This section explains how ActiveMQ prefetch limits control consumer delivery and how to choose and configure them.
- Prefetch Delivery Control: Explain how the prefetch limit controls message delivery to a consumer, including what happens when it is zero.
Why it matters: Prefetch determines how much work can be outstanding at a consumer and whether delivery is pushed or pulled. - Prefetch Performance Tradeoffs: Explain how prefetch size affects consumer speed, queue distribution, and client memory considerations.
Why it matters: Choosing a prefetch size involves balancing throughput against fairer work distribution and client memory use. - Prefetch Configuration Locations: Describe the two locations where the section says prefetch size can be configured.
Why it matters: These two configuration locations let you specify the limit for a connection or a destination. - Consumer Prefetch Defaults: State the default prefetch sizes for queue consumers, queue browsers, persistent topic consumers, and nonpersistent topic consumers.
Why it matters: The starting prefetch setting depends on the kind of consumer.
Key terms: push-based model, prefetch limit, in-flight messages, acknowledgement, prefetch size, queue, slow consumer, topics, ActiveMQConnectionFactory, destination property
13.3.2 Delivery and acknowledgment of messages
This section compares message delivery and acknowledgment approaches for consumer performance, including the throughput and duplicate-delivery tradeoff.
- Listener versus receive delivery: Explain why delivery through MessageListener.onMessage() is faster than calling MessageConsumer.receive() in ActiveMQ.
Why it matters: The delivery method can affect how quickly a consumer processes messages. - Acknowledgment and prefetch accounting: Describe why the broker tracks acknowledgments and when acknowledgments occur with transactions and auto-acknowledgment.
Why it matters: Acknowledgment timing affects both broker prefetch accounting and consumer work. - Batched acknowledgment tradeoff: Explain how DUPS_OK_ACKNOWLEDGE or optimizeAcknowledge can improve consumption speed and what duplicate-delivery risk accompanies that improvement.
Why it matters: Batching acknowledgments can boost throughput when an application can tolerate some duplicate risk.
Key terms: MessageListener, onMessage(), MessageConsumer, receive(), prefetch limits, message acknowledgment, Session.commit(), auto-acknowledgment, DUPS_OK_ACKNOWLEDGE, optimizeAcknowledge
13.3.3 Asynchronous dispatch
This section explains how disabling asynchronous session dispatch can reduce message-consumption overhead.
- Asynchronous session dispatch overhead: Explain how disabling alwaysSessionAsync changes message dispatch and why it can improve consumption performance.
Why it matters: This setting offers a way to reduce overhead in message consumption.
Key terms: asynchronous dispatch, alwaysSessionAsync, ActiveMQ ConnectionFactory, internal queue, transport, message consumer
13.4 Tuning in action
This section combines broker, producer, and consumer settings in a tuned real-time data-feed example.
- Embedded Data Feed Architecture: Describe the example’s producer, embedded broker, and remote consumer, including the producer’s tuning choices.
Why it matters: The example shows how deployment and producer settings work together to reduce publishing overhead. - Broker Memory and Policy: Explain how the example configures broker and destination memory limits and disables producer flow control using a default policy.
Why it matters: The default destination policy applies the example’s streaming-oriented settings consistently across the broker. - Consumer Delivery Configuration: Describe the example consumer’s straight-through delivery and acknowledgment settings.
Why it matters: These settings complete the example’s attempt to receive the data feed as quickly as possible.
Key terms: embedded broker, VM transport, nonpersistent messages, message copy, memory limit, PolicyEntry, default entry, flow control, destination, straight-through processing
13.5 Summary
Concepts explained in this chapter
- nonpersistent messageNonpersistent delivery mode is a JMS delivery mode that does not require the broker to persist messages to durable storage.
- embedded brokerAn embedded broker is a message broker hosted within an application rather than run as a separate service.
- prefetch limitA prefetch limit controls how many messages a broker dispatches to a consumer ahead of acknowledgment.
- persistent delivery modePersistent delivery mode is a JMS delivery mode that requires the provider to take steps to ensure a message is not lost in transit due to a failure.
- VM transportAn ActiveMQ connector for communicating with a broker embedded in the same application process.
- MessageListenerMessageListener.onMessage() is the JMS callback method invoked to deliver a message to an asynchronous consumer.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
