Throttling can be triggered for a single Message Queue for RabbitMQ instance based on the peak transactions per second (TPS) of the instance. This topic describes the throttling rules for a Message Queue for RabbitMQ instance, the operations performed by the consumer and producer after throttling is triggered, and the best practices that you can use for throttling.

Operations performed by the consumer and producer after throttling is triggered

If the peak TPS of a Message Queue for RabbitMQ instance exceeds the TPS threshold value that is specified when the Message Queue for RabbitMQ instance is purchased, throttling is triggered for the instance.

The following operations are performed after throttling is triggered:
  • The Message Queue for RabbitMQ broker returns an error code and an error message.
  • The Message Queue for RabbitMQ broker closes the channel of the current request. You can detect exceptions in code and reopen the channel.

The following section describes the error code and error message:

  • Error code: reply-code=530
  • Error message: reply-text=denied for too many requests
The following sample code provides an example of an error stack of the client in Java:
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>
(reply-code=530, reply-text=denied for too many requests, ReqId:5FB4C999314635F952FCBFF6, ErrorHelp[dstQueue=XXX_test_queue,
srcExchange=Producer.ExchangeName,bindingKey=XXX_test_bk, http://mrw.so/6rNqO8], class-id=50, method-id=20)
    at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:516)
    at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:346)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:182)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:114)
    at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:672)
    at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:48)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:599)
    at java.lang.Thread.run(Thread.java:748)

Query the peak TPS of an instance

You can query the actual peak TPS of an instance to understand the traffic fluctuation and peak traffic of your service and determine whether the current instance specification meets your business requirements.

Message Queue for RabbitMQ provides the following methods for you to query the peak TPS of an instance:

  • View the peak TPS of an instance on the Instance Details page (recommended)

    You can view the peak TPS of an instance on the Peak TPS Query tab of the Instance Details page in the Message Queue for RabbitMQ console. For more information, see View instance details.

  • Query TPS charts based on message logs

    You can also configure message logs to query the TPS charts of an instance based on the message logs of the Message Queue for RabbitMQ instance. For more information, see Query TPS charts.

Rules based on which the TPS of an instance is calculated

If you call one of the following operations once, one TPS is counted.

  • ConnectionOpen
  • ChannelOpen
  • QueueDeclare
  • QueueDelete
  • ExchangeDeclare
  • ExchangeDelete
  • QueueBind
  • QueueUnbind
  • ExchangeBind
  • ExchangeUnBind
  • SendMessage
  • BasicConsume
  • BasicGet
  • BasicAck
  • BasicReject
  • BasicNack
  • BasicRecover
Note

Delayed messages are messages of advanced features of Message Queue for RabbitMQ. The number of API calls for delayed messages is counted as five times the number of API calls for normal messages.

For example, if delayed messages are published 10 times per second, the TPS is calculated based on the following formula: 10 times per second × 5 = 50 times per second.