-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Manually Manage Direct Write Buffer in Frozen Cache Writes #70399
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
Manually Manage Direct Write Buffer in Frozen Cache Writes #70399
Conversation
Manually managing the buffer has a number of upsides for us and no direct downsides as far as I can see. * We limit the number of syscalls for large writes by a factor of up to `8` (in pratice it's probably mostly `8` when writing larger amounts of data) * Since we limit the write thread count to 28 the amount of direct memory used is limited * We eliminate the copying from heap -> off-heap under the lock in the channel's positional write * We eliminate allocating `ByteBuffer` instances in a hot loop when writing large regions
Pinging @elastic/es-distributed (Team:Distributed) |
return fc.write(byteBuffer, start); | ||
byteBuffer.flip(); | ||
int written = fc.write(byteBuffer, start); | ||
byteBuffer.clear(); |
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.
Can we clear buffer if not everything was written? Or would we have to assert that buffer.remaining() is 0 here and that written == old(buffer.remaining())?
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 think just assert byteBuffer.hasRemaining() == false;
is sufficient. We do assert that the sum of all writes matches up in the callers anyway and we don't have to add another variable just for the assertion here. I pushed 34b179e for that.
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
…0399) Manually managing the buffer has a number of upsides for us and no direct downsides as far as I can see. * We limit the number of syscalls for large writes by a factor of up to `8` (in practice it's probably mostly `8` when writing larger amounts of data) * Since we limit the write thread count to 28 the amount of direct memory used is limited * We eliminate the copying from heap -> off-heap under the lock in the channel's positional write * We eliminate allocating `ByteBuffer` instances in a hot loop when writing large regions
…0399) Manually managing the buffer has a number of upsides for us and no direct downsides as far as I can see. * We limit the number of syscalls for large writes by a factor of up to `8` (in practice it's probably mostly `8` when writing larger amounts of data) * Since we limit the write thread count to 28 the amount of direct memory used is limited * We eliminate the copying from heap -> off-heap under the lock in the channel's positional write * We eliminate allocating `ByteBuffer` instances in a hot loop when writing large regions
…70558) Manually managing the buffer has a number of upsides for us and no direct downsides as far as I can see. * We limit the number of syscalls for large writes by a factor of up to `8` (in practice it's probably mostly `8` when writing larger amounts of data) * Since we limit the write thread count to 28 the amount of direct memory used is limited * We eliminate the copying from heap -> off-heap under the lock in the channel's positional write * We eliminate allocating `ByteBuffer` instances in a hot loop when writing large regions
…70559) Manually managing the buffer has a number of upsides for us and no direct downsides as far as I can see. * We limit the number of syscalls for large writes by a factor of up to `8` (in practice it's probably mostly `8` when writing larger amounts of data) * Since we limit the write thread count to 28 the amount of direct memory used is limited * We eliminate the copying from heap -> off-heap under the lock in the channel's positional write * We eliminate allocating `ByteBuffer` instances in a hot loop when writing large regions
Manually managing the buffer has a number of upsides for us and no direct downsides as far as I can see:
8
(in practice it's probably mostly8
when writing larger amounts of data)ByteBuffer
instances in a hot loop when writing large regions