Skip to content

Commit 6da809d

Browse files
authored
Increase maxHeaderListSize for HpackDecoderBenchmark to be able to be… (netty#9321)
Motivation: The previous used maxHeaderListSize was too low which resulted in exceptions during the benchmark run: ``` io.netty.handler.codec.http2.Http2Exception: Header size exceeded max allowed size (8192) at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:103) at io.netty.handler.codec.http2.Http2Exception.headerListSizeError(Http2Exception.java:188) at io.netty.handler.codec.http2.Http2CodecUtil.headerListSizeExceeded(Http2CodecUtil.java:231) at io.netty.handler.codec.http2.HpackDecoder$Http2HeadersSink.finish(HpackDecoder.java:545) at io.netty.handler.codec.http2.HpackDecoder.decode(HpackDecoder.java:132) at io.netty.handler.codec.http2.HpackDecoderBenchmark.decode(HpackDecoderBenchmark.java:85) at io.netty.handler.codec.http2.generated.HpackDecoderBenchmark_decode_jmhTest.decode_thrpt_jmhStub(HpackDecoderBenchmark_decode_jmhTest.java:120) at io.netty.handler.codec.http2.generated.HpackDecoderBenchmark_decode_jmhTest.decode_Throughput(HpackDecoderBenchmark_decode_jmhTest.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:453) at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:437) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) ``` Also we should ensure we only use ascii for header names. Modifications: Just use Integer.MAX_VALUE as limit Result: Be able to run benchmark without exceptions
1 parent a0656d2 commit 6da809d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

microbench/src/main/java/io/netty/handler/codec/http2/HpackDecoderBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void teardown() {
7272
@Benchmark
7373
@BenchmarkMode(Mode.Throughput)
7474
public void decode(final Blackhole bh) throws Http2Exception {
75-
HpackDecoder hpackDecoder = new HpackDecoder(DEFAULT_HEADER_LIST_SIZE);
75+
HpackDecoder hpackDecoder = new HpackDecoder(Integer.MAX_VALUE);
7676
@SuppressWarnings("unchecked")
7777
Http2Headers headers =
7878
new DefaultHttp2Headers() {

microbench/src/main/java/io/netty/handler/codec/http2/HpackHeader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
/**
4141
* Helper class representing a single header entry. Used by the benchmarks.
4242
*/
43-
class HpackHeader {
43+
final class HpackHeader {
4444
private static final String ALPHABET =
4545
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
4646

4747
final CharSequence name;
4848
final CharSequence value;
4949

50-
HpackHeader(byte[] name, byte[] value) {
50+
private HpackHeader(byte[] name, byte[] value) {
5151
this.name = new AsciiString(name, false);
5252
this.value = new AsciiString(value, false);
5353
}
@@ -59,7 +59,8 @@ static List<HpackHeader> createHeaders(int numHeaders, int nameLength, int value
5959
boolean limitToAscii) {
6060
List<HpackHeader> hpackHeaders = new ArrayList<HpackHeader>(numHeaders);
6161
for (int i = 0; i < numHeaders; ++i) {
62-
byte[] name = randomBytes(new byte[nameLength], limitToAscii);
62+
// Force always ascii for header names
63+
byte[] name = randomBytes(new byte[nameLength], true);
6364
byte[] value = randomBytes(new byte[valueLength], limitToAscii);
6465
hpackHeaders.add(new HpackHeader(name, value));
6566
}

0 commit comments

Comments
 (0)