8.2. Queue Sizing
8.2.1. Controlling Queue Size
Controlling the size of queues is an important part of performance management in a messaging system.
When queues are created, you can specify a maximum queue size (
qpid.max_size
) and maximum message count (qpid.max_count
) for the queue.
qpid.max_size
is specified in bytes. qpid.max_count
is specified as the number of messages.
The following
qpid-config
creates a queue with a maximum size in memory of 200MB, and a maximum number of 5000 messages:
qpid-config add queue my-queue --max-queue-size=204800000 --max-queue-count 5000
In an application, the
qpid.max_count
and qpid.max_size
directives go inside the arguments
of the x-declare
of the node
. For example, the following address will create the queue as the qpid-config
command above:
- Python
tx = ssn.sender("my-queue; {create: always, node: {x-declare: {'auto-delete': True, arguments:{'qpid.max_count': 5000, 'qpid.max_size': 204800000}}}}")
Note that the
qpid.max_count
attribute will only be applied if the queue does not exist when this code is executed.
Behavior when limits are reached:
qpid.policy_type
The behavior when a queue reaches these limits is configurable. By default, on non-durable
queues the behavior is reject
: further attempts to send to the queue result in a TargetCapacityExceeded
exception being thrown at the sender.
The configurable behavior is set using the
qpid.policy_type
option. The possible values are:
- reject
- Message publishers throw an exception
TargetCapacityExceeded
. This is the default behavior for non-durable
queues. - ring
- The oldest messages are removed to make room for newer messages.
The following example
qpid-config
command sets the limit policy to ring
:
qpid-config add queue my-queue --max-queue-size=204800 --max-queue-count 5000 --limit-policy ring
The same thing is achieved in an application like so:
- Python
tx = ssn.sender("my-queue; {create: always, node: {x-declare: {'auto-delete': True, arguments:{'qpid.max_count': 5000, 'qpid.max_size': 204800, 'qpid.policy_type': 'ring'}}}}")
See Also: