Chapter 4. Producer Performance
4.1. Async Sends
Overview
ActiveMQ supports sending messages to a broker in either synchronous or asynchronous mode. The selected mode has a large impact on the latency of the send call: synchronous mode increases latency and can lead to a reduction in the producer's throughput; asynchronous mode generally improves throughput, but it also affects reliability.
Red Hat JBoss A-MQ sends messages in asynchronous mode by default in several cases. It is only in those cases where the JMS specification requires the use of synchronous mode that the producer defaults to synchronous sending. In particular, JMS requires synchronous sends when persistent messages are being sent outside of a transaction.
If you are not using transactions and are sending persistent messages, each send is synchronous and blocks until the broker has sent an acknowledgement back to the producer to confirm that the message is safely persisted to disk. This acknowledgment guarantees that the message will not be lost, but it also has a large latency cost.
Many high performance applications are designed to tolerate a small amount of message loss in failure scenarios. If your application is designed in this fashion, you can enable the use of async sends to increase throughput, even when using persistent messages.
Configuring on a transport URI
To enable async sends at the granularity level of a single producer, set the
jms.useAsyncSend
option to true
on the transport URI that you use to connect to the broker. For example:
tcp://locahost:61616?jms.useAsyncSend=true
Configuring on a connection factory
To enable async sends at the granularity level of a connection factory, set the
useAsyncSend
property to true
directly on the ActiveMQConnectionFactory
instance. For example:
// Java ((ActiveMQConnectionFactory)connectionFactory).setUseAsyncSend(true);
Configuring on a connection
To enable async sends at the granularity level of a JMS connection, set the
useAsyncSend
property to true
directly on the ActiveMQConnection
instance. For example:
// Java ((ActiveMQConnection)connection).setUseAsyncSend(true);