Skip to content
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

[improve][java-client]Shrink BatchMessageContainer maxBatchSize #17854

Merged
merged 4 commits into from
Oct 2, 2022

Conversation

AnonHxy
Copy link
Contributor

@AnonHxy AnonHxy commented Sep 27, 2022

Motivation

There will be memory waste when producer publishes messages with batch enable, which may cause some problems, e.g., issue #17662 and issue #14943

The PR #15033 try to fixed the memory waste problem but bringing a significant performance regression.

Here we introduce another way to solve the memory waste problem through shrinking the maxBatchSize of BatchMessageContainerImpl, without bringing performance regression, which will solve the two issues list above.

Following is the test result to approve it:

1. Solved memory waste

Reducing the memory waste will be very helpful for this issue: #17662

After applying this PR, following the steps of the issue to reproduce it, we can see that memory will not exceed the client memory limit:

image

2. Without bring performance regression

  • Here is the publish throughput(msg/s) result, And we can come to conclusion that shrink will not bring performance regression comparing with compositeBuffer
buffer shrink compositeBuffer
1 1,057,249.52 1,038,105.78 917,114.21
2 1,018,946.85 1,050,870.61 896,039.70
3 1,037,839.98 1,038,394.16 903,520.30
avg 1,038,012.11 1,042,456.85 905,558.07

buffer : means using allocator.buffer() to allocate batchedMessageMetadataAndPayload without shrink.
shrink : means applied this PR
compositeBuffer : means applied #15033, which using allocator.compositeBuffer() to allocate batchedMessageMetadataAndPayload

Modifications

  • Shrink AbstractBatchMessageContainer#maxBatchSize if meet the conditions.
  • Revert allocator.compositeBuffer() to allocator.buffer(Math.min(maxBatchSize, ClientCnx.getMaxMessageSize()))

Verifying this change

  • Make sure that the change passes the CI checks.
  • Add test org.apache.pulsar.client.impl.BatchMessageContainerImplTest#testUpdateMaxBatchSize

Documentation

  • doc-not-needed
    (Please explain why)

PR in forked repository: AnonHxy#5

@AnonHxy AnonHxy force-pushed the shrink_batch_buffer branch from bfa1149 to 875db28 Compare September 27, 2022 11:52
@AnonHxy AnonHxy changed the title [improve][java-client]Shrink BatchMessageContainer maxBatchSize [wip][improve][java-client]Shrink BatchMessageContainer maxBatchSize Sep 27, 2022
@AnonHxy AnonHxy force-pushed the shrink_batch_buffer branch from 875db28 to f079f3d Compare September 27, 2022 13:07
@AnonHxy AnonHxy changed the title [wip][improve][java-client]Shrink BatchMessageContainer maxBatchSize [improve][java-client]Shrink BatchMessageContainer maxBatchSize Sep 27, 2022
@AnonHxy AnonHxy self-assigned this Sep 27, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 27, 2022
@AnonHxy AnonHxy added this to the 2.12.0 milestone Sep 28, 2022
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this patch! Comments inline.

@AnonHxy
Copy link
Contributor Author

AnonHxy commented Sep 29, 2022

@tjiuming @Jason918 @merlimat @codelipenghui PTAL thanks

@AnonHxy AnonHxy force-pushed the shrink_batch_buffer branch from f54c34e to 391aeae Compare September 30, 2022 03:20
Copy link
Contributor

@Jason918 Jason918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@tisonkun
Copy link
Member

/pulsarbot run-failure-checks

@AnonHxy AnonHxy merged commit 9ff9703 into apache:master Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants