question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tjiumingcommented, Apr 6, 2022

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

0reactions
github-actions[bot]commented, Jun 19, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shared memory pre-allocation · Issue #1119 - GitHub
I am having a doubt regarding CUDA shared memory. Is it possible to allocate memory for max batch size and run inference for...
Read more >
How do I pre-allocate memory when using MATLAB?
Either the preallocated memory will either be too large, resulting in wasted memory; or the allotted memory will be too small for the...
Read more >
Red Hat Data Grid User Guide
Red Hat Data Grid is a distributed in-memory key/value data store with optional schema. It can be used both as an embedded Java...
Read more >
Create a list with initial capacity in Python - Stack Overflow
to preallocate a list (that is, to be able to address 'size' elements of the list instead of gradually forming the list by...
Read more >
Growing Objects and Loop Memory Pre-Allocation - R-bloggers
By Thiago Milagres Preallocating Memory This will be a short post about ... other value) with the total length and then run the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found