Skip to content

Commit 7b821a0

Browse files
netty: increase message quantum
This is a minor change setting the size of data frames sent when interleaving RPCs. The size was ~1024bytes previously, which resulted in the `writev` syscalls sending many smaller chunks before hitting the low water mark. The end effect is larger calls to `writev`, as seen with strace. The effect of this is noticeable when sending a lot of data. When sending as many 1MB messages as possible it nearly doubles the rate. Before: ``` INFO: single throughput GRPC 50.0%ile Latency (in nanos): 280856575 90.0%ile Latency (in nanos): 349618175 95.0%ile Latency (in nanos): 380444671 99.0%ile Latency (in nanos): 455172095 99.9%ile Latency (in nanos): 537198591 100.0%ile Latency (in nanos): 566886399 QPS: 346 Count: 103984 ``` After: ``` gRPC 50.0%ile Latency (in nanos): 125948927 90.0%ile Latency (in nanos): 166322175 95.0%ile Latency (in nanos): 177276927 99.0%ile Latency (in nanos): 193840127 99.9%ile Latency (in nanos): 226841599 100.0%ile Latency (in nanos): 256110591 QPS: 774 Count: 232340 ```
1 parent 6760bfe commit 7b821a0

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

netty/src/main/java/io/grpc/netty/NettyClientHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import io.netty.handler.codec.http2.DefaultHttp2FrameReader;
6262
import io.netty.handler.codec.http2.DefaultHttp2FrameWriter;
6363
import io.netty.handler.codec.http2.DefaultHttp2LocalFlowController;
64+
import io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController;
6465
import io.netty.handler.codec.http2.Http2Connection;
6566
import io.netty.handler.codec.http2.Http2ConnectionAdapter;
6667
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
@@ -78,6 +79,7 @@
7879
import io.netty.handler.codec.http2.Http2Stream;
7980
import io.netty.handler.codec.http2.Http2StreamVisitor;
8081
import io.netty.handler.codec.http2.StreamBufferingEncoder;
82+
import io.netty.handler.codec.http2.WeightedFairQueueByteDistributor;
8183
import io.netty.handler.logging.LogLevel;
8284
import java.nio.channels.ClosedChannelException;
8385
import java.util.concurrent.Executor;
@@ -121,6 +123,11 @@ static NettyClientHandler newHandler(ClientTransportLifecycleManager lifecycleMa
121123
Http2FrameReader frameReader = new DefaultHttp2FrameReader(headersDecoder);
122124
Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
123125
Http2Connection connection = new DefaultHttp2Connection(false);
126+
WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
127+
dist.allocationQuantum(16 * 1024); // Make benchmarks fast again.
128+
DefaultHttp2RemoteFlowController controller =
129+
new DefaultHttp2RemoteFlowController(connection, dist);
130+
connection.remote().flowController(controller);
124131

125132
return newHandler(connection, frameReader, frameWriter, lifecycleManager, keepAliveManager,
126133
flowControlWindow, maxHeaderListSize, ticker, tooManyPingsRunnable);

netty/src/main/java/io/grpc/netty/NettyServerHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import io.netty.handler.codec.http2.DefaultHttp2FrameReader;
7070
import io.netty.handler.codec.http2.DefaultHttp2FrameWriter;
7171
import io.netty.handler.codec.http2.DefaultHttp2LocalFlowController;
72+
import io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController;
7273
import io.netty.handler.codec.http2.Http2Connection;
7374
import io.netty.handler.codec.http2.Http2ConnectionAdapter;
7475
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
@@ -87,6 +88,7 @@
8788
import io.netty.handler.codec.http2.Http2Settings;
8889
import io.netty.handler.codec.http2.Http2Stream;
8990
import io.netty.handler.codec.http2.Http2StreamVisitor;
91+
import io.netty.handler.codec.http2.WeightedFairQueueByteDistributor;
9092
import io.netty.handler.logging.LogLevel;
9193
import io.netty.util.AsciiString;
9294
import io.netty.util.ReferenceCountUtil;
@@ -180,6 +182,11 @@ static NettyServerHandler newHandler(
180182
Preconditions.checkArgument(maxMessageSize > 0, "maxMessageSize must be positive");
181183

182184
final Http2Connection connection = new DefaultHttp2Connection(true);
185+
WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
186+
dist.allocationQuantum(16 * 1024); // Make benchmarks fast again.
187+
DefaultHttp2RemoteFlowController controller =
188+
new DefaultHttp2RemoteFlowController(connection, dist);
189+
connection.remote().flowController(controller);
183190
final KeepAliveEnforcer keepAliveEnforcer = new KeepAliveEnforcer(
184191
permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, TimeUnit.NANOSECONDS);
185192

0 commit comments

Comments
 (0)