eclipse-vertx / vertx-grpc

Development of the gRPC component for Eclipse Vert.x
Eclipse Public License 2.0
42 stars 23 forks source link

Avoid composite buffers for small messages #68

Open franz1981 opened 1 year ago

franz1981 commented 1 year ago

This change is optimizing the use case of Netty composite buffers in case a small payload/data is required.

The NIO Netty flow will end up copying the compontents from the CompositeBuffer in a single native direct buffer at https://github.com/netty/netty/blob/fbb0207d5ecce39f3d63450dfd59bad5510b8e8b/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java#L443.

For a composite buffer made of 2 components (the length and compression flag + data ones) it means iterating them (updating for each the offsets etc etc) in CompositeByteBuf::getBytes(int index, ByteBuf dst, int dstIndex, int length) (calling back to UnpooledHeapByteBuf::getBytes(int index, ByteBuf dst, int dstIndex, int length) with the direct dst for each component, updating each ones offset, checking accessibility etc etc).

In the case of a single merged buffer, we pay an additional allocation (and copy of data), but:

The point about reachability of buffers is a stealthy but important consideration:

franz1981 commented 1 year ago

@He-Pin I remember you have commented on the gRpc benchmark...we are still working on enabling our load generator to support gRpc, hence we have no "official" and supported benchmarks to verify this. This is mostly based on my knowledge of the Netty stack and the OpenJDK platform; do you have anything to test it and verify if it is worthy?