-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pulsar-broker] Dispatch batch messages according consumer permits #7266
Conversation
@rdhabalia Looks like the same purpose as #6719 |
@codelipenghui |
@rdhabalia Thanks, I now know this problem that you want to fix. |
/** | ||
* Get number of batch messages into the entry. | ||
* @return | ||
*/ | ||
int getNumberOfBatchMessages(); | ||
|
||
/** | ||
* Set number of batch messages into the entry. | ||
* @param numberOfBatchMessages | ||
*/ | ||
void setNumberOfBatchMessages(int numberOfBatchMessages); | ||
|
||
/** | ||
* Set data size of the entry. | ||
* @param totalSizeInBytes | ||
*/ | ||
void setTotalSizeInBytes(int totalSizeInBytes); | ||
|
||
/** | ||
* Set total number of chunked messages in entry. | ||
* @param totalChunkedMessages | ||
*/ | ||
void setTotalChunkedMessages(int totalChunkedMessages); | ||
|
||
/** | ||
* Get total data size of the entry. | ||
* @return | ||
*/ | ||
int getTotalSizeInBytes(); | ||
|
||
/** | ||
* Get total number of chuncked messages. | ||
* @return | ||
*/ | ||
int getTotalChunkedMessages(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we better not add message related concepts to the entry. Maybe we can add a context carrier in the entry. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @codelipenghui , could you please provide a little more detail on what you mean by a "context carrier"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @codelipenghui
it is unfortunate to add these methods here.
we are going to use them (and the underlying fields) only on the Dispatcher.
it would be better (for instance) to have some EntryWithMetatadata object in Dispatcher that wraps the Entry and adds these fields
I. think it should open a doc issue to update docs for this PR. @jennifer88huang , could you help open an doc issue for this PR? |
Thanks @rdhabalia. overall lgtm. Would you please help on @codelipenghui 's last comments? |
@Huanli-Meng Thanks for informing me on this. We can add a label "doc-required" in the |
@rdhabalia thanks for your work.
|
@rdhabalia thanks for your work.
|
I will rebase this soon. |
@rdhabalia could you please help add docs accordingly? Then I would like to help review, thanks. |
20fbcc9
to
3cb0334
Compare
3cb0334
to
739c32f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@merlimat do you want to take a look as well? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closing and reopening this PR to get the fix for a flaky test. |
…pache#7266) Right now, dispatching of batch messages is not predictable for a shared-subscription. Dispatcher doesn't consider number of batch messages in an entry which can cause higher number of message delivery than consumer receiver-queue. For example: If a topic has message-entries with 100 batched message in an entry. If consumer has receiver queue=40 and has available-permits=20. then broker dispatches 20 entries with total 2000 (20*100) messages in it. because of that consumer's will high number of messages than expected and we can see available-permits in negative. - Find out average number of batch messages in an entry - Dispatch messages considering total batch-messages in an entry It will avoid dispatching higher number of messages than consumer's available-permit and will fix -ve available-permits. (cherry picked from commit a6aed55)
…pache#7266) Right now, dispatching of batch messages is not predictable for a shared-subscription. Dispatcher doesn't consider number of batch messages in an entry which can cause higher number of message delivery than consumer receiver-queue. For example: If a topic has message-entries with 100 batched message in an entry. If consumer has receiver queue=40 and has available-permits=20. then broker dispatches 20 entries with total 2000 (20*100) messages in it. because of that consumer's will high number of messages than expected and we can see available-permits in negative. - Find out average number of batch messages in an entry - Dispatch messages considering total batch-messages in an entry It will avoid dispatching higher number of messages than consumer's available-permit and will fix -ve available-permits. (cherry picked from commit a6aed55)
…rmits (apache#7266)" This reverts commit 5d7ef69.
@rdhabalia Nice work! |
…pache#7266) Right now, dispatching of batch messages is not predictable for a shared-subscription. Dispatcher doesn't consider number of batch messages in an entry which can cause higher number of message delivery than consumer receiver-queue. For example: If a topic has message-entries with 100 batched message in an entry. If consumer has receiver queue=40 and has available-permits=20. then broker dispatches 20 entries with total 2000 (20*100) messages in it. because of that consumer's will high number of messages than expected and we can see available-permits in negative. - Find out average number of batch messages in an entry - Dispatch messages considering total batch-messages in an entry It will avoid dispatching higher number of messages than consumer's available-permit and will fix -ve available-permits. (cherry picked from commit a6aed55)
…pache#7266) Right now, dispatching of batch messages is not predictable for a shared-subscription. Dispatcher doesn't consider number of batch messages in an entry which can cause higher number of message delivery than consumer receiver-queue. For example: If a topic has message-entries with 100 batched message in an entry. If consumer has receiver queue=40 and has available-permits=20. then broker dispatches 20 entries with total 2000 (20*100) messages in it. because of that consumer's will high number of messages than expected and we can see available-permits in negative. - Find out average number of batch messages in an entry - Dispatch messages considering total batch-messages in an entry It will avoid dispatching higher number of messages than consumer's available-permit and will fix -ve available-permits. (cherry picked from commit a6aed55)
Fixes #10813 The issue is introduced by #7266, it only affects the master branch. ### Motivation 1. Add wrapperOffset to make sure get the correct batch size from the metadata 2. Fix the issue that using (batch count / avgBatchSizePerMsg) to calculate messages for the consumer it should be (messages / avgBatchSizePerMsg) ### Verifying this change * The test case is to simulate dispatch batches with different batch size to the consumer. * 1. The consumer has 1000 available permits * 2. The producer send batches with different batch size * * According the batch average size dispatching, the broker will dispatch all the batches to the consumer
Fixes apache#10813 The issue is introduced by apache#7266, it only affects the master branch. ### Motivation 1. Add wrapperOffset to make sure get the correct batch size from the metadata 2. Fix the issue that using (batch count / avgBatchSizePerMsg) to calculate messages for the consumer it should be (messages / avgBatchSizePerMsg) ### Verifying this change * The test case is to simulate dispatch batches with different batch size to the consumer. * 1. The consumer has 1000 available permits * 2. The producer send batches with different batch size * * According the batch average size dispatching, the broker will dispatch all the batches to the consumer (cherry picked from commit 4f23767)
…pache#7266) ### Motivation Right now, dispatching of batch messages is not predictable for a shared-subscription. Dispatcher doesn't consider number of batch messages in an entry which can cause higher number of message delivery than consumer receiver-queue. For example: If a topic has message-entries with 100 batched message in an entry. If consumer has receiver queue=40 and has available-permits=20. then broker dispatches 20 entries with total 2000 (20*100) messages in it. because of that consumer's will high number of messages than expected and we can see available-permits in negative. ### Modification - Find out average number of batch messages in an entry - Dispatch messages considering total batch-messages in an entry ### Result It will avoid dispatching higher number of messages than consumer's available-permit and will fix -ve available-permits.
Fixes apache#10813 The issue is introduced by apache#7266, it only affects the master branch. ### Motivation 1. Add wrapperOffset to make sure get the correct batch size from the metadata 2. Fix the issue that using (batch count / avgBatchSizePerMsg) to calculate messages for the consumer it should be (messages / avgBatchSizePerMsg) ### Verifying this change * The test case is to simulate dispatch batches with different batch size to the consumer. * 1. The consumer has 1000 available permits * 2. The producer send batches with different batch size * * According the batch average size dispatching, the broker will dispatch all the batches to the consumer
…pache#7266) ### Motivation Right now, dispatching of batch messages is not predictable for a shared-subscription. Dispatcher doesn't consider number of batch messages in an entry which can cause higher number of message delivery than consumer receiver-queue. For example: If a topic has message-entries with 100 batched message in an entry. If consumer has receiver queue=40 and has available-permits=20. then broker dispatches 20 entries with total 2000 (20*100) messages in it. because of that consumer's will high number of messages than expected and we can see available-permits in negative. ### Modification - Find out average number of batch messages in an entry - Dispatch messages considering total batch-messages in an entry ### Result It will avoid dispatching higher number of messages than consumer's available-permit and will fix -ve available-permits.
Fixes apache#10813 The issue is introduced by apache#7266, it only affects the master branch. ### Motivation 1. Add wrapperOffset to make sure get the correct batch size from the metadata 2. Fix the issue that using (batch count / avgBatchSizePerMsg) to calculate messages for the consumer it should be (messages / avgBatchSizePerMsg) ### Verifying this change * The test case is to simulate dispatch batches with different batch size to the consumer. * 1. The consumer has 1000 available permits * 2. The producer send batches with different batch size * * According the batch average size dispatching, the broker will dispatch all the batches to the consumer
… instead ### Motivation apache#7266 introduced the `EntryWrapper` to store the `Entry` object and the associated `MessageMetadata` if it exists. However, the `getEntry` field of `EntryWrapper` is never used. There is no need to allocate memory for `EntryWrapper`, even if it's allocated from the recycler pool. ### Modifications - Calculate the remaining messages without creating `EntryWrapper` object, just iterate over the parsed message metadata list. - Pass an optional `MessageMetadata` array to `filterEntriesForConsumer` and add the JavaDocs for these two parameters. After that, Remove unused `EntryWrapper` and `updateEntryWrapperWithMetadata`. This PR uses functional programming style to make code more simple and clear. ### Verifying this change - [ ] Make sure that the change passes the CI checks. This change is already covered by existing tests, such as `testBatchMessageDispatchingAccordingToPermits`. ### Documentation Check the box below or label this PR directly. Need to update docs? - [ ] `doc-required` (Your PR needs to update docs and you will update later) - [x] `doc-not-needed` (Please explain why) - [ ] `doc` (Your PR contains doc changes) - [ ] `doc-complete` (Docs have been already added)
… instead (#15967) ### Motivation #7266 introduced the `EntryWrapper` to store the `Entry` object and the associated `MessageMetadata` if it exists. However, the `getEntry` field of `EntryWrapper` is never used. There is no need to allocate memory for `EntryWrapper`, even if it's allocated from the recycler pool. ### Modifications - Calculate the remaining messages without creating `EntryWrapper` object, just iterate over the parsed message metadata list. - Pass an optional `MessageMetadata` array to `filterEntriesForConsumer` and add the JavaDocs for these two parameters. After that, Remove unused `EntryWrapper` and `updateEntryWrapperWithMetadata`. This PR uses functional programming style to make code more simple and clear.
… instead (apache#15967) apache#7266 introduced the `EntryWrapper` to store the `Entry` object and the associated `MessageMetadata` if it exists. However, the `getEntry` field of `EntryWrapper` is never used. There is no need to allocate memory for `EntryWrapper`, even if it's allocated from the recycler pool. - Calculate the remaining messages without creating `EntryWrapper` object, just iterate over the parsed message metadata list. - Pass an optional `MessageMetadata` array to `filterEntriesForConsumer` and add the JavaDocs for these two parameters. After that, Remove unused `EntryWrapper` and `updateEntryWrapperWithMetadata`. This PR uses functional programming style to make code more simple and clear. (cherry picked from commit c33b12d)
… instead (apache#15967) apache#7266 introduced the `EntryWrapper` to store the `Entry` object and the associated `MessageMetadata` if it exists. However, the `getEntry` field of `EntryWrapper` is never used. There is no need to allocate memory for `EntryWrapper`, even if it's allocated from the recycler pool. - Calculate the remaining messages without creating `EntryWrapper` object, just iterate over the parsed message metadata list. - Pass an optional `MessageMetadata` array to `filterEntriesForConsumer` and add the JavaDocs for these two parameters. After that, Remove unused `EntryWrapper` and `updateEntryWrapperWithMetadata`. This PR uses functional programming style to make code more simple and clear. (cherry picked from commit c33b12d)
Motivation
Right now, dispatching of batch messages is not predictable for a shared-subscription. Dispatcher doesn't consider number of batch messages in an entry which can cause higher number of message delivery than consumer receiver-queue.
For example:
If a topic has message-entries with 100 batched message in an entry.
If consumer has receiver queue=40 and has available-permits=20. then broker dispatches 20 entries with total 2000 (20*100) messages in it. because of that consumer's will high number of messages than expected and we can see available-permits in negative.
Modification
Result
It will avoid dispatching higher number of messages than consumer's available-permit and will fix -ve available-permits.