yandrey321 commented on PR #1677:
URL: https://github.com/apache/ratis/pull/1677#issuecomment-6609971986
@amaliujia, I agree the root cause is in gRPC, and it's good that it's being
fixed there. I checked #13108, and on its
own it won't restore zero-copy. So I'd still keep a fix in Ratis.
**#13108 keeps the flag right, but the payload is still copied.**
- **What it changes:** it wraps the coalesced bytes as a heap buffer,
`ReadableBuffers.wrap(ByteBuffer.wrap(coalescedBytes))`.
So `byteBufferSupported()` stays true and `ZeroCopyMessageMarshaller`
takes its zero-copy path.
- **Why that isn't enough:** protobuf aliases `bytes` fields only when every
input buffer is direct. If any piece is a
heap buffer, `CodedInputStream.newInstance(Iterable<ByteBuffer>)` falls
back to a stream decoder, which copies every
`bytes` field.
I reproduced what #13108 produces with the current gRPC: a 300 KB message in
direct buffers with one 4-byte heap
`ByteBuffer` among them, as #13108 would create.
| marshaller | `byteBufferSupported()` | the 300 KB payload after parsing |
|---|---|---|
| master | true | all 307,200 bytes copied to the heap (`LiteralByteString`)
|
`TestGrpcZeroCopy` would pass again with #13108, since its counter counts
these messages as zero-copy, while the data
is still copied. So the regression would just become silent.
**Release status:**
- #13108 was merged to grpc-java master on Oct 13. It isn't in v1.85.1 or
v1.84.3, and I found no backport to a
release branch, so the earliest release with it is 1.86.0.
- After that, Ratis needs a ratis-thirdparty release with that gRPC, and
Ozone a Ratis release.
**Pinning ratis-thirdparty 1.1.0 (gRPC 1.82.1) has its own cost.** The
coalescing came from grpc-java#12924, "Coalesce
Contiguous Small Buffers for ReadableBuffer to prevent OOM". It was
backported to 1.82.4 (#12943) and 1.83.1 (#12944).
Going back to 1.82.1 would drop that OOM protection, and whatever else came
in 1.82.3–1.82.4.
cc: @adoroszlai @szetszwo
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]