43.2. Tuning JMS
Optimization is possible in the following areas when using the JMS API:
- Disable message id. Use the
setDisableMessageID()
method on theMessageProducer
class to disable message ids if not needed. This decreases the size of the message and also avoids the overhead of creating a unique ID. - Disable message time stamp. Use the
setDisableMessageTimeStamp()
method on theMessageProducer
class to disable message timestamps not required. - Avoid
ObjectMessage
.ObjectMessage
is convenient but it comes at a cost. The body of aObjectMessage
uses Java serialization to serialize it to bytes. The Java serialized form of even small objects is verbose, resulting in increased server traffic, also Java serialization is slow in comparison to custom marshaling techniques. Only useObjectMessage
if one of the other message types are unsuitable (for example, if the type of payload is unknown until run-time). - Avoid
AUTO_ACKNOWLEDGE
.AUTO_ACKNOWLEDGE
mode requires an acknowledgment to be sent from the server for each message received on the client, this means more traffic on the network. If possible, useDUPS_OK_ACKNOWLEDGE
, or useCLIENT_ACKNOWLEDGE
or a transacted session and batch up many acknowledgments with one acknowledge/commit. - Avoid durable messages. By default JMS messages are durable. If really durable messages are not required, set the messages to be non-durable. Durable messages incur much more overhead in persisting them to storage.
- Batch many sends or acknowledgments in a single transaction. HornetQ will only require a network round trip on the commit, not on every send or acknowledgment.