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.

Hints for a Custom Marshaller(KnownLength vs Drainable)

See original GitHub issue

Using 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:

  1. Support KnownLength by serializing the message to byte[] which would be helpful in reducing the number of ByteBuf allocations (in MessageFramer when draining the message to OutputStream) as length is known. But this approach loses the benefit of Drainable, where we would be copying the byte[] to OutputStream.

  2. Don’t support KnownLength and support only Drainable to avoid additional copy when draining to OutputStream. But this may lead to lot more ByteBuf allocations as message length is not known. (Due to usingBufferChainOutputStream in MessageFramer).

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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ejona86commented, Mar 27, 2018

It seems this is answered reasonably for now. @srujann, comment more if you need more help on this topic and we can reopen. Closing.

0reactions
ejona86commented, Mar 23, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom JSON Marshaller in Go and Common Pitfalls - Medium
Marshaler and Unmarshaler Interfaces. It is pretty straightforward in Go to implement custom marshallers for your custom types. You just need to ...
Read more >
CallOptions (grpc-all 1.50.2 API)
Returns the deadline or null if the deadline is not set. ... Key<T> key). Get the value for a custom option or its...
Read more >
Index (grpc-api 1.40.0 API) - javadoc.io
KnownLength. Returns the total number of bytes that can be read (or skipped over) from this object until all bytes have been read...
Read more >
Never take Marshaling for granted - WorksHub
Building a custom unmarshaller. The same way we overwrite the unmarshaller for Pairs we are going to write a custom marshaller for our...
Read more >
Reprinted Pieces, by Charles Dickens - Project Gutenberg
Whole pages of the 'Court Guide' are ready to be references for him. ... Over and above which change, I bethought myself that...
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