Hints for a Custom Marshaller(KnownLength vs Drainable)
See original GitHub issueUsing gRPC version 1.7.0 with Netty Epoll transport.
I am using a custom marshaller for non-proto messages. For InputStream
provided by Marshaller.stream(message)
, currently I don’t have a way to provide length of the message without serializing it. So, I have these two options:
-
Support
KnownLength
by serializing the message tobyte[]
which would be helpful in reducing the number ofByteBuf
allocations (inMessageFramer
when draining the message toOutputStream
) as length is known. But this approach loses the benefit ofDrainable
, where we would be copying thebyte[]
toOutputStream
. -
Don’t support
KnownLength
and support onlyDrainable
to avoid additional copy when draining toOutputStream
. But this may lead to lot moreByteBuf
allocations as message length is not known. (Due to usingBufferChainOutputStream
inMessageFramer
).
Could you share your thoughts on which approach provides lower latency? (Especially if we have large messages of 10 MB or so.)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
It seems this is answered reasonably for now. @srujann, comment more if you need more help on this topic and we can reopen. Closing.
@srujann, since you can’t easy obtain the length, I’d suggest not implementing KnownLength. I’d suggest implementing Drainable if it is the more “natural” interface for your serialization logic, and if it avoids allocating temporary byte[]s. Basically, do what’s natural/cheap and let gRPC handle the rest.