diff options
author | Craig Tiller <ctiller@google.com> | 2017-04-12 14:48:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-12 14:48:36 -0700 |
commit | 023a51a7fadc5d1a764fa8dddedceb396f54cff6 (patch) | |
tree | e77b919bd8cab25729c3ae096fec5d1e18953ab4 /test | |
parent | d338dd3d391e4fe1eabcaf19586943604b2358df (diff) | |
parent | 12d716c88ce3b4f81d1d4c7a8fdbcddf65134b62 (diff) |
Merge pull request #10473 from ctiller/truebin
True Binary Encoding
Diffstat (limited to 'test')
-rw-r--r-- | test/core/transport/chttp2/hpack_encoder_test.c | 61 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 154 |
2 files changed, 146 insertions, 69 deletions
diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index d572d79a7f..f4ccc71b39 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -60,9 +60,9 @@ size_t cap_to_delete = 0; /* verify that the output generated by encoding the stream matches the hexstring passed in */ -static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, - size_t expect_window_used, const char *expected, - size_t nheaders, ...) { +static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, bool eof, + bool use_true_binary_metadata, size_t expect_window_used, + const char *expected, size_t nheaders, ...) { grpc_slice_buffer output; grpc_slice merged; grpc_slice expect = parse_hexstring(expected); @@ -103,8 +103,14 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, grpc_transport_one_way_stats stats; memset(&stats, 0, sizeof(stats)); - grpc_chttp2_encode_header(exec_ctx, &g_compressor, 0xdeadbeef, &b, eof, 16384, - &stats, &output); + grpc_encode_header_options hopt = { + .stream_id = 0xdeadbeef, + .is_eof = eof, + .use_true_binary_metadata = use_true_binary_metadata, + .max_frame_size = 16384, + .stats = &stats, + }; + grpc_chttp2_encode_header(exec_ctx, &g_compressor, &b, &hopt, &output); merged = grpc_slice_merge(output.slices, output.count); grpc_slice_buffer_destroy_internal(exec_ctx, &output); grpc_metadata_batch_destroy(exec_ctx, &b); @@ -127,25 +133,28 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, static void test_basic_headers(grpc_exec_ctx *exec_ctx) { int i; - verify(exec_ctx, 0, 0, 0, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); - verify(exec_ctx, 0, 0, 0, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, 0, 0, 0, "000001 0104 deadbeef be", 1, "a", "a"); - verify(exec_ctx, 0, 0, 0, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", - "b", "c"); - verify(exec_ctx, 0, 0, 0, "000002 0104 deadbeef bf be", 2, "a", "a", "b", - "c"); - verify(exec_ctx, 0, 0, 0, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); + verify(exec_ctx, 0, false, false, 0, "000005 0104 deadbeef 40 0161 0161", 1, + "a", "a"); + verify(exec_ctx, 0, false, false, 0, "000001 0104 deadbeef be", 1, "a", "a"); + verify(exec_ctx, 0, false, false, 0, "000001 0104 deadbeef be", 1, "a", "a"); + verify(exec_ctx, 0, false, false, 0, "000006 0104 deadbeef be 40 0162 0163", + 2, "a", "a", "b", "c"); + verify(exec_ctx, 0, false, false, 0, "000002 0104 deadbeef bf be", 2, "a", + "a", "b", "c"); + verify(exec_ctx, 0, false, false, 0, "000004 0104 deadbeef 7f 00 0164", 1, + "a", "d"); /* flush out what's there to make a few values look very popular */ for (i = 0; i < 350; i++) { - verify(exec_ctx, 0, 0, 0, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", - "c", "a", "d"); + verify(exec_ctx, 0, false, false, 0, "000003 0104 deadbeef c0 bf be", 3, + "a", "a", "b", "c", "a", "d"); } - verify(exec_ctx, 0, 0, 0, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", - "k", "v"); + verify(exec_ctx, 0, false, false, 0, "000006 0104 deadbeef c0 00 016b 0176", + 2, "a", "a", "k", "v"); /* this could be 000004 0104 deadbeef 0f 30 0176 also */ - verify(exec_ctx, 0, 0, 0, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); + verify(exec_ctx, 0, false, false, 0, "000004 0104 deadbeef 0f 2f 0176", 1, + "a", "v"); } static void encode_int_to_str(int i, char *p) { @@ -179,17 +188,17 @@ static void test_decode_table_overflow(grpc_exec_ctx *exec_ctx) { } if (i > 0) { - verify(exec_ctx, 0, 0, 0, expect, 2, "aa", "ba", key, value); + verify(exec_ctx, 0, false, false, 0, expect, 2, "aa", "ba", key, value); } else { - verify(exec_ctx, 0, 0, 0, expect, 1, key, value); + verify(exec_ctx, 0, false, false, 0, expect, 1, key, value); } gpr_free(expect); } /* if the above passes, then we must have just knocked this pair out of the decoder stack, and so we'll be forced to re-encode it */ - verify(exec_ctx, 0, 0, 0, "000007 0104 deadbeef 40 026161 026261", 1, "aa", - "ba"); + verify(exec_ctx, 0, false, false, 0, "000007 0104 deadbeef 40 026161 026261", + 1, "aa", "ba"); } static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, @@ -214,8 +223,12 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, grpc_transport_one_way_stats stats; memset(&stats, 0, sizeof(stats)); - grpc_chttp2_encode_header(exec_ctx, &g_compressor, 0xdeadbeef, &b, 0, 16384, - &stats, &output); + grpc_encode_header_options hopt = {.stream_id = 0xdeadbeef, + .is_eof = false, + .use_true_binary_metadata = false, + .max_frame_size = 16384, + .stats = &stats}; + grpc_chttp2_encode_header(exec_ctx, &g_compressor, &b, &hopt, &output); grpc_slice_buffer_destroy_internal(exec_ctx, &output); grpc_metadata_batch_destroy(exec_ctx, &b); diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index 55d2d2f58d..581440682a 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -90,10 +90,15 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State &state) { grpc_slice_buffer outbuf; grpc_slice_buffer_init(&outbuf); while (state.KeepRunning()) { - uint32_t stream_id = static_cast<uint32_t>(state.iterations()); - grpc_chttp2_encode_header(&exec_ctx, &c, stream_id, &b, state.range(0), - state.range(1), &stats, &outbuf); - if (!logged_representative_output) { + grpc_encode_header_options hopt = { + static_cast<uint32_t>(state.iterations()), + state.range(0) != 0, + Fixture::kEnableTrueBinary, + (size_t)state.range(1), + &stats, + }; + grpc_chttp2_encode_header(&exec_ctx, &c, &b, &hopt, &outbuf); + if (!logged_representative_output && state.iterations() > 3) { logged_representative_output = true; for (size_t i = 0; i < outbuf.count; i++) { char *s = grpc_dump_slice(outbuf.slices[i], GPR_DUMP_HEX); @@ -122,6 +127,7 @@ namespace hpack_encoder_fixtures { class EmptyBatch { public: + static constexpr bool kEnableTrueBinary = false; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {}; } @@ -129,6 +135,7 @@ class EmptyBatch { class SingleStaticElem { public: + static constexpr bool kEnableTrueBinary = false; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE}; } @@ -136,6 +143,7 @@ class SingleStaticElem { class SingleInternedElem { public: + static constexpr bool kEnableTrueBinary = false; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {grpc_mdelem_from_slices( exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), @@ -143,9 +151,10 @@ class SingleInternedElem { } }; -template <int kLength> +template <int kLength, bool kTrueBinary> class SingleInternedBinaryElem { public: + static constexpr bool kEnableTrueBinary = kTrueBinary; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { grpc_slice bytes = MakeBytes(); std::vector<grpc_mdelem> out = {grpc_mdelem_from_slices( @@ -167,6 +176,7 @@ class SingleInternedBinaryElem { class SingleInternedKeyElem { public: + static constexpr bool kEnableTrueBinary = false; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {grpc_mdelem_from_slices( exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), @@ -176,6 +186,7 @@ class SingleInternedKeyElem { class SingleNonInternedElem { public: + static constexpr bool kEnableTrueBinary = false; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_static_string("abc"), @@ -183,9 +194,10 @@ class SingleNonInternedElem { } }; -template <int kLength> +template <int kLength, bool kTrueBinary> class SingleNonInternedBinaryElem { public: + static constexpr bool kEnableTrueBinary = kTrueBinary; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {grpc_mdelem_from_slices( exec_ctx, grpc_slice_from_static_string("abc-bin"), MakeBytes())}; @@ -203,6 +215,7 @@ class SingleNonInternedBinaryElem { class RepresentativeClientInitialMetadata { public: + static constexpr bool kEnableTrueBinary = true; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, @@ -224,6 +237,7 @@ class RepresentativeClientInitialMetadata { class RepresentativeServerInitialMetadata { public: + static constexpr bool kEnableTrueBinary = true; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {GRPC_MDELEM_STATUS_200, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, @@ -233,6 +247,7 @@ class RepresentativeServerInitialMetadata { class RepresentativeServerTrailingMetadata { public: + static constexpr bool kEnableTrueBinary = true; static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { return {GRPC_MDELEM_GRPC_STATUS_0}; } @@ -247,28 +262,67 @@ BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleInternedKeyElem) ->Args({0, 16384}); BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleInternedElem) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleInternedBinaryElem<1>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<1, false>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<3, false>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<10, false>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<31, false>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<100, false>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<1, true>) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleInternedBinaryElem<3>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<3, true>) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleInternedBinaryElem<10>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<10, true>) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleInternedBinaryElem<31>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<31, true>) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleInternedBinaryElem<100>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleInternedBinaryElem<100, true>) ->Args({0, 16384}); BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleNonInternedElem) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleNonInternedBinaryElem<1>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<1, false>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<3, false>) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleNonInternedBinaryElem<3>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<10, false>) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleNonInternedBinaryElem<10>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<31, false>) ->Args({0, 16384}); -BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleNonInternedBinaryElem<31>) +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<100, false>) ->Args({0, 16384}); BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, - SingleNonInternedBinaryElem<100>) + SingleNonInternedBinaryElem<1, true>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<3, true>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<10, true>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<31, true>) + ->Args({0, 16384}); +BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, + SingleNonInternedBinaryElem<100, true>) ->Args({0, 16384}); // test with a tiny frame size, to highlight continuation costs BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, SingleNonInternedElem) @@ -421,7 +475,27 @@ class NonIndexedElem { } }; -class NonIndexedBinaryElem1 { +template <int kLength, bool kTrueBinary> +class NonIndexedBinaryElem; + +template <int kLength> +class NonIndexedBinaryElem<kLength, true> { + public: + static std::vector<grpc_slice> GetInitSlices() { return {}; } + static std::vector<grpc_slice> GetBenchmarkSlices() { + std::vector<uint8_t> v = { + 0x00, 0x07, 'a', 'b', 'c', + '-', 'b', 'i', 'n', static_cast<uint8_t>(kLength + 1), + 0}; + for (int i = 0; i < kLength; i++) { + v.push_back(static_cast<uint8_t>(i)); + } + return {MakeSlice(v)}; + } +}; + +template <> +class NonIndexedBinaryElem<1, false> { public: static std::vector<grpc_slice> GetInitSlices() { return {}; } static std::vector<grpc_slice> GetBenchmarkSlices() { @@ -430,7 +504,8 @@ class NonIndexedBinaryElem1 { } }; -class NonIndexedBinaryElem3 { +template <> +class NonIndexedBinaryElem<3, false> { public: static std::vector<grpc_slice> GetInitSlices() { return {}; } static std::vector<grpc_slice> GetBenchmarkSlices() { @@ -439,7 +514,8 @@ class NonIndexedBinaryElem3 { } }; -class NonIndexedBinaryElem10 { +template <> +class NonIndexedBinaryElem<10, false> { public: static std::vector<grpc_slice> GetInitSlices() { return {}; } static std::vector<grpc_slice> GetBenchmarkSlices() { @@ -449,7 +525,8 @@ class NonIndexedBinaryElem10 { } }; -class NonIndexedBinaryElem31 { +template <> +class NonIndexedBinaryElem<31, false> { public: static std::vector<grpc_slice> GetInitSlices() { return {}; } static std::vector<grpc_slice> GetBenchmarkSlices() { @@ -461,7 +538,8 @@ class NonIndexedBinaryElem31 { } }; -class NonIndexedBinaryElem100 { +template <> +class NonIndexedBinaryElem<100, false> { public: static std::vector<grpc_slice> GetInitSlices() { return {}; } static std::vector<grpc_slice> GetBenchmarkSlices() { @@ -570,11 +648,16 @@ BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, IndexedSingleInternedElem); BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, AddIndexedSingleInternedElem); BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, KeyIndexedSingleInternedElem); BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedElem); -BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem1); -BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem3); -BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem10); -BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem31); -BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem100); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<1, false>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<3, false>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<10, false>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<31, false>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<100, false>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<1, true>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<3, true>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<10, true>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<31, true>); +BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, NonIndexedBinaryElem<100, true>); BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, RepresentativeClientInitialMetadata); BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, @@ -584,23 +667,4 @@ BENCHMARK_TEMPLATE(BM_HpackParserParseHeader, } // namespace hpack_parser_fixtures -static void BM_Base16SomeStuff(benchmark::State &state) { - uint8_t *bytes = new uint8_t[state.range(0)]; - for (int i = 0; i < state.range(0); i++) { - bytes[i] = static_cast<uint8_t>(rand()); - } - uint8_t *encoded = new uint8_t[state.range(0) * 2]; - static const uint8_t hex[] = "0123456789abcdef"; - while (state.KeepRunning()) { - for (int i = 0; i < state.range(0); i++) { - encoded[2 * i + 0] = hex[encoded[i] >> 8]; - encoded[2 * i + 1] = hex[encoded[i] & 0xf]; - } - } - delete[] encoded; - delete[] bytes; - state.SetBytesProcessed(state.iterations() * state.range(0)); -} -BENCHMARK(BM_Base16SomeStuff)->Range(1, 4096); - BENCHMARK_MAIN(); |