Backlog and Smart Pipelining
AMPS queues are designed for high-volume applications that need minimal latency and overhead. One of the features that helps performance is the subscription backlog feature, which allows applications to receive multiple messages at a time. The subscription backlog sets the maximum number of unacknowledged messages that AMPS will provide to the subscription.
When the subscription backlog is larger than 1
, AMPS delivers additional messages to a subscriber before the subscriber has acknowledged the first message received. This technique allows subscribers to process messages as fast as possible, without ever having to wait for messages to be delivered. The technique of providing a consistent flow of messages to the application is called smart pipelining.
Subscription Backlog
The AMPS server determines the backlog for each subscription. An application can set the maximum backlog that it is willing to accept with the max_backlog
option. Depending on the configuration of the queue (or queues) specified in the subscription, AMPS may assign a smaller backlog to the subscription. If no max_backlog
option is specified, AMPS uses a max_backlog
of 1
for that subscription.
In general, applications that have a constant flow of messages perform better with a max_backlog
setting higher than 1
. The reason for this is that, with a backlog greater than 1
, the application can always have a message waiting when the previous message is processed. Setting the optimum max_backlog
is a matter of understanding the messaging pattern of your application and how quickly your application can process messages.
To request a max_backlog
for a subscription, you explicitly set the option on the subscribe command, as shown below:
Acknowledging Messages
For each message delivered on a subscription, AMPS counts the message against the subscription backlog until the message is explicitly acknowledged. In addition, when a queue specifies at-least-once
delivery, AMPS retains the message in the queue until the message expires or until the message has been explicitly acknowledged and removed from the queue. From the point of view of the AMPS server, this is implemented as a sow_delete
from the queue with the bookmarks of the messages to remove. The AMPS C++ client provides several ways to make it easier for applications to create and send the appropriate sow_delete
.
Automatic Acknowledgment
The AMPS client allows you to specify that messages should be automatically acknowledged. When this mode is on, AMPS acknowledges the message automatically in the following cases:
Asynchronous message processing interface - The message handler returns without throwing an exception.
Synchronous message processing interface - The application requests the next message from the
MessageStream
.
AMPS batches acknowledgments created with this method, as described in the following section.
To enable automatic acknowledgment, use the setAutoAck()
method.
Message Convenience Method
The AMPS C++ client provides a convenience method, ack()
, on delivered messages. When the application is finished with the message, the application simply calls ack()
on the message. (This, in turn, provides the topic and bookmark to the ack()
function of the client that received the message.)
For messages that originated from a queue with at-least-once
semantics, this adds the bookmark from the message to the batch of messages to acknowledge. For other messages, this method has no effect.
Last updated