Message load balancing policies

更新时间:
复制 MD 格式

Message queue load balancing policies differ for publishers and subscribers. For subscribers, the load balancing policy can affect message accumulation.

Publisher load balancing policy

Message queues use a round-robin policy for publishers. A producer sends messages to queues in a round-robin sequence, as shown in the following figure.

发布方消息负载均衡策略

The numbers on the arrows in the figure indicate the sending sequence. The publisher sends the first message to queue 0, the second to queue 1, and so on until the eighth message is sent to queue 7. The ninth message is then sent to queue 0, which starts the cycle again.

Subscriber load balancing policy

A message queue includes nodes such as brokers and Name Servers. Broker nodes report the routing information for topics to Name Server nodes.

Assume that a message queue has only one broker node. When a producer sends messages to a topic, the messages are load-balanced across eight default queues, which are logical concepts. The broker then evenly assigns these queues to a subscriber cluster where all subscribers share the same Group ID.

Therefore, the number of queues that each subscriber handles is determined by one of the following scenarios:

  • If there are more subscribers than queues, the excess subscribers will not handle any messages, as shown in the following figure.订阅方slb1

  • If the number of subscribers equals the number of queues, each subscriber handles messages from one queue, as shown in the following figure.订阅方slb2

  • If there are fewer subscribers than queues, subscribers handle messages from multiple queues, as shown in the following figure.订阅方slb3

If one subscriber slows down, messages in the queues assigned to it may not be processed promptly. A slowdown can be caused by factors such as hardware issues, system problems, remote RPC calls, or Java Garbage Collection (GC). Because message queue load balancing is managed at the queue level, slow processing for a single queue causes messages to accumulate for that entire queue.