9. Performance

Clients can often be made significantly faster by batching acknowledgements and setting the capacity of receivers to allow prefetch. The size of a sender's replay buffer can also affect performance.

9.1. Batching Acknowledgements

Many of the simple examples we have shown retrieve a message and immediately acknowledge it. Because each acknowledgement results in network traffic, you can dramatically increase performance by acknowledging messages in batches. For instance, an application can read a number of related messages, then acknowledge the entire batch, or an application can acknowledge after a certain number of messages have been received or a certain time period has elapsed. Messages are not removed from the broker until they are acknowledged, so guaranteed delivery is still available when batching acknowledgements.

9.2. Prefetch

By default, a receiver retrieves the next message from the server, one message at a time, which provides intuitive results when writing and debugging programs, but does not provide optimum performance. To create an input buffer, set the capacity of the receiver to the size of the desired input buffer; for many applications, a capacity of 100 performs well.

Example 2.16. Prefetch

C++

Receiver receiver = session.createReceiver(address);
receiver.setCapacity(100);
Message message = receiver.fetch();
	  

9.3. Sizing the Replay Buffer

In order to guarantee delivery, a sender automatically keeps messages in a replay buffer until the messaging broker acknowledges that they have been received. The replay buffer is held in memory, and is never paged to disk. For most applications, the default size of the replay buffer works well. A large replay buffer requires more memory, a small buffer can slow down the client because it can not send new messages if the replay buffer is full, and must wait for existing sends to be acknowledged.

Example 2.17. Sizing the Replay Buffer

C++

Sender sender = session.createSender(address);
sender.setCapacity(100);