-
Notifications
You must be signed in to change notification settings - Fork 962
Avoid using directBuffer directly #2158
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
Conversation
*Motivation* We introduced a smart buffer allocator since 4.9.0. It falls back to allocate buffer on heap when running out direct memory so that the bookie can run in a degraded mode rather than crashes. However if we use `directBuffer` directly, it bypasses the fallback mechanism. So the bookie crashes when running out of direct memory. *Modifications* Use `buffer` instead of `directBuffer` and let the allocator decide what is the best to use.
eolivelli
left a comment
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
Will merge as soon as CI passes
|
2019-09-06T09:38:45.945 [INFO] Starting audit... |
|
@diegosalvi this may be your problem of today :-) |
|
@eolivelli Unfortunately I think no. I've got many OOM due to newDirectBuffer invocation by netty itself as: org.apache.bookkeeper.common.allocator.impl.ByteBufAllocatorImpl.newDirectBuffer(ByteBufAllocatorImpl.java:158) My guess in such cases newDirectBuffer "interface" method should route to buffer public buffer method and add a new private internalNewDirectBuffer to really instance buffers.. but I think is out of scope. Stacktrace |
|
@sijie please fix checkstyle issues |
|
@eolivelli done |
|
Let's wait for CI |
|
Some tests failed with an unrelated error: |
|
rebuild java8 |
|
run pr validation |
|
|
||
| for (int i = 0; i < segmentsCount; i++) { | ||
| cacheSegments.add(Unpooled.directBuffer(segmentSize, segmentSize)); | ||
| cacheSegments.add(Unpooled.buffer(segmentSize, segmentSize)); |
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.
This is not really coming from the allocator. Rather, the intention is to really get unpooled direct memory for the read cache.
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.
what is the side effect of being pooled?
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.
In this case that the memory is not returned to the pool (but rather the direct mem chunks will be just GCed when the handle object is GCed)
For this case, we allocate big chunks of mem (eg: 1GB each) and we keep using them indefinitely. Effectively this is a kind of "manual pooling" of the read and write cache memory.
There would be no advantage in pooling that memory again.
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.
but it doesn't hurt to use pooled, correct? from code maintenance perspective, isn't it clear to use allocator across the bookkeeper code base? If we need to use unpooled, we can use unpooled and document why do we need to use unpooled to make people know exact the reason behind the scene.
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.
but it doesn't hurt to use pooled, correct?
We'd have to at least release the buffers when the ReadCache/WriteCache are closed
If we need to use unpooled, we can use unpooled and document why do we need to use unpooled to make people know exact the reason behind the scene.
Sure, that would be better to be explicitely noted why it was that way
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.
Sure, I'm just saying that in this PR we need to add that release when switching from unpooled to pooled.
I didn't still get the point why there are benefits using unpooled buffers.
I would avoid the tracking of these buffers by the allocator. The overhead might be minimal, OTOH there's no advantage from the allocator either.
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 would avoid the tracking of these buffers by the allocator. The overhead might be minimal, OTOH there's no advantage from the allocator either.
the intention is to make sure all the memory allocation is consistent across the bookie server and leverage whatever changes we made in our allocator, unless there are a very strong reason to not do so.
since there is no advantages and also no disadvantages, why not just to make things consistent and easier to maintain?
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'm not saying not to do it. just saying to add the release on close().
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.
If you are okay with using allocator, I will fix the release part.
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.
actually those buffers are already released on close
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/WriteCache.java
Show resolved
Hide resolved
merlimat
left a comment
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.
👍
|
|
run pr validation |
|
@sijie tests are failing consistently: 2019-09-22 12:59:48,207 - ERROR - [DL-io-0:ByteBufAllocatorImpl@62] - Unable to allocate memory |
|
@sijie do you have time to finish this work in a way that we get it into 4.10? |
|
@eolivelli feel free to move 4.11. will cherry-pick it to 4.10.1 |
|
run pr validation |
eolivelli
left a comment
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.
This patch needs rebase and also we have tests failing
|
@sijie what's the status of this patch? |
|
run pr validation |
|
@Ghatage this patch needs a rebase/resolve conflicts, it is not ready for merge. I feel this patch is quite dangerous, it is not a good candidate for 4.11. btw the magic word to trigger a build is |
|
@sijie I am closing this PR. It needs a rebase and it does not run GitHub actions. |
Descriptions of the changes in this PR:
Motivation
We introduced a smart buffer allocator since 4.9.0. It falls back to allocate buffer
on heap when running out direct memory so that the bookie can run in a degraded mode
rather than crashes.
However if we use
directBufferdirectly, it bypasses the fallback mechanism. Sothe bookie crashes when running out of direct memory.
Modifications
Use
bufferinstead ofdirectBufferand let the allocator decide what is the bestto use.