You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by 炼龙 <19...@qq.com> on 2021/05/16 09:55:33 UTC

阶段性并发消费特性 The features of periodical concurrent consumption

CN


亲爱的大佬们,你们好!


请让我举一个例子,来说明MessageListenerOrderly对性能的浪费。


比如电商搞活动,前10笔订单可以额外获得一台笔记本电脑,前10-30笔订单可以额外获得一台平板电脑,前30-100笔订单可以额外获得一台手机,而在100笔之后订单则没有额外的奖励。


此种场景下,当您使用了MessageListenerOrderly,能够保证前100笔订单的顺序(单读写队列),也会保证100笔订单之后的顺序,而100笔订单之后的顺序其实是没必要保证的(没有意义),也就是说100笔之后的订单,应该使用MessageListenerConcurrently来并发消费。


更进一步来说,假设我们将1-10的区间称为阶段1,将10-30的区间称为阶段2,将30-100的区间称为阶段3,将100+的区间称为阶段4。由于每个阶段的奖励都相同,因此阶段内其实是可以并发消费的(比如阶段1的10条消息可以并发消费),我们只需要保证阶段之间顺序(阶段2必须在阶段1后面)即可。


综上,我在此提出了MessageListenerPeriodicConcurrently,它能保证阶段间的顺序性,同时在阶段内并发消费,大幅提升了性能。


EN


Dear masters, Hello!

Let me give an example to illustrate the waste of performance caused by `MessageListenerOrderly`.

For example, for e-commerce activities, the first 10 orders can get an extra laptop, the first 10-30 orders can get an extra tablet, the first 30-100 orders can get an extra mobile phone, and after 100 orders, there is no extra reward.

In this scenario, when you use `MessageListenerOrderly`, you can guarantee the order of the first 100 orders (single read-write queue) and the order after 100 orders. In fact, the order after 100 orders is unnecessary (meaningless), that is to say, the order after 100 orders should be consumed by `MessageListenerConcurrently`.

Furthermore, suppose we call the interval from 1 to 10 stage 1, the interval from 10 to 30 stage 2, the interval from 30 to 100 stage 3, and the interval from 100 + stage 4. Because the reward of each stage is the same, in fact, concurrent consumption can be made in stages (for example, 10 messages in stage 1 can be consumed concurrently). We only need to ensure the order between stages (stage 2 must be after stage 1).

To sum up, I propose `MessageListenerPeriodicConcurrently`, which can ensure the sequence between phases and consume concurrently within phases, greatly improving the performance.