[improvement][client-java] Avoid too large memory preallocation for batch message.#15033
[improvement][client-java] Avoid too large memory preallocation for batch message.#15033AnonHxy merged 10 commits intoapache:masterfrom
Conversation
|
The pr had no activity for 30 days, mark with Stale label. |
|
@codelipenghui seems the PR is able to merge |
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageContainerImpl.java
Outdated
Show resolved
Hide resolved
|
The pr had no activity for 30 days, mark with Stale label. |
|
@codelipenghui Please help merge the PR |
Please fix the CI failure @tjiuming |
|
@tjiuming Please provide a correct documentation label for your PR. |
|
This patch broken |
|
Hi @merlimat , If we want to avoid any memory copies, I think we could set the valule of |
|
@AnonHxy Can we do a quick test to validate this? Focus on the case with large number of messages in one batch. |
Sure |
|
@AnonHxy If we are writing bytes into the composite buffer, it either needs to have space into its own last buffer or to allocate a buffer and copy data into it. |
|
@merlimat @AnonHxy @Jason918 |
Allocating many small buffers will have a significant large impact compared to allocating 1 single large buffer:
|
|
@merlimat which means for a Producer, only 1 thread could send message at the same time, I think even there is allocator synchronization, it wouldn't have a significant large impact.
For this part, I don't think it will make a big difference. Yes, read bytes from I think the only problem is when the batch is |
|
@AnonHxy Is there a significant throughput difference between these two? |
OK. @Jason918
|
|
And here is the attachment of Flame Graph for the first time test |


Fixes (#14943)
Motivation
Allocate small memory for batch message first, and let it grow(with no memory resizes and memory copies).
Does this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changesDocumentation
Check the box below or label this PR directly (if you have committer privilege).
Need to update docs?
doc-required(If you need help on updating docs, create a doc issue)
no-need-doc(Please explain why)
doc(If this PR contains doc changes)