Repository navigation
RIP 27 Auto batching in producer
- Current State: Proposed
- Authors: guyinyou
- Shepherds: RongtongJin
- Mailing List discussion: dev@rocketmq.apache.org
- Pull Request:
- Released:
- Related Docs: Auto batching in producer
- Will we add a new module? No.
- Will we add new APIs? Yes.
- Will we add new feature? Yes.
- Are there any problems of our current project? Messages are sent in batches with very good throughput performance, but currently the business end needs to be packaged manually by itself, and the experience is not good enough.
---------------------äžæććČçșż----------------------
æ¶æŻæčéćéæçéćžžć„œçććéèĄšç°ïŒäœæŻçźćéèŠäžćĄæčèȘèĄæćšæć ïŒäœéȘäžć€ć„œă
- What can we benefit proposed changes?
To realize the automatic message packaging function, the business side only needs to simply call the sending interface of a single message to realize the throughput of batch sending.
---------------------äžæććČçșż----------------------
ćźç°äžäžȘæ¶æŻèȘćšæć çćèœïŒäžćĄæčćȘéèŠçźćè°çšćæĄæ¶æŻçćéæ„ćŁïŒćłćŻèŸŸć°æčéćéæ¶çććéă
- What problem is this proposal designed to solve?
Realize the auto batching function in the producer.
ćźç°producerçæ¶æŻèȘćšæć ćèœă
ProduceAccumulator
- Instructions for open
batchMaxBytesïŒæŻäžȘMessageAccumulationæć€§çŽŻç§Żć€§ć°ïŒè¶ èżèŻ„éćŒć°äŒæć ćé
batchMaxDelayMsïŒæŻæĄMessagećšæććșæéżçćŸ æ¶éŽïŒè¶ èżèŻ„éćŒć°äŒæć ćé
totalBatchMaxBytesïŒææMessageAccumulation环积性ć°äčćçéćŒïŒè¶ èżèŻ„éćŒćç»èŻ·æ±ć°çŽæ„ćé
Producers with the same MQClientId shares the same ProducerAccumulator instance
---------------------äžæććČçșż----------------------
çžć MQClientId ç Producers ć ±çšćäžäžȘ ProducerAccumulator
There are two MAP corresponding to two sending methods (syncSendBatchs and asyncSendBatchs). The key of Map is the smallest granularity of batch, the value is the staging area for messages.
There are two SERVICE for cooperating with two sending modes (GuardForSyncSendService and GuardForAsyncSendService), notify or send or cleanup regularly according to 'batchMaxDelayMs'.
---------------------äžæććČçșż----------------------
æŻäžäžȘ ProducerAccumulator äžæäž€äžȘ MAP ćŻčćș䞀ç§äžćçćéæšĄćŒïŒsyncSendBatchsăasyncSendBatchsïŒïŒMAP çéźäžșæčéćéèćæ¶çæć°çČćșŠïŒäŸćŠMessageQueueïŒïŒćŒäžșćŸ èćæ¶æŻççŒćČćșă
ćæ¶èżæäž€äžȘ SERVICE çšæ„ćè°äž€ç§äžćçćéæšĄćŒïŒGuardForSyncSendServiceăGuardForAsyncSendServiceïŒïŒä»„ batchMaxDelayMs äžșćšæïŒć€éçșżçšăćéæ¶æŻæè æž çćŻčè±Ąă
Map<String, MessageAccumulation> äžçKeyïŒćšæȘæćź MessageQueue çææćźæŻ TopicïŒéżć ćșç°ć€§éć°batchçæ ć”ïŒïŒćšæćźäșćééćçæ ć”äžææćźæŻ Topic+QueueăèżéäčèźžćșèŻ„æœè±ĄćșäžäžȘ类䌌äșâèćçČćșŠâçæŠćż”
èżéèżéèŠćŻč MessageAccumulation äžȘæ°ćäșéć¶ïŒéąć€ć ććŒé性çșŠäžș batchMaxBytes * MessageAccumulationäžȘæ°
Assign topic, waitStoreMsgOK, and createTime every time an instance of MessageAccumulation is created. When the user calls the send interface, the getOrCreateProduceAccumulator interface is called according to the message. If a new MessageAccumulation needs to be created, mqProducer will be registered.
---------------------äžæććČçșż----------------------
æŻæŹĄćć»ș MessageAccumulation ćźäŸæ¶äŒè”ćŒ topicăwaitStoreMsgOK ć createTime 俥æŻăćœçšæ·è°çš send æ„ćŁæ¶ïŒäŒè§Šć getOrCreateProduceAccumulator æ„ćŁïŒćŠææ€æ¶éèŠćć»ș MessageAccumulation ćźäŸïŒćć°æŹæŹĄćéæäœäžäžæäžç mqProducer æłšćèżć»ăïŒçžćœäșéæșæéèŻ„ instance äžç producerïŒæć€§ćć©çšć·ČçłèŻ·çè”æșïŒäŸćŠçșżçšæ± ïŒ
When the user sends a message in sync mode, the thread calling the send will check if it is ready to send or be suspended. GuardForSyncSendService will regularly notify when it is ready to send during the batchMaxDelayMs cycle and clean up long unused MessageAccumulation.
---------------------äžæććČçșż----------------------
ćœçšæ·ä»„ćæ„æšĄćŒćéæ¶æŻæ¶ïŒè°çšćéæ„ćŁççșżçšć°äŒæŁæ”æŻćŠæ»Ąè¶łćéæĄä»¶ïŒäžæ»Ąè¶łć°äŒæè”·ăGuardForSyncSendService äŒä»„ batchMaxDelayMs äžșćšæć€éæ»Ąè¶łćéæĄä»¶â ççșżçšïŒćč¶æž çäč æȘäœżçšçGuardForSyncSendServiceă
When the user sends a message in async mode, it will add message and sendCallBack to the two lists of MessageAccumulation respectively, and then return directly. GuardForAsyncSendService will regularly send by mqProducer if it is ready to send during the batchMaxDelayMs cycle and clean up long unused MessageAccumulation.
---------------------äžæććČçșż----------------------
ćœçšæ·ä»„ćŒæ„æšĄćŒćéæ¶æŻæ¶ïŒćŸ ćéçæ¶æŻććè°ćœæ°äŒæ·»ć ć° MessageAccumulation ç䞀äžȘ list äžïŒç¶ćçŽæ„èżćăGuardForAsyncSendService äŒä»„ batchMaxDelayMs äžșćšæćšæ»Ąè¶łćéæĄä»¶â çæ ć”äžçšæłšćèżć»ç mqProducer ćŒæ„ćéïŒćč¶æž é€äč æȘäœżçšç MessageAccumulationă
â æ»Ąè¶łćéæĄä»¶ïŒè·çŠ» MessageAccumulation ćć»șæ¶éŽ â„ batchMaxDelayMsïŒæè MessageAccumulation äžçŽŻç§Żæ¶æŻć€§ć° â„ batchMaxBytes
ć łäșæ¶æŻèćçæłšæäșéĄčïŒ
ćšæ§çæŹ Broker äžïŒæćĄç«ŻäŒć° MessageBatch è§Łć ćæć»ș玹ćŒïŒæ€æ¶äžäžȘ MessageBatch éç〿Ąæ°æźćŻä»„æćèȘäžćç TAGăKEYSăMsgIDă
äœæŻćšäœżçš BatchConsumerQueue çæ°çæŹ Broker äžïŒäžäžȘ MessageBatch ć°èą«ćœćäžæĄçŹç«çæ¶æŻïŒæäžćȘæćŻäžç TAGăKEYSăMsgIDăć æ€éèŠć łæłšæć»ș BCQ ć index æ¶çç»èă
TAGïŒć ·æçžć TAG çæ¶æŻæèœèćïŒæȘèźŸçœź TAG çäčéèŠććŒèćïŒïŒæ°æ§çæŹć ŒćźčïŒ
KEYSïŒäžä»„ KEYS äœäžșèć绎ćșŠéć¶ïŒäœæŻćšæć æ MessageBatch ćïŒéèŠèźŸçœź MessageBatch ç KEYS äžșæŻæĄæ¶æŻ KEYS çćč¶éăïŒæ°æ§çæŹć ŒćźčïŒ
MsgIDïŒææäžäžȘ MessageBatch çæææ¶æŻć ·æçžćç MsgIDăïŒæ§çæŹäžć ŒćźčïŒć æ€éèŠćŻčèżćçMsgIDćçčæźć€æćć€ç
-
Method signature changes
Nothing specific.
-
Method behavior changes
When calling the send interface, distinguish whether it needs to be sent in batches. What is needed will go to MessageAccumulation, and the others will be sent as usual
---------------------äžæććČçșż----------------------
è°çš send æ„ćŁæ¶ćșćæŻćŠéèŠæčéćéïŒéèŠçć°äŒèżć „ MessageAccumulation ïŒć ¶ä»çç §ćžžćé
-
CLI command changes
Nothing specific.
-
Log format or content changes Nothing specific.
- Are backward and forward compatibility taken into consideration?
Reuse the ability of MessageBatch, only as an enhancement.
---------------------äžæććČçșż----------------------
ć€çšäș MessageBatch çèœćïŒćȘäœäžșèœććąćŒș
-
Are there deprecated APIs? Nothing specific.
-
How do we do migration? Upgrade on the client side.
We will implement the proposed changes by 3 phases.
Implement autobatch on the client-side
ćšćźąæ·ç«ŻäŸ§ćźç° autobatch
æ€é¶æź”çćźç°ćŻčçšæ·ćźć šć±èœïŒæ æç„ăç±äș MessageBatch ćéæ¶ïŒèżćç sendResult äžäŒć°æŻäžæĄæ¶æŻç msgId çšéć·æŒæ„è”·æ„ïŒććČććłćŻćŸć°æŻäžæĄæ¶æŻćèȘç msgIdă
Enhance the ability of MessageBatch to support multiple partitions ćąćŒș MessageBatch çèœćïŒäœżć ¶æŻæäžćććșçæ¶æŻäžè”·æć
æ€é¶æź”çćźç°æŻèŸéçšäșæźéäžćĄæ¶æŻçćéïŒèœć€§ć€§æé«ććéïŒæ€æ¶ç msgId ć Phase1 çæ ć”äžèŽă
Increase BatchConsumerQueue so that messages sent in the same batch share one msgId ćąć BatchConsumerQueue ïŒäœżćäžæčćéçæ¶æŻć ±çšäžäžȘ msgId
æ€é¶æź”çćźç°æŻèŸéçšäș streaming ćșæŻïŒéćŻčäșçčćźććșçæ¶æŻćéïŒæ€æ¶ćäžæčćéæ¶æŻæ„æćäžäžȘ msgId
Manual batch sending by users.
çšæ·æćšæčéćéæ¶æŻ
Pros: higher throughput.
Cons: It is not convenient to use, users need to understand the details.
äŒçčïŒé«ćć
çŒșçčïŒäœżçšäžć€ćć„œïŒçšæ·éèŠäșè§Łć ·äœç»èïŒæŻćŠäžćŻæć éèŻæ¶æŻăćźæ¶æ¶æŻäžćż 饻ćtopicćwaitStoreMsgOkïŒ
Users are still allowed to manually send messages in batches, and when the send interface is called, the incoming MessageBatch will be sent directly.
çšæ·ç°ćšäŸç¶ćŻä»„æćšćéæčéæ¶æŻïŒćœè°çš send æ„ćŁć „ćäžș MessageBatch æ¶ć°çŽæ„ćéïŒäžćæŹæŹĄćèœćœ±ć
Copyright © 2016~2022 The Apache Software Foundation.
- Home
- RocketMQ Improvement Proposal
- User Guide
- Community





