From c5a602b272cd45db73bac8480b6cecdf72412124 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 4 Jul 2019 11:24:13 +0200 Subject: [PATCH] =?UTF-8?q?Increase=20maxHeaderListSize=20for=20HpackDecod?= =?UTF-8?q?erBenchmark=20to=20be=20able=20to=20be=E2=80=A6=20(#9321)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../netty/handler/codec/http2/HpackDecoderBenchmark.java | 2 +- .../java/io/netty/handler/codec/http2/HpackHeader.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/microbench/src/main/java/io/netty/handler/codec/http2/HpackDecoderBenchmark.java b/microbench/src/main/java/io/netty/handler/codec/http2/HpackDecoderBenchmark.java index 7a94def517..8a8241413f 100644 --- a/microbench/src/main/java/io/netty/handler/codec/http2/HpackDecoderBenchmark.java +++ b/microbench/src/main/java/io/netty/handler/codec/http2/HpackDecoderBenchmark.java @@ -72,7 +72,7 @@ public class HpackDecoderBenchmark extends AbstractMicrobenchmark { @Benchmark @BenchmarkMode(Mode.Throughput) public void decode(final Blackhole bh) throws Http2Exception { - HpackDecoder hpackDecoder = new HpackDecoder(DEFAULT_HEADER_LIST_SIZE); + HpackDecoder hpackDecoder = new HpackDecoder(Integer.MAX_VALUE); @SuppressWarnings("unchecked") Http2Headers headers = new DefaultHttp2Headers() { diff --git a/microbench/src/main/java/io/netty/handler/codec/http2/HpackHeader.java b/microbench/src/main/java/io/netty/handler/codec/http2/HpackHeader.java index dede5f9a87..884341ac4a 100644 --- a/microbench/src/main/java/io/netty/handler/codec/http2/HpackHeader.java +++ b/microbench/src/main/java/io/netty/handler/codec/http2/HpackHeader.java @@ -40,14 +40,14 @@ import java.util.Random; /** * Helper class representing a single header entry. Used by the benchmarks. */ -class HpackHeader { +final class HpackHeader { private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; final CharSequence name; final CharSequence value; - HpackHeader(byte[] name, byte[] value) { + private HpackHeader(byte[] name, byte[] value) { this.name = new AsciiString(name, false); this.value = new AsciiString(value, false); } @@ -59,7 +59,8 @@ class HpackHeader { boolean limitToAscii) { List hpackHeaders = new ArrayList<>(numHeaders); for (int i = 0; i < numHeaders; ++i) { - byte[] name = randomBytes(new byte[nameLength], limitToAscii); + // Force always ascii for header names + byte[] name = randomBytes(new byte[nameLength], true); byte[] value = randomBytes(new byte[valueLength], limitToAscii); hpackHeaders.add(new HpackHeader(name, value)); }