-
Notifications
You must be signed in to change notification settings - Fork 576
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
Use ByteBuffers for message bodies #421
Comments
This is something that can be done for 6.0. |
@michaelklishin Thanks, that would be great. I believe it could be integrated in 5.x as well, as this should not break the current API. Thanks, greatly appreciated! |
I don't see how this would not affect several interfaces. So yes, likely it will. At least I don't see any reason not to convert to byte buffers as much as we can with a thin compatibility layer. @acogoluegnes WDYT? |
This should affect at least the Regarding the feature itself, it's possible to fit it into the current code base, it wouldn't be easy though: it should go into blocking and non-blocking IO modes, the byte buffer body would still need to be broken into several frames if it exceeds the max frame size, the NIO mode would need to juggle between the byte buffer it owns and byte buffer(s) from message body frames. Nothing blocking here, this is just implementations details, but it's not a trivial change. Some random thoughts (benefits/limitations of the feature):
I still need to be convinced to make the client code base more complex for a feature that could benefit only a very limited number of use cases. |
FYI, I left out my initial specific PostgreSQL example (which can still be looked up in the edit history) as I expected this would be distracting from the generic intent in the change request here. In that example, the buffer was indeed on the heap, but I believe that is a shortcoming from the implementation. In theory, PostgreSQL WAL events could be backed by a pure NIO channel from the network. I believe the reason for returning a I can surely see that this complicates the implementation. While the benefits are non-existing in certain cases (such as TLS), I believe it could (?) be a performance boost in other use cases where streams from one system to RabbitMQ are implemented. That said, as suggested in my addendum, certain buffer copies in client code can be avoided by extending the API to allow the user to define the Thanks! |
It's actually hard to find any benchmarks comparing heap-based byte buffers to direct byte buffers. We may need to come up with our own. Under the appropriate conditions, we could observe a performance boost (no copy) and less garbage collection activity, at least in theory. Not sure those would matter much compared network latency we'll always have. What you suggest in the addendum could be interesting in the PostgreSQL example, that would avoid the need to copy the array (but would make the byte buffer unusable until the write happens, see the new item in my comment above). This should be doable by introducing e.g. an public class ArrayFragment {
byte [] array;
int start;
int length;
...
} We could add new |
That would be great. You could make the Wrt. pure Thanks again! |
@pbillen I created a follow-up issue for the fragment array part: #422. For the |
@acogoluegnes Thanks! I'm very interested in the outcome of that benchmark project. |
Hi all,
I would like to propose to use
ByteBuffer
for message bodies. Now, the API accepts a plainbyte[]
, which forces intermediate copies of buffers if we are already working withByteBuffer
or similar representations of a buffer.Internally, the client implementation can use
array()
andarrayOffset()
to get the data to be sent over the wire ifhasArray()
returnstrue
; or copy the contents withget()
in the other case. In pure NIO mode, we could simply write theByteBuffer
to thejava.nio.Channel
without any intermediate overhead.What do you think?
Thank you!
addendum
FWIW, although I believe native support for
ByteBuffer
is the preferred solution, we could also avoid the copy if the API would accept an offset in the provided array (+ optionally the length) as an alternative proposal:The text was updated successfully, but these errors were encountered: