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

maxBatchSize preallocated memory may be thousands of times larger than actual message length #14943

Open
keyboardbobo opened this issue Mar 30, 2022 · 6 comments

Comments

@keyboardbobo
Copy link

keyboardbobo commented Mar 30, 2022

Is your enhancement request related to a problem? Please describe.
Guys, during the stress test, we found that the client's memory is very large, and even Full gc appeared. After analyzing the dump file, we found that the memory space occupied is much larger than the actual message size, and the serialization of 1KB of messages takes up 1MB.

batchedMessageMetadataAndPayload = PulsarByteBufAllocator.DEFAULT
                        .buffer(Math.min(maxBatchSize, ClientCnx.getMaxMessageSize()));

maxBatchSize = Math.max(maxBatchSize, uncompressedSize);

Debugging found that the maxBatchSize that controls the pre-allocated ByteBufPair.b2 memory size is stateful. As the size of the largest batch or the largest single message grows, this may cause the pre-allocated ByteBufPair.b2 memory to grow larger and larger , which maybe thousands of times larger than the payload of MessageImpl.

Lowering the value of batchingMaxMessages may reduce the risk of problems, but a single message that may be too large can also cause problems

Describe the solution you'd like
It is best to loop through the messages to be packed to accurately calculate the memory size to be allocated

Describe alternatives you've considered
Let the user choose whether to precisely allocate or pre-allocate

Additional context

maxPendingMessages=2000
maxPendingMessagesAcrossPartitions=40000
blockIfQueueFull=false
sendTimeoutMs=5000
batchingMaxPublishDelayMicros=50
batchingMaxMessages=2000
batchingMaxBytes=5242880
batchingEnabled=true

A11E7121-0FC6-4A0F-AC88-FC33AF63F41C

@gaozhangmin
Copy link
Contributor

gaozhangmin commented Mar 31, 2022

I have a doubt, How to achieve precisely allocate? @keyboardbobo

@keyboardbobo
Copy link
Author

It is best to loop through the messages to be packed to accurately calculate the memory size to be allocated

Whether it is possible to loop through the messages to be packaged and add their sizes to accurately calculate the size of the memory to be allocated?

@tjiuming
Copy link
Contributor

tjiuming commented Apr 6, 2022

How about use CompositeByteBuf, allocate small memory and let it grow. @codelipenghui Could you please assign it to me?

@codelipenghui
Copy link
Contributor

@tjiuming Yes, I think CompositeByteBuf will work which provided a Bytebuf that can be dynamically expanded

@github-actions
Copy link

The issue had no activity for 30 days, mark with Stale label.

@github-actions
Copy link

The issue had no activity for 30 days, mark with Stale label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants