diff --git a/docs/performance/http-arena-followup.json b/docs/performance/http-arena-followup.json new file mode 100644 index 00000000..4e6dbdab --- /dev/null +++ b/docs/performance/http-arena-followup.json @@ -0,0 +1,2599 @@ +{ + "measured_dates": "2026-11-11/2026-11-12", + "baseline_commit": "28a1e2c7b9e22fac5d0c74444b5c99da17b7acd3", + "after_source": "Measurement-time worktree based on baseline_commit; component provenance below. Source hashes describe that snapshot, before later PR integration.", + "platform": "macOS arm64, non-isolated workstation, loopback client/server", + "rustc": "rustc 1.99.0 (b940084d7 2026-09-28)", + "cargo_lock_sha256": "8f99c8c4b177970c4a62913b1864cb78e8c519c8b624d46c02ea1a0e93fb244f", + "conditions": [ + "No concurrent task-owned builds, tests or benchmarks during these runs.", + "HTTP1/2/3 and Criterion cases ran A/B/A/B; WebSocket ran three A/B pairs.", + "All included rounds retained; earlier overlapping-build H2 probe excluded.", + "Network summary is median of all round RPS; WS is median of three rates.", + "Criterion summary is median of two run point estimates, not request-latency percentiles.", + "HTTP1 uses multithread Server::spawn_http, whereas Arena uses serve_per_thread.", + "H3 finish tolerates RemoteTerminate(0) only; response status, body and EOF still checked.", + "gRPC group overrides CLI timing: 1 s warmup, 3 s measurement, 50 samples.", + "Compression: 1 s warmup, 2 s target, 30 samples; mixed case automatically took longer.", + "Compression labels 128/1024/16384 denote actual JSON lengths 140/1031/16394 bytes.", + "Microbenchmarks exclude network/TLS; no official Arena or gateway rerun." + ], + "provenance": { + "http1_http3": "Archived baseline HEAD and final worktree; identical harness/lockfile; all workspace crates explicitly rebuilt for each source.", + "http2": "Baseline binary preserved before edits; final binary rebuilt after metadata correctness fixes; identical harness.", + "grpc": "Shared-worktree builds before/after message.rs MIME fast path; other concurrent transport edits are outside direct extractor path. Not full frozen snapshots.", + "compression": "Shared-worktree builds with HEAD vs new compression files; same core artifact 228e2e6ff8253c7c (fingerprint 2024348527227860782). Timed production paths unchanged since capture. Later bench changes only filtered-run guard and setup String::new.", + "ws": "Shared-worktree release test builds with default,ws (Tokio); old/new socket.rs differ only in inherent send. Identical buffered echo harness; unrelated later transport edits do not execute in the timed path. Not full frozen snapshots." + }, + "source_sha256": { + "tako-rs-core/benches/grpc_decode.rs": "ef082523e1bb69cfb410a7a6298c3475dd33bf5c551acb39182800bedb42d84a", + "tako-rs-core/src/grpc/message.rs": "1d654f35c4c0f9a513fdb8987155c9c25a83c2eb241eefb952bbf492f032e7a4", + "tako-rs-core/src/router/dispatch.rs": "1d514a86b3ac796dab8297f155f2d7b9cab0fa1c073bdfcc6e3fd8f5f281eecc", + "tako-rs-core/src/router/fast_path.rs": "abe8d2b8ded523ff6a10dc60deb825814afed8b8b24cf00b268c23e2b42eb74d", + "tako-rs-core/src/router/fast_path/tests.rs": "7103b445d8d7d9a9a81315b27717f73a7e427374f4e96fadfb3c98eac558249d", + "tako-rs-core/src/server_support.rs": "bd9cc8f030cdca1ab330a107c943b9f8bbbc7c8c32578fa09af59f07e6c0f990", + "tako-rs-core/src/server_support/http.rs": "b9329a8b7c7970e3238069583e24043d9540ef48cdc06253172363ed6e74ef40", + "tako-rs-core/src/server_support/http/tests.rs": "e803f289d463859f2eba529dd958d44107648fbb2c3b0c8a90825f233afd6ff1", + "tako-rs-core/src/ws/socket.rs": "abf97953b6c801cb0c5d0086c6da68b0d8bf915cc37578f2b24114573e5f48d5", + "tako-rs-core/tests/grpc_unary.rs": "7c537a6184666957e5d62830a964e71341a6398ee35a1e34fa8f8986081fe5a8", + "tako-rs-plugins/benches/compression.rs": "88aebac3c67f6f64fe64fea3787219b75b13db0dee5a63d461597a8030737f53", + "tako-rs-plugins/src/plugins/compression.rs": "a54379938b82b1fb81da61cbf18fb4b19c3a57415eb536fa6b45b23eaefe206f", + "tako-rs-plugins/src/plugins/compression/frames.rs": "dd1bd9d8e8ab285a938d09ef044570b2fafbc35049c59eac46491a4f6cc9936d", + "tako-rs-plugins/src/plugins/compression/negotiate.rs": "bb3ea7ca425ad05bc6c8e3d60ca8bb33ed3bdae4b0c1d94a730479feed1128d2", + "tako-rs-plugins/src/plugins/compression/plugin.rs": "0d264ae9773fa462e861a1a3cdd6c9baf246889a3f3a308ba063d68b4522e35e", + "tako-rs-server/benches/http3.rs": "7352a004c880d4ca349e2fb82fe331b3f37002a25e57a3f5eac656847d4a94b2", + "tako-rs-server/src/h3_common/request.rs": "e05093aa142ed49630d3b40cd60fee4b7f5f8017aaf2dceb31b42e0db77baedd", + "tako-rs-server/src/server_tls_compio/accept.rs": "12a9971e998ba14731894fa8ae936a073e6977dc83ba31ae14ac86a4f4dd2716", + "tako-rs-server/tests/tenant_authority.rs": "a597abd9d737e90899147cfe06269648ac825dad43a36ecd058cd04f896b28f4", + "tako-rs-core/src/ws/socket/benchmarks.rs": "20fffb8873ec35f04598cf53e40c4b4f8735c4dee84d5762bd6f6dc577b8145f", + "tako-rs-core/src/ws/socket/send_tests.rs": "562a5dbdbf1ca78b41a8038bdb9830ab5796bc75d6653be52bb91613dc1ec29c", + "tako-rs-core/tests/grpc_allocations.rs": "daa59719b624ecbf71f016705677dc3c051ebde476a747bd6cbdae47a1b66a29", + "tako-rs-plugins/src/plugins/compression/buffered_tests.rs": "a23d81d79c6aefb3fa51a5d3363a7833a18987c67e1d50d64c218311037c9fb8", + "tako-rs-plugins/src/plugins/compression/negotiation_tests.rs": "be2212a385400f97e07ad15e293fa44b5905efd7a28e6bbb8def2044b65044c5", + "tako-rs-plugins/tests/compression_allocations.rs": "039c6327bc53f0c633a77303c6acf8d68a48a8ba1d2006eeeefe8af1016d4477", + "tako-rs-server/benches/http1.rs": "0b86d93c22997d3bd94cf7712d64dc420d30dae2b8bd9ec1f2f20f39d557b065", + "tako-rs-server/tests/h3_metadata.rs": "2f4a26e91bd393ecacf6867e30dbc45bf8de3a9b757afb7233934b761ea20db2" + }, + "summaries": [ + { + "case": "http1-p1", + "unit": "requests/s", + "before_median": 184635.0, + "after_median": 184783.5, + "change_percent": 0.08042895442359477, + "before_values": [ + 183781, + 184346, + 178213, + 184083, + 184026, + 185489, + 186468, + 184924, + 186257, + 185356 + ], + "after_values": [ + 182823, + 184952, + 184419, + 184116, + 184971, + 184615, + 185041, + 185390, + 179942, + 185367 + ] + }, + { + "case": "http1-p16", + "unit": "requests/s", + "before_median": 3013597.5, + "after_median": 3026021.5, + "change_percent": 0.4122647433839388, + "before_values": [ + 2987581, + 3021619, + 3008800, + 2794420, + 3018395, + 3043923, + 2948412, + 2996695, + 3054569, + 3058191 + ], + "after_values": [ + 2977912, + 2987195, + 2910345, + 2992901, + 3025082, + 3066513, + 3026961, + 3069334, + 3058213, + 3063574 + ] + }, + { + "case": "http2", + "unit": "requests/s", + "before_median": 778449.5, + "after_median": 784320.0, + "change_percent": 0.754127274794314, + "before_values": [ + 784593, + 774790, + 751729, + 782109, + 771554, + 792426 + ], + "after_values": [ + 749145, + 768502, + 758072, + 800138, + 803367, + 812525 + ] + }, + { + "case": "http3", + "unit": "requests/s", + "before_median": 111982.5, + "after_median": 116634.5, + "change_percent": 4.15422052552854, + "before_values": [ + 114509, + 111866, + 112099, + 111164, + 106863, + 113462 + ], + "after_values": [ + 110146, + 109888, + 116591, + 116678, + 121364, + 124739 + ] + }, + { + "case": "ws_buffered_echo/5", + "unit": "messages/s", + "before_median": 24223401, + "after_median": 25451550, + "change_percent": 5.070093171474976, + "before_values": [ + 24588622, + 24223401, + 22791868 + ], + "after_values": [ + 26062045, + 23402993, + 25451550 + ] + }, + { + "case": "ws_buffered_echo/64", + "unit": "messages/s", + "before_median": 23663009, + "after_median": 25057568, + "change_percent": 5.893413639829159, + "before_values": [ + 23928115, + 23663009, + 21458891 + ], + "after_values": [ + 25185792, + 24268734, + 25057568 + ] + }, + { + "case": "ws_buffered_echo/1024", + "unit": "messages/s", + "before_median": 11055668, + "after_median": 10870090, + "change_percent": -1.6785779023031466, + "before_values": [ + 11343165, + 11055668, + 10826866 + ], + "after_values": [ + 11523480, + 10870090, + 10785100 + ] + }, + { + "case": "grpc_decode/unary_sum", + "unit": "ns", + "before_median": 222.32, + "after_median": 199.4, + "change_percent": -10.309463835912192, + "before_values": [ + 224.99, + 219.65 + ], + "after_values": [ + 199.49, + 199.31 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/proto", + "unit": "ns", + "before_median": 238.54000000000002, + "after_median": 201.85500000000002, + "change_percent": -15.378972080154274, + "before_values": [ + 237.15, + 239.93 + ], + "after_values": [ + 205.0, + 198.71 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/mixed_case", + "unit": "ns", + "before_median": 233.375, + "after_median": 199.42000000000002, + "change_percent": -14.549544724156394, + "before_values": [ + 232.19, + 234.56 + ], + "after_values": [ + 200.13, + 198.71 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/parameterized", + "unit": "ns", + "before_median": 248.96, + "after_median": 248.385, + "change_percent": -0.23096079691516946, + "before_values": [ + 249.43, + 248.49 + ], + "after_values": [ + 248.51, + 248.26 + ] + }, + { + "case": "compression_buffered/identity/128", + "unit": "ns", + "before_median": 642.65, + "after_median": 604.985, + "change_percent": -5.860888508519402, + "before_values": [ + 666.65, + 618.65 + ], + "after_values": [ + 596.27, + 613.7 + ] + }, + { + "case": "compression_buffered/gzip/128", + "unit": "ns", + "before_median": 681.645, + "after_median": 630.465, + "change_percent": -7.50830711000593, + "before_values": [ + 696.48, + 666.81 + ], + "after_values": [ + 629.61, + 631.32 + ] + }, + { + "case": "compression_buffered/br/128", + "unit": "ns", + "before_median": 687.185, + "after_median": 623.6949999999999, + "change_percent": -9.239142297925596, + "before_values": [ + 712.29, + 662.08 + ], + "after_values": [ + 626.93, + 620.46 + ] + }, + { + "case": "compression_buffered/deflate/128", + "unit": "ns", + "before_median": 689.8699999999999, + "after_median": 627.53, + "change_percent": -9.036485134880479, + "before_values": [ + 709.68, + 670.06 + ], + "after_values": [ + 623.1, + 631.96 + ] + }, + { + "case": "compression_buffered/identity/1024", + "unit": "ns", + "before_median": 668.405, + "after_median": 602.12, + "change_percent": -9.916891704879527, + "before_values": [ + 714.2, + 622.61 + ], + "after_values": [ + 596.77, + 607.47 + ] + }, + { + "case": "compression_buffered/gzip/1024", + "unit": "ns", + "before_median": 7001.400000000001, + "after_median": 6879.1, + "change_percent": -1.7467934984431666, + "before_values": [ + 7081.1, + 6921.700000000001 + ], + "after_values": [ + 6855.2, + 6903.0 + ] + }, + { + "case": "compression_buffered/br/1024", + "unit": "ns", + "before_median": 12682.0, + "after_median": 12536.5, + "change_percent": -1.147295379277713, + "before_values": [ + 12903.0, + 12461.0 + ], + "after_values": [ + 12457.0, + 12616.0 + ] + }, + { + "case": "compression_buffered/deflate/1024", + "unit": "ns", + "before_median": 6916.55, + "after_median": 6692.900000000001, + "change_percent": -3.233548517685836, + "before_values": [ + 6986.6, + 6846.5 + ], + "after_values": [ + 6690.400000000001, + 6695.400000000001 + ] + }, + { + "case": "compression_buffered/identity/16384", + "unit": "ns", + "before_median": 633.24, + "after_median": 605.27, + "change_percent": -4.4169667108837185, + "before_values": [ + 646.94, + 619.54 + ], + "after_values": [ + 594.71, + 615.83 + ] + }, + { + "case": "compression_buffered/gzip/16384", + "unit": "ns", + "before_median": 17973.5, + "after_median": 17429.5, + "change_percent": -3.0266781650763575, + "before_values": [ + 18438.0, + 17509.0 + ], + "after_values": [ + 17391.0, + 17468.0 + ] + }, + { + "case": "compression_buffered/br/16384", + "unit": "ns", + "before_median": 26504.0, + "after_median": 24144.5, + "change_percent": -8.902429821913671, + "before_values": [ + 28699.0, + 24309.0 + ], + "after_values": [ + 24114.0, + 24175.0 + ] + }, + { + "case": "compression_buffered/deflate/16384", + "unit": "ns", + "before_median": 17624.0, + "after_median": 16962.0, + "change_percent": -3.7562414888787976, + "before_values": [ + 17318.0, + 17930.0 + ], + "after_values": [ + 16763.0, + 17161.0 + ] + }, + { + "case": "compression_negotiation/empty", + "unit": "ns", + "before_median": 521.035, + "after_median": 490.755, + "change_percent": -5.811509783411861, + "before_values": [ + 498.05, + 544.02 + ], + "after_values": [ + 488.08, + 493.43 + ] + }, + { + "case": "compression_negotiation/gzip", + "unit": "ns", + "before_median": 537.24, + "after_median": 498.075, + "change_percent": -7.290037971856156, + "before_values": [ + 536.3, + 538.18 + ], + "after_values": [ + 497.5, + 498.65 + ] + }, + { + "case": "compression_negotiation/browser", + "unit": "ns", + "before_median": 611.7149999999999, + "after_median": 544.3199999999999, + "change_percent": -11.017385547191093, + "before_values": [ + 615.55, + 607.88 + ], + "after_values": [ + 536.04, + 552.6 + ] + }, + { + "case": "compression_negotiation/parameters", + "unit": "ns", + "before_median": 668.13, + "after_median": 597.49, + "change_percent": -10.57279271997964, + "before_values": [ + 678.67, + 657.59 + ], + "after_values": [ + 587.09, + 607.89 + ] + }, + { + "case": "compression_negotiation/unknown_tokens", + "unit": "ns", + "before_median": 4484.4, + "after_median": 2297.45, + "change_percent": -48.76795111943627, + "before_values": [ + 4505.7, + 4463.099999999999 + ], + "after_values": [ + 2274.7000000000003, + 2320.2 + ] + }, + { + "case": "compression_mixed_requests", + "unit": "ns", + "before_median": 7772000.0, + "after_median": 7814900.0, + "change_percent": 0.5519814719505911, + "before_values": [ + 7810800.0, + 7733200.0 + ], + "after_values": [ + 7744200.0, + 7885600.0 + ] + } + ], + "runs": [ + { + "name": "http1-p1-before-1", + "command": [ + "/private/tmp/tako-perf-20261111/http1-before" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "1", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "59a93a378b1b51c769dfffbdbcba793da50db6cdf3bd006f47a5173bfbeebc71", + "elapsed_seconds": 15.476062667003134, + "exit_code": 0, + "observations": [ + { + "case": "http1-p1", + "unit": "requests/s", + "round": 1, + "value": 183781, + "elapsed_ms": 2852.8 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 2, + "value": 184346, + "elapsed_ms": 2844.0 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 3, + "value": 178213, + "elapsed_ms": 2941.9 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 4, + "value": 184083, + "elapsed_ms": 2848.1 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 5, + "value": 184026, + "elapsed_ms": 2849.0 + } + ] + }, + { + "name": "http1-p1-after-2", + "command": [ + "/private/tmp/tako-perf-20261111/http1-after" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "1", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "b45ce6aee33d84a194517bbbd342b7e01c5cb643c8d3f9abdee2b51e77773065", + "elapsed_seconds": 15.165718791999097, + "exit_code": 0, + "observations": [ + { + "case": "http1-p1", + "unit": "requests/s", + "round": 1, + "value": 182823, + "elapsed_ms": 2867.7 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 2, + "value": 184952, + "elapsed_ms": 2834.7 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 3, + "value": 184419, + "elapsed_ms": 2842.9 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 4, + "value": 184116, + "elapsed_ms": 2847.6 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 5, + "value": 184971, + "elapsed_ms": 2834.4 + } + ] + }, + { + "name": "http1-p1-before-3", + "command": [ + "/private/tmp/tako-perf-20261111/http1-before" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "1", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "59a93a378b1b51c769dfffbdbcba793da50db6cdf3bd006f47a5173bfbeebc71", + "elapsed_seconds": 14.827064459001122, + "exit_code": 0, + "observations": [ + { + "case": "http1-p1", + "unit": "requests/s", + "round": 1, + "value": 185489, + "elapsed_ms": 2826.5 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 2, + "value": 186468, + "elapsed_ms": 2811.7 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 3, + "value": 184924, + "elapsed_ms": 2835.2 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 4, + "value": 186257, + "elapsed_ms": 2814.9 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 5, + "value": 185356, + "elapsed_ms": 2828.5 + } + ] + }, + { + "name": "http1-p1-after-4", + "command": [ + "/private/tmp/tako-perf-20261111/http1-after" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "1", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "b45ce6aee33d84a194517bbbd342b7e01c5cb643c8d3f9abdee2b51e77773065", + "elapsed_seconds": 14.950105625001015, + "exit_code": 0, + "observations": [ + { + "case": "http1-p1", + "unit": "requests/s", + "round": 1, + "value": 184615, + "elapsed_ms": 2839.9 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 2, + "value": 185041, + "elapsed_ms": 2833.4 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 3, + "value": 185390, + "elapsed_ms": 2828.0 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 4, + "value": 179942, + "elapsed_ms": 2913.7 + }, + { + "case": "http1-p1", + "unit": "requests/s", + "round": 5, + "value": 185367, + "elapsed_ms": 2828.4 + } + ] + }, + { + "name": "http1-p16-before-1", + "command": [ + "/private/tmp/tako-perf-20261111/http1-before" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "16", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "59a93a378b1b51c769dfffbdbcba793da50db6cdf3bd006f47a5173bfbeebc71", + "elapsed_seconds": 0.9382422499984386, + "exit_code": 0, + "observations": [ + { + "case": "http1-p16", + "unit": "requests/s", + "round": 1, + "value": 2987581, + "elapsed_ms": 175.5 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 2, + "value": 3021619, + "elapsed_ms": 173.5 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 3, + "value": 3008800, + "elapsed_ms": 174.3 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 4, + "value": 2794420, + "elapsed_ms": 187.6 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 5, + "value": 3018395, + "elapsed_ms": 173.7 + } + ] + }, + { + "name": "http1-p16-after-2", + "command": [ + "/private/tmp/tako-perf-20261111/http1-after" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "16", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "b45ce6aee33d84a194517bbbd342b7e01c5cb643c8d3f9abdee2b51e77773065", + "elapsed_seconds": 0.9326856249972479, + "exit_code": 0, + "observations": [ + { + "case": "http1-p16", + "unit": "requests/s", + "round": 1, + "value": 2977912, + "elapsed_ms": 176.1 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 2, + "value": 2987195, + "elapsed_ms": 175.5 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 3, + "value": 2910345, + "elapsed_ms": 180.1 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 4, + "value": 2992901, + "elapsed_ms": 175.2 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 5, + "value": 3025082, + "elapsed_ms": 173.3 + } + ] + }, + { + "name": "http1-p16-before-3", + "command": [ + "/private/tmp/tako-perf-20261111/http1-before" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "16", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "59a93a378b1b51c769dfffbdbcba793da50db6cdf3bd006f47a5173bfbeebc71", + "elapsed_seconds": 0.9203617090024636, + "exit_code": 0, + "observations": [ + { + "case": "http1-p16", + "unit": "requests/s", + "round": 1, + "value": 3043923, + "elapsed_ms": 172.2 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 2, + "value": 2948412, + "elapsed_ms": 177.8 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 3, + "value": 2996695, + "elapsed_ms": 175.0 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 4, + "value": 3054569, + "elapsed_ms": 171.6 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 5, + "value": 3058191, + "elapsed_ms": 171.4 + } + ] + }, + { + "name": "http1-p16-after-4", + "command": [ + "/private/tmp/tako-perf-20261111/http1-after" + ], + "settings": { + "CONNECTIONS": "64", + "PIPELINE": "16", + "REQUESTS": "8192", + "ROUNDS": "5", + "WORKERS": "4" + }, + "sha256": "b45ce6aee33d84a194517bbbd342b7e01c5cb643c8d3f9abdee2b51e77773065", + "elapsed_seconds": 0.9072132500004955, + "exit_code": 0, + "observations": [ + { + "case": "http1-p16", + "unit": "requests/s", + "round": 1, + "value": 3066513, + "elapsed_ms": 171.0 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 2, + "value": 3026961, + "elapsed_ms": 173.2 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 3, + "value": 3069334, + "elapsed_ms": 170.8 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 4, + "value": 3058213, + "elapsed_ms": 171.4 + }, + { + "case": "http1-p16", + "unit": "requests/s", + "round": 5, + "value": 3063574, + "elapsed_ms": 171.1 + } + ] + }, + { + "name": "http2-before-1", + "command": [ + "/private/tmp/tako-perf-20261111/http2-before" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "32768", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "6bc1c48ff1e1bf0c3bb63f84ebe98e5e59f7eae3c984c6e62b7795d6a8accd5a", + "elapsed_seconds": 8.89452387500205, + "exit_code": 0, + "observations": [ + { + "case": "http2", + "unit": "requests/s", + "round": 1, + "value": 784593, + "elapsed_ms": 2672.9 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 2, + "value": 774790, + "elapsed_ms": 2706.7 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 3, + "value": 751729, + "elapsed_ms": 2789.8 + } + ] + }, + { + "name": "http2-after-2", + "command": [ + "/private/tmp/tako-perf-20261111/http2-after" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "32768", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "3f8add47947fe8832f32b07f6267f023ce454790bbdad1b863714cd3a78bfbcb", + "elapsed_seconds": 9.318504708004184, + "exit_code": 0, + "observations": [ + { + "case": "http2", + "unit": "requests/s", + "round": 1, + "value": 749145, + "elapsed_ms": 2799.4 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 2, + "value": 768502, + "elapsed_ms": 2728.9 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 3, + "value": 758072, + "elapsed_ms": 2766.4 + } + ] + }, + { + "name": "http2-before-3", + "command": [ + "/private/tmp/tako-perf-20261111/http2-before" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "32768", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "6bc1c48ff1e1bf0c3bb63f84ebe98e5e59f7eae3c984c6e62b7795d6a8accd5a", + "elapsed_seconds": 8.753621374999057, + "exit_code": 0, + "observations": [ + { + "case": "http2", + "unit": "requests/s", + "round": 1, + "value": 782109, + "elapsed_ms": 2681.4 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 2, + "value": 771554, + "elapsed_ms": 2718.1 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 3, + "value": 792426, + "elapsed_ms": 2646.5 + } + ] + }, + { + "name": "http2-after-4", + "command": [ + "/private/tmp/tako-perf-20261111/http2-after" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "32768", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "3f8add47947fe8832f32b07f6267f023ce454790bbdad1b863714cd3a78bfbcb", + "elapsed_seconds": 8.546865666998201, + "exit_code": 0, + "observations": [ + { + "case": "http2", + "unit": "requests/s", + "round": 1, + "value": 800138, + "elapsed_ms": 2621.0 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 2, + "value": 803367, + "elapsed_ms": 2610.5 + }, + { + "case": "http2", + "unit": "requests/s", + "round": 3, + "value": 812525, + "elapsed_ms": 2581.0 + } + ] + }, + { + "name": "http3-before-1", + "command": [ + "/private/tmp/tako-perf-20261111/http3-before" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "8192", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "8f89cd2451f2e95df132b90a95492f5ac122f87b5b8530135175be6bf609c2b5", + "elapsed_seconds": 15.372250125001301, + "exit_code": 0, + "observations": [ + { + "case": "http3", + "unit": "requests/s", + "round": 1, + "value": 114509, + "elapsed_ms": 4578.6 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 2, + "value": 111866, + "elapsed_ms": 4686.7 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 3, + "value": 112099, + "elapsed_ms": 4677.0 + } + ] + }, + { + "name": "http3-after-2", + "command": [ + "/private/tmp/tako-perf-20261111/http3-after" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "8192", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "17642666b30477510a8df4feea449bc6fa926f5c7b33628e544c4ef813c0fd62", + "elapsed_seconds": 15.415741249998973, + "exit_code": 0, + "observations": [ + { + "case": "http3", + "unit": "requests/s", + "round": 1, + "value": 110146, + "elapsed_ms": 4760.0 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 2, + "value": 109888, + "elapsed_ms": 4771.1 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 3, + "value": 116591, + "elapsed_ms": 4496.8 + } + ] + }, + { + "name": "http3-before-3", + "command": [ + "/private/tmp/tako-perf-20261111/http3-before" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "8192", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "8f89cd2451f2e95df132b90a95492f5ac122f87b5b8530135175be6bf609c2b5", + "elapsed_seconds": 15.522713082995324, + "exit_code": 0, + "observations": [ + { + "case": "http3", + "unit": "requests/s", + "round": 1, + "value": 111164, + "elapsed_ms": 4716.4 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 2, + "value": 106863, + "elapsed_ms": 4906.2 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 3, + "value": 113462, + "elapsed_ms": 4620.8 + } + ] + }, + { + "name": "http3-after-4", + "command": [ + "/private/tmp/tako-perf-20261111/http3-after" + ], + "settings": { + "CONNECTIONS": "64", + "STREAMS": "32", + "REQUESTS": "8192", + "ROUNDS": "3", + "WORKERS": "4" + }, + "sha256": "17642666b30477510a8df4feea449bc6fa926f5c7b33628e544c4ef813c0fd62", + "elapsed_seconds": 14.36161033299868, + "exit_code": 0, + "observations": [ + { + "case": "http3", + "unit": "requests/s", + "round": 1, + "value": 116678, + "elapsed_ms": 4493.5 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 2, + "value": 121364, + "elapsed_ms": 4320.0 + }, + { + "case": "http3", + "unit": "requests/s", + "round": 3, + "value": 124739, + "elapsed_ms": 4203.1 + } + ] + }, + { + "name": "ws-before-1", + "command": [ + "/private/tmp/tako-ws-before", + "ws::socket::benchmarks::buffered_echo_throughput", + "--exact", + "--ignored", + "--nocapture", + "--test-threads=1" + ], + "settings": {}, + "sha256": "2dc2c00775130d4bc2929176b642987b29e79678d4a35392612a9792da2cfafd", + "elapsed_seconds": 0.6069613750005374, + "exit_code": 0, + "observations": [ + { + "case": "ws_buffered_echo/5", + "unit": "messages/s", + "messages": 8192000, + "elapsed_ns": 333162218, + "value": 24588622 + }, + { + "case": "ws_buffered_echo/64", + "unit": "messages/s", + "messages": 1024000, + "elapsed_ns": 42794847, + "value": 23928115 + }, + { + "case": "ws_buffered_echo/1024", + "unit": "messages/s", + "messages": 64000, + "elapsed_ns": 5642164, + "value": 11343165 + } + ] + }, + { + "name": "ws-after-2", + "command": [ + "/private/tmp/tako-ws-after", + "ws::socket::benchmarks::buffered_echo_throughput", + "--exact", + "--ignored", + "--nocapture", + "--test-threads=1" + ], + "settings": {}, + "sha256": "175f7550a6045767841915a48b627f88187ae268eb9a979cb35ce2ac4c9a50ad", + "elapsed_seconds": 0.3872238749972894, + "exit_code": 0, + "observations": [ + { + "case": "ws_buffered_echo/5", + "unit": "messages/s", + "messages": 8192000, + "elapsed_ns": 314326833, + "value": 26062045 + }, + { + "case": "ws_buffered_echo/64", + "unit": "messages/s", + "messages": 1024000, + "elapsed_ns": 40657844, + "value": 25185792 + }, + { + "case": "ws_buffered_echo/1024", + "unit": "messages/s", + "messages": 64000, + "elapsed_ns": 5553878, + "value": 11523480 + } + ] + }, + { + "name": "ws-before-3", + "command": [ + "/private/tmp/tako-ws-before", + "ws::socket::benchmarks::buffered_echo_throughput", + "--exact", + "--ignored", + "--nocapture", + "--test-threads=1" + ], + "settings": {}, + "sha256": "2dc2c00775130d4bc2929176b642987b29e79678d4a35392612a9792da2cfafd", + "elapsed_seconds": 0.39659254100115504, + "exit_code": 0, + "observations": [ + { + "case": "ws_buffered_echo/5", + "unit": "messages/s", + "messages": 8192000, + "elapsed_ns": 338185374, + "value": 24223401 + }, + { + "case": "ws_buffered_echo/64", + "unit": "messages/s", + "messages": 1024000, + "elapsed_ns": 43274293, + "value": 23663009 + }, + { + "case": "ws_buffered_echo/1024", + "unit": "messages/s", + "messages": 64000, + "elapsed_ns": 5788886, + "value": 11055668 + } + ] + }, + { + "name": "ws-after-4", + "command": [ + "/private/tmp/tako-ws-after", + "ws::socket::benchmarks::buffered_echo_throughput", + "--exact", + "--ignored", + "--nocapture", + "--test-threads=1" + ], + "settings": {}, + "sha256": "175f7550a6045767841915a48b627f88187ae268eb9a979cb35ce2ac4c9a50ad", + "elapsed_seconds": 0.4081917910007178, + "exit_code": 0, + "observations": [ + { + "case": "ws_buffered_echo/5", + "unit": "messages/s", + "messages": 8192000, + "elapsed_ns": 350040698, + "value": 23402993 + }, + { + "case": "ws_buffered_echo/64", + "unit": "messages/s", + "messages": 1024000, + "elapsed_ns": 42194207, + "value": 24268734 + }, + { + "case": "ws_buffered_echo/1024", + "unit": "messages/s", + "messages": 64000, + "elapsed_ns": 5887716, + "value": 10870090 + } + ] + }, + { + "name": "ws-before-5", + "command": [ + "/private/tmp/tako-ws-before", + "ws::socket::benchmarks::buffered_echo_throughput", + "--exact", + "--ignored", + "--nocapture", + "--test-threads=1" + ], + "settings": {}, + "sha256": "2dc2c00775130d4bc2929176b642987b29e79678d4a35392612a9792da2cfafd", + "elapsed_seconds": 0.42425004200049443, + "exit_code": 0, + "observations": [ + { + "case": "ws_buffered_echo/5", + "unit": "messages/s", + "messages": 8192000, + "elapsed_ns": 359426434, + "value": 22791868 + }, + { + "case": "ws_buffered_echo/64", + "unit": "messages/s", + "messages": 1024000, + "elapsed_ns": 47719148, + "value": 21458891 + }, + { + "case": "ws_buffered_echo/1024", + "unit": "messages/s", + "messages": 64000, + "elapsed_ns": 5911221, + "value": 10826866 + } + ] + }, + { + "name": "ws-after-6", + "command": [ + "/private/tmp/tako-ws-after", + "ws::socket::benchmarks::buffered_echo_throughput", + "--exact", + "--ignored", + "--nocapture", + "--test-threads=1" + ], + "settings": {}, + "sha256": "175f7550a6045767841915a48b627f88187ae268eb9a979cb35ce2ac4c9a50ad", + "elapsed_seconds": 0.3786992500026827, + "exit_code": 0, + "observations": [ + { + "case": "ws_buffered_echo/5", + "unit": "messages/s", + "messages": 8192000, + "elapsed_ns": 321866452, + "value": 25451550 + }, + { + "case": "ws_buffered_echo/64", + "unit": "messages/s", + "messages": 1024000, + "elapsed_ns": 40865897, + "value": 25057568 + }, + { + "case": "ws_buffered_echo/1024", + "unit": "messages/s", + "messages": 64000, + "elapsed_ns": 5934113, + "value": 10785100 + } + ] + }, + { + "name": "grpc-before-1", + "command": [ + "/private/tmp/tako-grpc-perf-before", + "--bench", + "unary_sum", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "118cacd2db2d789691585e1dd4ea0ab9362afee61c1c25037f32a1a86a45489a", + "elapsed_seconds": 18.10209274999943, + "exit_code": 0, + "observations": [ + { + "case": "grpc_decode/unary_sum", + "unit": "ns", + "value": 224.99, + "criterion_time_estimate_ns": [ + 224.53, + 224.99, + 225.51 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/proto", + "unit": "ns", + "value": 237.15, + "criterion_time_estimate_ns": [ + 236.15, + 237.15, + 238.13 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/mixed_case", + "unit": "ns", + "value": 232.19, + "criterion_time_estimate_ns": [ + 231.71, + 232.19, + 232.73 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/parameterized", + "unit": "ns", + "value": 249.43, + "criterion_time_estimate_ns": [ + 248.18, + 249.43, + 250.57 + ] + } + ] + }, + { + "name": "grpc-after-2", + "command": [ + "/private/tmp/tako-grpc-perf-after", + "--bench", + "unary_sum", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "29d6cffd5791caa51b5031af566e799c2fc2487e8c08f2ddb45e80b0ce746eb1", + "elapsed_seconds": 18.382877042000473, + "exit_code": 0, + "observations": [ + { + "case": "grpc_decode/unary_sum", + "unit": "ns", + "value": 199.49, + "criterion_time_estimate_ns": [ + 198.78, + 199.49, + 200.4 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/proto", + "unit": "ns", + "value": 205.0, + "criterion_time_estimate_ns": [ + 201.55, + 205.0, + 209.8 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/mixed_case", + "unit": "ns", + "value": 200.13, + "criterion_time_estimate_ns": [ + 199.64, + 200.13, + 200.68 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/parameterized", + "unit": "ns", + "value": 248.51, + "criterion_time_estimate_ns": [ + 247.6, + 248.51, + 249.53 + ] + } + ] + }, + { + "name": "grpc-before-3", + "command": [ + "/private/tmp/tako-grpc-perf-before", + "--bench", + "unary_sum", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "118cacd2db2d789691585e1dd4ea0ab9362afee61c1c25037f32a1a86a45489a", + "elapsed_seconds": 17.932365583998035, + "exit_code": 0, + "observations": [ + { + "case": "grpc_decode/unary_sum", + "unit": "ns", + "value": 219.65, + "criterion_time_estimate_ns": [ + 219.3, + 219.65, + 220.06 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/proto", + "unit": "ns", + "value": 239.93, + "criterion_time_estimate_ns": [ + 239.17, + 239.93, + 240.62 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/mixed_case", + "unit": "ns", + "value": 234.56, + "criterion_time_estimate_ns": [ + 233.99, + 234.56, + 235.2 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/parameterized", + "unit": "ns", + "value": 248.49, + "criterion_time_estimate_ns": [ + 247.43, + 248.49, + 249.52 + ] + } + ] + }, + { + "name": "grpc-after-4", + "command": [ + "/private/tmp/tako-grpc-perf-after", + "--bench", + "unary_sum", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "29d6cffd5791caa51b5031af566e799c2fc2487e8c08f2ddb45e80b0ce746eb1", + "elapsed_seconds": 17.945182082999963, + "exit_code": 0, + "observations": [ + { + "case": "grpc_decode/unary_sum", + "unit": "ns", + "value": 199.31, + "criterion_time_estimate_ns": [ + 198.81, + 199.31, + 199.88 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/proto", + "unit": "ns", + "value": 198.71, + "criterion_time_estimate_ns": [ + 198.41, + 198.71, + 199.01 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/mixed_case", + "unit": "ns", + "value": 198.71, + "criterion_time_estimate_ns": [ + 198.21, + 198.71, + 199.28 + ] + }, + { + "case": "grpc_decode/unary_sum_content_type/parameterized", + "unit": "ns", + "value": 248.26, + "criterion_time_estimate_ns": [ + 246.54, + 248.26, + 251.07 + ] + } + ] + }, + { + "name": "compression-before-1", + "command": [ + "/private/tmp/tako-compression-before/compression-bench", + "--bench", + "compression", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "f829908978f67db57efaacb0ac9d1eab88aa957de7b46124cfe08a6410239fa3", + "elapsed_seconds": 64.60811699999613, + "exit_code": 0, + "observations": [ + { + "case": "compression_buffered/identity/128", + "unit": "ns", + "value": 666.65, + "criterion_time_estimate_ns": [ + 645.44, + 666.65, + 695.83 + ] + }, + { + "case": "compression_buffered/gzip/128", + "unit": "ns", + "value": 696.48, + "criterion_time_estimate_ns": [ + 688.06, + 696.48, + 707.35 + ] + }, + { + "case": "compression_buffered/br/128", + "unit": "ns", + "value": 712.29, + "criterion_time_estimate_ns": [ + 692.61, + 712.29, + 736.48 + ] + }, + { + "case": "compression_buffered/deflate/128", + "unit": "ns", + "value": 709.68, + "criterion_time_estimate_ns": [ + 704.12, + 709.68, + 716.61 + ] + }, + { + "case": "compression_buffered/identity/1024", + "unit": "ns", + "value": 714.2, + "criterion_time_estimate_ns": [ + 672.51, + 714.2, + 777.46 + ] + }, + { + "case": "compression_buffered/gzip/1024", + "unit": "ns", + "value": 7081.1, + "criterion_time_estimate_ns": [ + 7039.799999999999, + 7081.1, + 7125.3 + ] + }, + { + "case": "compression_buffered/br/1024", + "unit": "ns", + "value": 12903.0, + "criterion_time_estimate_ns": [ + 12791.0, + 12903.0, + 13005.0 + ] + }, + { + "case": "compression_buffered/deflate/1024", + "unit": "ns", + "value": 6986.6, + "criterion_time_estimate_ns": [ + 6944.0, + 6986.6, + 7031.4 + ] + }, + { + "case": "compression_buffered/identity/16384", + "unit": "ns", + "value": 646.94, + "criterion_time_estimate_ns": [ + 643.02, + 646.94, + 652.25 + ] + }, + { + "case": "compression_buffered/gzip/16384", + "unit": "ns", + "value": 18438.0, + "criterion_time_estimate_ns": [ + 17999.0, + 18438.0, + 19089.0 + ] + }, + { + "case": "compression_buffered/br/16384", + "unit": "ns", + "value": 28699.0, + "criterion_time_estimate_ns": [ + 25892.0, + 28699.0, + 33485.0 + ] + }, + { + "case": "compression_buffered/deflate/16384", + "unit": "ns", + "value": 17318.0, + "criterion_time_estimate_ns": [ + 17229.0, + 17318.0, + 17432.0 + ] + }, + { + "case": "compression_negotiation/empty", + "unit": "ns", + "value": 498.05, + "criterion_time_estimate_ns": [ + 492.55, + 498.05, + 502.32 + ] + }, + { + "case": "compression_negotiation/gzip", + "unit": "ns", + "value": 536.3, + "criterion_time_estimate_ns": [ + 528.88, + 536.3, + 541.53 + ] + }, + { + "case": "compression_negotiation/browser", + "unit": "ns", + "value": 615.55, + "criterion_time_estimate_ns": [ + 611.15, + 615.55, + 620.03 + ] + }, + { + "case": "compression_negotiation/parameters", + "unit": "ns", + "value": 678.67, + "criterion_time_estimate_ns": [ + 668.84, + 678.67, + 685.93 + ] + }, + { + "case": "compression_negotiation/unknown_tokens", + "unit": "ns", + "value": 4505.7, + "criterion_time_estimate_ns": [ + 4478.1, + 4505.7, + 4530.3 + ] + }, + { + "case": "compression_mixed_requests", + "unit": "ns", + "value": 7810800.0, + "criterion_time_estimate_ns": [ + 7771500.0, + 7810800.0, + 7856300.0 + ] + } + ] + }, + { + "name": "compression-after-2", + "command": [ + "/private/tmp/tako-compression-after-bench", + "--bench", + "compression", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "b18c6eea37d0509d6c0cab28f889c5e7c676336e5d3fc3674c483a459ba2b69a", + "elapsed_seconds": 64.52253329099767, + "exit_code": 0, + "observations": [ + { + "case": "compression_buffered/identity/128", + "unit": "ns", + "value": 596.27, + "criterion_time_estimate_ns": [ + 593.15, + 596.27, + 599.38 + ] + }, + { + "case": "compression_buffered/gzip/128", + "unit": "ns", + "value": 629.61, + "criterion_time_estimate_ns": [ + 627.36, + 629.61, + 631.68 + ] + }, + { + "case": "compression_buffered/br/128", + "unit": "ns", + "value": 626.93, + "criterion_time_estimate_ns": [ + 625.71, + 626.93, + 628.11 + ] + }, + { + "case": "compression_buffered/deflate/128", + "unit": "ns", + "value": 623.1, + "criterion_time_estimate_ns": [ + 620.88, + 623.1, + 625.21 + ] + }, + { + "case": "compression_buffered/identity/1024", + "unit": "ns", + "value": 596.77, + "criterion_time_estimate_ns": [ + 595.09, + 596.77, + 598.78 + ] + }, + { + "case": "compression_buffered/gzip/1024", + "unit": "ns", + "value": 6855.2, + "criterion_time_estimate_ns": [ + 6824.6, + 6855.2, + 6889.3 + ] + }, + { + "case": "compression_buffered/br/1024", + "unit": "ns", + "value": 12457.0, + "criterion_time_estimate_ns": [ + 12407.0, + 12457.0, + 12514.0 + ] + }, + { + "case": "compression_buffered/deflate/1024", + "unit": "ns", + "value": 6690.400000000001, + "criterion_time_estimate_ns": [ + 6667.5, + 6690.400000000001, + 6709.1 + ] + }, + { + "case": "compression_buffered/identity/16384", + "unit": "ns", + "value": 594.71, + "criterion_time_estimate_ns": [ + 591.58, + 594.71, + 598.4 + ] + }, + { + "case": "compression_buffered/gzip/16384", + "unit": "ns", + "value": 17391.0, + "criterion_time_estimate_ns": [ + 17300.0, + 17391.0, + 17498.0 + ] + }, + { + "case": "compression_buffered/br/16384", + "unit": "ns", + "value": 24114.0, + "criterion_time_estimate_ns": [ + 24047.0, + 24114.0, + 24184.0 + ] + }, + { + "case": "compression_buffered/deflate/16384", + "unit": "ns", + "value": 16763.0, + "criterion_time_estimate_ns": [ + 16713.0, + 16763.0, + 16818.0 + ] + }, + { + "case": "compression_negotiation/empty", + "unit": "ns", + "value": 488.08, + "criterion_time_estimate_ns": [ + 482.2, + 488.08, + 495.23 + ] + }, + { + "case": "compression_negotiation/gzip", + "unit": "ns", + "value": 497.5, + "criterion_time_estimate_ns": [ + 491.13, + 497.5, + 502.8 + ] + }, + { + "case": "compression_negotiation/browser", + "unit": "ns", + "value": 536.04, + "criterion_time_estimate_ns": [ + 530.81, + 536.04, + 540.56 + ] + }, + { + "case": "compression_negotiation/parameters", + "unit": "ns", + "value": 587.09, + "criterion_time_estimate_ns": [ + 582.73, + 587.09, + 590.64 + ] + }, + { + "case": "compression_negotiation/unknown_tokens", + "unit": "ns", + "value": 2274.7000000000003, + "criterion_time_estimate_ns": [ + 2263.2, + 2274.7000000000003, + 2287.4 + ] + }, + { + "case": "compression_mixed_requests", + "unit": "ns", + "value": 7744200.0, + "criterion_time_estimate_ns": [ + 7679800.0, + 7744200.0, + 7823900.0 + ] + } + ] + }, + { + "name": "compression-before-3", + "command": [ + "/private/tmp/tako-compression-before/compression-bench", + "--bench", + "compression", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "f829908978f67db57efaacb0ac9d1eab88aa957de7b46124cfe08a6410239fa3", + "elapsed_seconds": 65.40353474999574, + "exit_code": 0, + "observations": [ + { + "case": "compression_buffered/identity/128", + "unit": "ns", + "value": 618.65, + "criterion_time_estimate_ns": [ + 616.24, + 618.65, + 621.48 + ] + }, + { + "case": "compression_buffered/gzip/128", + "unit": "ns", + "value": 666.81, + "criterion_time_estimate_ns": [ + 661.09, + 666.81, + 674.68 + ] + }, + { + "case": "compression_buffered/br/128", + "unit": "ns", + "value": 662.08, + "criterion_time_estimate_ns": [ + 659.98, + 662.08, + 664.11 + ] + }, + { + "case": "compression_buffered/deflate/128", + "unit": "ns", + "value": 670.06, + "criterion_time_estimate_ns": [ + 667.8, + 670.06, + 672.79 + ] + }, + { + "case": "compression_buffered/identity/1024", + "unit": "ns", + "value": 622.61, + "criterion_time_estimate_ns": [ + 619.62, + 622.61, + 625.73 + ] + }, + { + "case": "compression_buffered/gzip/1024", + "unit": "ns", + "value": 6921.700000000001, + "criterion_time_estimate_ns": [ + 6876.0, + 6921.700000000001, + 6959.900000000001 + ] + }, + { + "case": "compression_buffered/br/1024", + "unit": "ns", + "value": 12461.0, + "criterion_time_estimate_ns": [ + 12378.0, + 12461.0, + 12533.0 + ] + }, + { + "case": "compression_buffered/deflate/1024", + "unit": "ns", + "value": 6846.5, + "criterion_time_estimate_ns": [ + 6812.400000000001, + 6846.5, + 6874.0 + ] + }, + { + "case": "compression_buffered/identity/16384", + "unit": "ns", + "value": 619.54, + "criterion_time_estimate_ns": [ + 616.94, + 619.54, + 622.43 + ] + }, + { + "case": "compression_buffered/gzip/16384", + "unit": "ns", + "value": 17509.0, + "criterion_time_estimate_ns": [ + 17466.0, + 17509.0, + 17547.0 + ] + }, + { + "case": "compression_buffered/br/16384", + "unit": "ns", + "value": 24309.0, + "criterion_time_estimate_ns": [ + 24203.0, + 24309.0, + 24451.0 + ] + }, + { + "case": "compression_buffered/deflate/16384", + "unit": "ns", + "value": 17930.0, + "criterion_time_estimate_ns": [ + 17111.0, + 17930.0, + 19763.0 + ] + }, + { + "case": "compression_negotiation/empty", + "unit": "ns", + "value": 544.02, + "criterion_time_estimate_ns": [ + 511.64, + 544.02, + 592.42 + ] + }, + { + "case": "compression_negotiation/gzip", + "unit": "ns", + "value": 538.18, + "criterion_time_estimate_ns": [ + 533.88, + 538.18, + 541.58 + ] + }, + { + "case": "compression_negotiation/browser", + "unit": "ns", + "value": 607.88, + "criterion_time_estimate_ns": [ + 603.74, + 607.88, + 611.24 + ] + }, + { + "case": "compression_negotiation/parameters", + "unit": "ns", + "value": 657.59, + "criterion_time_estimate_ns": [ + 652.81, + 657.59, + 661.5 + ] + }, + { + "case": "compression_negotiation/unknown_tokens", + "unit": "ns", + "value": 4463.099999999999, + "criterion_time_estimate_ns": [ + 4435.2, + 4463.099999999999, + 4493.2 + ] + }, + { + "case": "compression_mixed_requests", + "unit": "ns", + "value": 7733200.0, + "criterion_time_estimate_ns": [ + 7713200.0, + 7733200.0, + 7756100.0 + ] + } + ] + }, + { + "name": "compression-after-4", + "command": [ + "/private/tmp/tako-compression-after-bench", + "--bench", + "compression", + "--warm-up-time", + "1", + "--measurement-time", + "2", + "--sample-size", + "30", + "--noplot" + ], + "settings": {}, + "sha256": "b18c6eea37d0509d6c0cab28f889c5e7c676336e5d3fc3674c483a459ba2b69a", + "elapsed_seconds": 63.68491829200502, + "exit_code": 0, + "observations": [ + { + "case": "compression_buffered/identity/128", + "unit": "ns", + "value": 613.7, + "criterion_time_estimate_ns": [ + 606.39, + 613.7, + 626.01 + ] + }, + { + "case": "compression_buffered/gzip/128", + "unit": "ns", + "value": 631.32, + "criterion_time_estimate_ns": [ + 628.12, + 631.32, + 634.18 + ] + }, + { + "case": "compression_buffered/br/128", + "unit": "ns", + "value": 620.46, + "criterion_time_estimate_ns": [ + 617.97, + 620.46, + 623.63 + ] + }, + { + "case": "compression_buffered/deflate/128", + "unit": "ns", + "value": 631.96, + "criterion_time_estimate_ns": [ + 629.32, + 631.96, + 635.14 + ] + }, + { + "case": "compression_buffered/identity/1024", + "unit": "ns", + "value": 607.47, + "criterion_time_estimate_ns": [ + 604.3, + 607.47, + 611.41 + ] + }, + { + "case": "compression_buffered/gzip/1024", + "unit": "ns", + "value": 6903.0, + "criterion_time_estimate_ns": [ + 6878.599999999999, + 6903.0, + 6934.1 + ] + }, + { + "case": "compression_buffered/br/1024", + "unit": "ns", + "value": 12616.0, + "criterion_time_estimate_ns": [ + 12491.0, + 12616.0, + 12718.0 + ] + }, + { + "case": "compression_buffered/deflate/1024", + "unit": "ns", + "value": 6695.400000000001, + "criterion_time_estimate_ns": [ + 6673.8, + 6695.400000000001, + 6718.7 + ] + }, + { + "case": "compression_buffered/identity/16384", + "unit": "ns", + "value": 615.83, + "criterion_time_estimate_ns": [ + 608.41, + 615.83, + 621.24 + ] + }, + { + "case": "compression_buffered/gzip/16384", + "unit": "ns", + "value": 17468.0, + "criterion_time_estimate_ns": [ + 17415.0, + 17468.0, + 17529.0 + ] + }, + { + "case": "compression_buffered/br/16384", + "unit": "ns", + "value": 24175.0, + "criterion_time_estimate_ns": [ + 24027.0, + 24175.0, + 24318.0 + ] + }, + { + "case": "compression_buffered/deflate/16384", + "unit": "ns", + "value": 17161.0, + "criterion_time_estimate_ns": [ + 17060.0, + 17161.0, + 17269.0 + ] + }, + { + "case": "compression_negotiation/empty", + "unit": "ns", + "value": 493.43, + "criterion_time_estimate_ns": [ + 487.1, + 493.43, + 499.28 + ] + }, + { + "case": "compression_negotiation/gzip", + "unit": "ns", + "value": 498.65, + "criterion_time_estimate_ns": [ + 494.92, + 498.65, + 501.7 + ] + }, + { + "case": "compression_negotiation/browser", + "unit": "ns", + "value": 552.6, + "criterion_time_estimate_ns": [ + 547.99, + 552.6, + 556.21 + ] + }, + { + "case": "compression_negotiation/parameters", + "unit": "ns", + "value": 607.89, + "criterion_time_estimate_ns": [ + 602.38, + 607.89, + 612.83 + ] + }, + { + "case": "compression_negotiation/unknown_tokens", + "unit": "ns", + "value": 2320.2, + "criterion_time_estimate_ns": [ + 2306.0, + 2320.2, + 2337.8 + ] + }, + { + "case": "compression_mixed_requests", + "unit": "ns", + "value": 7885600.0, + "criterion_time_estimate_ns": [ + 7814400.0, + 7885600.0, + 7964600.0 + ] + } + ] + } + ], + "build_commands": { + "http1": "cargo bench -p tako-rs-server --bench http1 --no-run", + "http3": "cargo bench -p tako-rs-server --features http2,http3 --bench http3 --no-run", + "grpc": "cargo bench -p tako-rs-core --features grpc --bench grpc_decode --no-run", + "compression": "cargo bench -p tako-rs-plugins --features plugins --bench compression --no-run", + "ws": "cargo test --release -p tako-rs-core --features ws --lib --no-run" + }, + "pr_integration": { + "base_commit": "e7995eb4c9c95f815b629fbbb9f62931a5c3fcf1", + "note": "The patch was rebased onto this newer main after measurement. Benchmark values and source/lockfile hashes above belong to the original measurement snapshots, not the rebased PR. No performance comparison against this newer base is claimed.", + "workspace_tests": { + "default": { + "passed": 502, + "failed": 0, + "ignored": 13 + }, + "tokio-rich": { + "passed": 870, + "failed": 0, + "ignored": 44 + }, + "all-features": { + "passed": 820, + "failed": 0, + "ignored": 43 + } + }, + "test_command": "bash scripts/check-workspace.sh test ", + "checks_passed": [ + "bash scripts/check-workspace.sh clippy default", + "bash scripts/check-workspace.sh clippy tokio-rich", + "bash scripts/check-workspace.sh clippy all-features", + "cargo clippy --workspace --all-features --benches -- -D warnings", + "cargo +nightly fmt --all -- --check", + "git diff --check" + ] + } +} diff --git a/docs/performance/http-arena-followup.md b/docs/performance/http-arena-followup.md new file mode 100644 index 00000000..500cbc9c --- /dev/null +++ b/docs/performance/http-arena-followup.md @@ -0,0 +1,257 @@ +# HTTP Arena: további protokolloptimalizálás + +Vizsgálat és helyi mérések: 2026. november 11–12. +Kiinduló commit: `28a1e2c7b9e22fac5d0c74444b5c99da17b7acd3`. +Ez az [előző vizsgálat](http-arena.md) utáni módosításokat méri. + +A PR előkészítésekor a módosításokat a `main` +`e7995eb4c9c95f815b629fbbb9f62931a5c3fcf1` commitjára vezettük át. +Az alábbi teljesítményszámok és forráshash-ek a korábbi mérési forráspárt +írják le; az új alaphoz képest külön teljesítménymérés nem történt. + +A közös HTTP-kiszolgálási útvonal, a WebSocket-küldés, a gRPC Content-Type +ellenőrzése és a tömörítési plugin kapott célzott optimalizálást. A helyi +mikromérésekben a kis gRPC-kérés feldolgozási ideje 10–15%-kal csökkent, +a kis WebSocket-üzenetek memóriabeli echo-teljesítménye 5–6%-kal nőtt. +A HTTP hálózati kontrollokból egyelőre nem igazolható egyértelmű gyorsulás. +Új hivatalos arénás vagy teljes gateway-mérés nem futott. + +## A közzétett eredmények értelmezése + +Az aréna adaptere továbbra is Tako 2.4.2-t használ; a méréskori helyi workspace +2.5.0. +Így a nyilvános számok sem az előző optimalizálásokat, sem ezt a módosítást +nem mérik. A `tuned=0` nézethez tartozó közzétett minták: + +| Profil | Kapcsolatok | Tako kérés/s, illetve WS üzenet/s | +|---|---:|---:| +| H1 baseline | 4096 | 3 282 244 | +| H1 pipelined | 4096 | 22 398 380 | +| JSON tömörítéssel | 4096 | 211 108 | +| H2 TLS | 256 | 740 669 | +| H2 cleartext | 256 | 744 038 | +| H3 baseline | 64 | 540 317 | +| gRPC unary | 256 | 578 019 | +| gRPC unary TLS | 256 | 622 537 | +| WebSocket echo | 4096 | 4 062 111 | +| WebSocket pipeline | 4096 | 6 007 904 | +| H2 gateway | 512 | 77 411 | +| H3 gateway | 64 | 83 042 | + +Források: [aktuális aréna](https://http-arena.com/#tuned=0), +[adapterfüggőségek](https://github.com/MDA2AV/HttpArena/blob/main/frameworks/tako/Cargo.toml), +[nyers Tako-eredmények](https://github.com/MDA2AV/HttpArena/blob/main/site/data/results/tako.json). +A számok eltérő munkaterheléseket jelentenek, egymással közvetlenül nem összehasonlíthatók. + +A gatewayben Caddy zárja le a H2/H3-kapcsolatokat, és HTTP/1.1-en küldi tovább +a dinamikus kéréseket. A H2 gateway 512 kapcsolatos mérésében Caddy 3155%, +Tako 853% CPU-t használt a szolgáltatásonként 32 logikai CPU-s keretből. +Ez elsősorban proxyoldali korlátra utal. A tömörítési javítás az upstream +kiszolgálásban hasznosulhat, de ebből teljes gateway-gyorsulás nem következik. +[Konfiguráció és mérési korlátok](http-arena-gateway.md), +[Caddy-konfiguráció](https://github.com/MDA2AV/HttpArena/blob/main/frameworks/tako-gateway/proxy/Caddyfile). + +## A módosítások és a megőrzött viselkedés + +- **HTTP/1 TLS, HTTP/2 és HTTP/3:** a kapcsolati metaadatok akkor kerülnek + a request extension mapbe, ha az extractor vagy a teljes middleware-pipeline + használhatja őket. A puszta handler elkerüli a felesleges bejegyzések + létrehozását; a szükséges bejegyzések újrahasználhatják a meglévő tárolót. + A compio TLS-kiszolgáló is a közös HTTP service-t használja. + A peer, TLS, ALPN, SNI, saját extensionök, HEAD és fallback viselkedését + regressziós tesztek ellenőrzik. +- **WebSocket:** az inherent `send` egy zárolás alatt ellenőrzi a küldhetőséget + és helyezi sorba az üzenetet. Sorba állítás előtti megszakításnál az új üzenet + nem kerül elküldésre; flush közbeni megszakításnál a már elfogadott frame + megmarad a sorban. Nincs duplikáció, a külön taskból küldés továbbra is flushol. + A `Sink` API és a protokoll feldolgozása változatlan. +- **gRPC:** a paraméter nélküli `application/grpc` és `application/grpc+proto` + értékeket kis- és nagybetűtől függetlenül, allokáció nélkül ellenőrizzük. + Minden más érték az eddigi MIME parserhez kerül. A paraméterek, hibás + headerek, framing, streaming és méretkorlátok viselkedése megmarad. +- **HTTP-válaszok tömörítése:** az Accept-Encoding feldolgozása kölcsönzött + szeleteket és rögzített méretű tárolót használ. Az egyetlen DATA frame-ből + álló bufferelt bodyhoz nem készül külön chunk-sor. Megmarad a szerver + codec-preferenciája, a q-értékek, wildcard és ismételt codingok kezelése, + valamint a töredezett body, trailer, pending és hibás stream viselkedése. + A tömörítési szintek és az alapértelmezett kodekek nem változtak. + +A metaadat-pooling ellenőrzése két regressziót is feltárt, amelyeket a végső +változat javít: az error handler többé nem láthat előző kérésből maradt route +paramétereket, és másik workerre kerülő kérés nem örökölhet régi body limitet. +Mindkét új teszt elbukott a javítás előtt és átment utána. + +A QUIC-tesztkliensnél egy időzítésfüggő lezárás is előjött: a szerver a teljes +válasz mellett megszakíthatja az üres kérés fogadási irányát. A teszt és a +benchmark kizárólag a `finish()` alatti `RemoteTerminate(0)` esetet tolerálja; +a státusz, válaszbody és EOF ellenőrzése megmarad. A produkciós HTTP/3 body +lezárását nem módosítottuk. A korai válasz és a kérésirány megszakításának +szabályait az [RFC 9114, 4.1. szakasza](https://www.rfc-editor.org/rfc/rfc9114.html#section-4.1), +az ismeretlen hibakódok kezelését a +[8. szakasz](https://www.rfc-editor.org/rfc/rfc9114.html#section-8) írja le. + +## Mérések + +Környezet: macOS arm64, Rust 1.99, ugyanazon gépen futó kliens és szerver. +Mérés közben nem futott párhuzamos fordítás, teszt vagy másik benchmark. +A gép nem CPU-izolált, ezért a hálózati futások szórása érdemi korlát. +A [mérési adatok](http-arena-followup.json) minden felhasznált futást, +beállítást, bináris-hasht és részidő-becslést tartalmaznak. Nem hagytunk el +kiugró mérési köröket. Egy korábbi, fordítással átfedő H2-próba nem része +az alábbi, később külön lefuttatott A/B/A/B összehasonlításnak. + +A mikromérés-binárisok a közös munkapéldányból készültek, a vizsgált komponens +régi és új forrásával, azonos harness és lockfile mellett. Nem teljes, +elkülönített repository-pillanatképek: a gRPC és WS időzített útvonalát nem +érintik a párhuzamosan készülő transportmódosítások; a két tömörítési bináris +azonos core artifactot használ. A későbbi módosítások ezeket az időzített +útvonalakat nem változtatták meg. A JSON a részletes származást is rögzíti. + +### HTTP hálózati kontrollok + +Külön négyszálas kliens- és szerver-runtime, 64 élő kapcsolat, bemelegítés, +státusz- és bodyellenőrzés. H1: kapcsolatonként 8192 kérés, öt kör/futás. +H2: 32 stream, 32 768 kérés/kapcsolat, három kör/futás. +H3: 32 stream, 8192 kérés/kapcsolat, három kör/futás. +Minden eset A/B/A/B sorrendben futott; a táblázat az összes kör mediánját adja. + +| Profil | Előtte kérés/s | Utána kérés/s | Eltérés | +|---|---:|---:|---:| +| H1 keepalive | 184 635 | 184 784 | +0,08% | +| H1 pipeline, 16 kérés | 3 013 598 | 3 026 022 | +0,41% | +| H2 cleartext | 778 450 | 784 320 | +0,75% | +| H3 | 111 983 | 116 635 | +4,15% | + +H1 és H2 lényegében változatlan. H3-nál az előtte tartomány 106 863–114 509, +az utána tartomány 109 888–124 739 kérés/s; az első pár utána futása lassabb, +a második gyorsabb volt. Emiatt a pozitív összesített eltérés még nem elég +egyértelmű gyorsulási állításhoz. A H1 harness a multithread szervert méri; +az aréna H1 adaptere per-thread szervert használ. A H3 mérése tartalmazza +a QUIC titkosítását. A TCP-s TLS-profilokat, a kapcsolatfelépítés költségét, +statikus fájlokat, adatbázist és a teljes arénás kevert terhelést nem mérjük. + +### WebSocket memóriabeli echo + +Három A/B pár, optimalizált build. A mérés a már beolvasott frame-ek +`recv` + `send` feldolgozását méri, hálózat és flush nélkül. Soronként a három +futás mediánja szerepel; a kis üzeneteknél 8 192 000, 64 bájtnál 1 024 000, +1 KiB-nál 64 000 üzenet futásonként. + +| Payload | Előtte üzenet/s | Utána üzenet/s | Eltérés | +|---|---:|---:|---:| +| 5 B | 24 223 401 | 25 451 550 | +5,07% | +| 64 B | 23 663 009 | 25 057 568 | +5,89% | +| 1 KiB | 11 055 668 | 10 870 090 | −1,68% | + +Az 1 KiB-os mérés időzített része csak néhány milliszekundum, és nem mutat +előnyt. A kisebb üzenetek eredménye sem teljes WebSocket-hálózati gyorsulás. +A mérésben nincs zárolási versengés, backpressure, fragmentáció, szöveges +üzenet vagy külön taskból küldés; ezek helyességét a tesztek ellenőrzik. + +### gRPC unary extractor + +Az aréna két egész számot összeadó kéréséhez hasonló protobuf input, +nyilvános `GrpcRequest` extractor, request-építéssel együtt. Két A/B pár, +esetenként egy másodperc bemelegítés, három másodperc mérés, 50 Criterion-minta. +A benchmark csoportbeállításai felülírják a parancssor rövidebb időzítését. +A táblázat futásonkénti Criterion-időbecslések mediánját mutatja. + +| Content-Type | Előtte ns | Utána ns | Időváltozás | +|---|---:|---:|---:| +| `application/grpc` | 222,32 | 199,40 | −10,31% | +| `application/grpc+proto` | 238,54 | 201,86 | −15,38% | +| `Application/Grpc+Proto` | 233,38 | 199,42 | −14,55% | +| `application/grpc; charset=utf-8` | 248,96 | 248,39 | −0,23% | + +Külön, thread-local számláló allocatorral a már elkészített, statikus bodyt +használó paraméter nélküli kérés extractora **1 helyett 0 allokációt** végez. +Ebben a mérésben a request elkészítése és a `BodyLimit(None)` beállítása +a számláláson kívül van. Ez a Content-Type feldolgozás további megtakarítása +az előző framing-optimalizálás után, nem a teljes hálózati gRPC-kérés költsége. + +### Tömörítés + +Két A/B pár, esetenként egy másodperc bemelegítés, két másodperc célidő és +30 Criterion-minta. A buffered és negotiation esetekben a request építése +az időzítésen kívül történik; a dispatch és a tömörítés benne van. A buffered +payloadok előre elkészített JSON-adatok. +A méretcímkékhez tartozó tényleges bodyhossz 140, 1031 és 16 394 bájt; +a legkisebb body alapbeállítással még nem tömörül. +Az 512 KiB-os mixed eset előre elkészített, nyomtatható ASCII szöveget használ; +mindkét request felépítése és a handler bodymásolása is az időzítés része. + +| Eset | Előtte µs | Utána µs | Időváltozás | +|---|---:|---:|---:| +| Negotiation: üres header, kontroll | 0,521 | 0,491 | −5,81% | +| Negotiation: gzip | 0,537 | 0,498 | −7,29% | +| Negotiation: böngészős, négy coding | 0,612 | 0,544 | −11,02% | +| Negotiation: q-paraméterek | 0,668 | 0,597 | −10,57% | +| Negotiation: 128 ismeretlen token | 4,484 | 2,297 | −48,77% | +| 140 B, identity | 0,643 | 0,605 | −5,86% | +| 140 B, gzip kérés | 0,682 | 0,630 | −7,51% | +| 140 B, Brotli kérés | 0,687 | 0,624 | −9,24% | +| 140 B, deflate kérés | 0,690 | 0,628 | −9,04% | +| 1031 B, identity | 0,668 | 0,602 | −9,92% | +| 1031 B, gzip | 7,001 | 6,879 | −1,75% | +| 1031 B, Brotli | 12,682 | 12,537 | −1,15% | +| 1031 B, deflate | 6,917 | 6,693 | −3,23% | +| 16 394 B, identity | 0,633 | 0,605 | −4,42% | +| 16 394 B, gzip | 17,974 | 17,430 | −3,03% | +| 16 394 B, Brotli | 26,504 | 24,145 | −8,90% | +| 16 394 B, deflate | 17,624 | 16,962 | −3,76% | +| 512 KiB vegyes request benchmark | 7772 | 7815 | +0,55% | + +Az üres header kontrollja is 5,8%-kal elmozdult, és az első 16 KiB-os +Brotli-futás erősen szórt. Ezért a kis időeltérések teljes egészét nem lehet +az optimalizálásnak tulajdonítani. A nagy vegyes terhelés lényegében változatlan. +Az ismeretlen tokenes eset a parser költségét emeli ki, nem tipikus HTTP-terhelés. + +Az allokációs regressziós tesztek erősebb, időzítéstől független bizonyítékot +adnak: az `identity` negotiation korábbi **2 allokáció / 136 bájt** többlete +megszűnt, és 1024 ismeretlen token sem okoz további allokációt. Az egyetlen +frame-ből álló, tömörítési küszöb alatti body vizsgálatánál a korábbi +**1 allokáció / 128 bájt** chunk-sor is megszűnt. Ezek a változatlan alap +dispatchhez képesti többletek, nem a teljes HTTP-kérés allokációszámai. + +## Ellenőrzés és újrafuttatás + +A méréskori forráson a teljes workspace tesztjei sikeresek voltak: +a bővített Tokio-konfigurációban +805 teszt átment, 16 ignored; `--all-features` mellett 779 átment, 42 ignored. +A compio HTTP/3 kliensmódosításának három integrációs tesztje külön is átment. +A csak `http3` feature-rel futtatott két érintett integrációs teszt is sikeres. +Mindkét feature-konfiguráció tests/benches Clippy ellenőrzése sikeres volt +`-D warnings` mellett. A nightly rustfmt és a `git diff --check` is sikeres. + +A méréskori Tokio feature-lista: +`ws,sse,proxy-protocol,udp,per-thread,tls,http2,http3,webtransport,plugins,signals,multipart,simd,protobuf,grpc,ip-filter,hmac-signature,json-schema,zstd,typed-header,zero-copy-extractors,jwt-simple,file-stream`. + +A friss `main`-re átvezetett PR-verzió a repository +`scripts/check-workspace.sh test` parancsával is átment mindhárom profilban: +default **502**, Tokio-rich **870**, all-features **820** sikeres teszt; +az ignored tesztek száma rendre 13, 44 és 43. Ez az integrált változat +helyességi ellenőrzése, és nem módosítja a korábbi teljesítménymérés eredményeit. +A `scripts/check-workspace.sh clippy` mindhárom profilja, az all-features +benchmarkok szigorú Clippy-ellenőrzése és a nightly rustfmt is sikeres volt. + +```sh +CONNECTIONS=64 PIPELINE=1 REQUESTS=8192 ROUNDS=5 WORKERS=4 \ + cargo bench -p tako-rs-server --bench http1 +CONNECTIONS=64 PIPELINE=16 REQUESTS=8192 ROUNDS=5 WORKERS=4 \ + cargo bench -p tako-rs-server --bench http1 +CONNECTIONS=64 STREAMS=32 REQUESTS=32768 ROUNDS=3 WORKERS=4 \ + cargo bench -p tako-rs-server --features http2,http3 --bench http2 +CONNECTIONS=64 STREAMS=32 REQUESTS=8192 ROUNDS=3 WORKERS=4 \ + cargo bench -p tako-rs-server --features http2,http3 --bench http3 +cargo test -p tako-rs-core --release --features ws --lib \ + ws::socket::benchmarks::buffered_echo_throughput -- --exact --ignored --nocapture +cargo bench -p tako-rs-core --features grpc --bench grpc_decode -- unary_sum +cargo bench -p tako-rs-plugins --features plugins --bench compression -- \ + --warm-up-time 1 --measurement-time 2 --sample-size 30 --noplot +``` + +Összehasonlításhoz azonos harness, lockfile és fordító szükséges az alapcommit +és az új forrás mellett; külön megőrzött binárisokat futtassunk felváltva. +Az arénás hatás következő érdemi ellenőrzése dedikált Linux-gépen, a friss +Tako-forrásra állított adapterrel végzett teljes protokollmérés. A gatewayt +és a proxy CPU-elosztását külön kísérletként kell mérni. diff --git a/docs/performance/http-arena.md b/docs/performance/http-arena.md index 7b05ead5..8586dcac 100644 --- a/docs/performance/http-arena.md +++ b/docs/performance/http-arena.md @@ -1,5 +1,8 @@ # HttpArena: HTTP/2, HTTP/3 és gRPC +A novemberi, további protokolloptimalizálásokat és méréseket a +[követő vizsgálat](http-arena-followup.md) dokumentálja. + Vizsgálat: 2026. október 24. Kiinduló commit: `0fb91ee6`. Az aréna közzétett adaptere Tako 2.4.2-t használ; a helyi kiindulópont 2.5.0. A rangsor ezért önmagában nem írja le a jelenlegi repository teljesítményét. diff --git a/tako-rs-core/benches/grpc_decode.rs b/tako-rs-core/benches/grpc_decode.rs index 40aa006f..60102c0b 100644 --- a/tako-rs-core/benches/grpc_decode.rs +++ b/tako-rs-core/benches/grpc_decode.rs @@ -34,10 +34,14 @@ struct SumRequest { } fn request(body: TakoBody) -> Request { + request_with_content_type(body, "application/grpc") +} + +fn request_with_content_type(body: TakoBody, content_type: &'static str) -> Request { Request::builder() .method("POST") .uri("/bench.Echo/Call") - .header("content-type", "application/grpc") + .header("content-type", content_type) .body(body) .unwrap() } @@ -66,6 +70,25 @@ fn bench_decode(c: &mut Criterion) { }); }); + for (name, content_type) in [ + ("proto", "application/grpc+proto"), + ("mixed_case", "Application/Grpc+Proto"), + ("parameterized", "application/grpc; charset=utf-8"), + ] { + group.bench_function(BenchmarkId::new("unary_sum_content_type", name), |b| { + b.iter(|| { + runtime.block_on(async { + let mut request = request_with_content_type(TakoBody::from(sum.clone()), content_type); + black_box( + GrpcRequest::::from_request(&mut request) + .await + .unwrap(), + ); + }); + }); + }); + } + for size in [32, 1024, 64 * 1024] { let message = Payload { data: Bytes::from(vec![b'x'; size]), diff --git a/tako-rs-core/src/grpc/message.rs b/tako-rs-core/src/grpc/message.rs index 25eb0675..adf420be 100644 --- a/tako-rs-core/src/grpc/message.rs +++ b/tako-rs-core/src/grpc/message.rs @@ -61,10 +61,18 @@ where } pub(crate) fn is_grpc_content_type(req: &Request) -> bool { - req - .headers() - .get(http::header::CONTENT_TYPE) - .and_then(|v| v.to_str().ok()) + let Some(value) = req.headers().get(http::header::CONTENT_TYPE) else { + return false; + }; + let bytes = value.as_bytes(); + if bytes.eq_ignore_ascii_case(b"application/grpc") + || bytes.eq_ignore_ascii_case(b"application/grpc+proto") + { + return true; + } + value + .to_str() + .ok() .and_then(|ct| ct.parse::().ok()) .is_some_and(|ct| { ct.type_() == mime::APPLICATION diff --git a/tako-rs-core/src/router/dispatch.rs b/tako-rs-core/src/router/dispatch.rs index 8f63d075..a2653f95 100644 --- a/tako-rs-core/src/router/dispatch.rs +++ b/tako-rs-core/src/router/dispatch.rs @@ -73,15 +73,6 @@ impl Router { let original = crate::router_state::OriginalUriMarker(req.uri().clone()); req.extensions_mut().insert(original); } - let request_parts = self.error_handler_with_parts.as_ref().map(|_| { - let mut saved = Request::default(); - *saved.method_mut() = req.method().clone(); - *saved.uri_mut() = req.uri().clone(); - *saved.version_mut() = req.version(); - *saved.headers_mut() = req.headers().clone(); - *saved.extensions_mut() = req.extensions().clone(); - saved.into_parts().0 - }); let is_head = req.method() == Method::HEAD; let (mut parts, body) = req.into_parts(); @@ -111,6 +102,15 @@ impl Router { }; self.set_route_entries(&mut parts.extensions, route); let req = Request::from_parts(parts, body); + let request_parts = self.error_handler_with_parts.as_ref().map(|_| { + let mut saved = Request::default(); + *saved.method_mut() = req.method().clone(); + *saved.uri_mut() = req.uri().clone(); + *saved.version_mut() = req.version(); + *saved.headers_mut() = req.headers().clone(); + *saved.extensions_mut() = req.extensions().clone(); + saved.into_parts().0 + }); #[cfg(feature = "signals")] let signals = super::request_signals::RequestSignals::new(&self.signals, route, &req); diff --git a/tako-rs-core/src/router/fast_path.rs b/tako-rs-core/src/router/fast_path.rs index 54f7aacc..8937950c 100644 --- a/tako-rs-core/src/router/fast_path.rs +++ b/tako-rs-core/src/router/fast_path.rs @@ -35,8 +35,14 @@ impl Router { /// Starts the handler at once when no middleware, timeout, guard, signal or error hook /// applies; with `peer` set, a plain route gets only the entries its extractors list. pub(crate) fn begin(&self, req: Request, peer: Option) -> Dispatch { + let info = peer.map(ConnInfo::tcp); + self.begin_with_info(req, info.as_ref()) + } + + /// Attaches transport metadata only when the handler or full pipeline can read it. + pub(crate) fn begin_with_info(&self, req: Request, info: Option<&ConnInfo>) -> Dispatch { if req.method() == Method::HEAD || !self.serves_plain_routes() { - return Dispatch::Full(with_conn(req, peer)); + return Dispatch::Full(with_info(req, info)); } let (mut parts, body) = req.into_parts(); let Some(matched) = self @@ -44,16 +50,16 @@ impl Router { .get(&parts.method) .and_then(|routes| routes.at(parts.uri.path()).ok()) else { - return Dispatch::Full(with_conn(Request::from_parts(parts, body), peer)); + return Dispatch::Full(with_info(Request::from_parts(parts, body), info)); }; let route: &Route = matched.value; if !self.is_plain(route) { - return Dispatch::Full(with_conn(Request::from_parts(parts, body), peer)); + return Dispatch::Full(with_info(Request::from_parts(parts, body), info)); } let needs = route.handler.entries(); if needs == Entries::ALL { - if let Some(peer) = peer { - attach_conn(&mut parts.extensions, peer); + if let Some(info) = info { + attach_info(&mut parts.extensions, info); } set_params(&mut parts.extensions, route, &matched.params); set_matched_path(&mut parts.extensions, route); @@ -62,7 +68,7 @@ impl Router { .extensions .get_or_insert_with(|| crate::router_state::OriginalUriMarker(parts.uri.clone())); } else if needs != Entries::NONE { - self.attach_listed(&mut parts.extensions, route, &matched.params, peer, needs); + self.attach_listed(&mut parts.extensions, route, &matched.params, info, needs); } Dispatch::Handler(route.handler.call(Request::from_parts(parts, body))) } @@ -74,19 +80,19 @@ impl Router { extensions: &mut Extensions, route: &Route, params: &matchit::Params<'_, '_>, - peer: Option, + info: Option<&ConnInfo>, needs: Entries, ) { - let recycled = peer.is_some() && extensions.is_empty(); + let recycled = info.is_some() && extensions.is_empty(); if recycled { *extensions = recycle::take_extensions(); } let mut set = Entries::NONE; let mut count = 0; - if let Some(peer) = peer.filter(|_| needs.contains(Entries::CONN)) { - set_conn(extensions, peer); + if let Some(info) = info.filter(|_| needs.contains(Entries::CONN)) { + set_info(extensions, info); set = set.union(Entries::CONN); - count += 2; + count += 1 + usize::from(info.peer.as_socket().is_some()); } if needs.contains(Entries::PARAMS) && !params.is_empty() { set_params(extensions, route, params); @@ -185,34 +191,39 @@ impl Router { } /// Adds the connection entries for a full-pipeline request. -fn with_conn(mut req: Request, peer: Option) -> Request { - if let Some(peer) = peer { - attach_conn(req.extensions_mut(), peer); +fn with_info(mut req: Request, info: Option<&ConnInfo>) -> Request { + if let Some(info) = info { + let extensions = req.extensions_mut(); + let recycled = extensions.is_empty(); + attach_info(extensions, info); + if recycled { + // The full pipeline may start on a worker that has never pooled a body limit. + extensions.remove::(); + } } req } /// Adds `ConnInfo` and the peer address, building on a recycled map unless the /// transport already attached entries, such as hyper's upgrade handle. -pub(super) fn attach_conn(extensions: &mut Extensions, peer: SocketAddr) { +pub(super) fn attach_info(extensions: &mut Extensions, info: &ConnInfo) { if extensions.is_empty() { *extensions = recycle::take_extensions(); } - set_conn(extensions, peer); + set_info(extensions, info); } -fn set_conn(extensions: &mut Extensions, peer: SocketAddr) { +fn set_info(extensions: &mut Extensions, info: &ConnInfo) { match extensions.get_mut::() { - Some(info) => *info = ConnInfo::tcp(peer), + Some(current) => *current = info.clone(), None => { - extensions.insert(ConnInfo::tcp(peer)); + extensions.insert(info.clone()); } } - match extensions.get_mut::() { - Some(addr) => *addr = peer, - None => { - extensions.insert(peer); - } + if let Some(peer) = info.peer.as_socket() { + *extensions.get_or_insert(*peer) = *peer; + } else { + extensions.remove::(); } } diff --git a/tako-rs-core/src/router/fast_path/tests.rs b/tako-rs-core/src/router/fast_path/tests.rs index f890cafc..87733357 100644 --- a/tako-rs-core/src/router/fast_path/tests.rs +++ b/tako-rs-core/src/router/fast_path/tests.rs @@ -256,7 +256,7 @@ async fn unmatched_requests_drop_recycled_route_entries() { fn connection_entries_overwrite_a_recycled_map() { pool_stale_map(); let mut extensions = Extensions::new(); - super::attach_conn(&mut extensions, peer(2)); + super::attach_info(&mut extensions, &ConnInfo::tcp(peer(2))); assert_eq!(extensions.get::(), Some(&peer(2))); assert!(matches!( extensions.get::().map(|info| &info.peer), @@ -268,7 +268,7 @@ fn connection_entries_overwrite_a_recycled_map() { fn entries_a_transport_already_added_are_kept() { let mut extensions = Extensions::new(); extensions.insert(7_u8); - super::attach_conn(&mut extensions, peer(2)); + super::attach_info(&mut extensions, &ConnInfo::tcp(peer(2))); assert_eq!(extensions.get::(), Some(&7)); assert_eq!(extensions.get::(), Some(&peer(2))); } diff --git a/tako-rs-core/src/server_support.rs b/tako-rs-core/src/server_support.rs index fb51d9c3..0bb7116c 100644 --- a/tako-rs-core/src/server_support.rs +++ b/tako-rs-core/src/server_support.rs @@ -20,6 +20,7 @@ pub use conn::tcp_service; pub use driver::ConnDriver; use futures_util::future::Either; pub use headers::sanitize_response; +pub use http::dispatch_with_info; pub use http::http_service; pub use http::http_service_with_upgrades; pub use http1_io::Http1Io; diff --git a/tako-rs-core/src/server_support/http.rs b/tako-rs-core/src/server_support/http.rs index 1cfc6ecc..760e3f29 100644 --- a/tako-rs-core/src/server_support/http.rs +++ b/tako-rs-core/src/server_support/http.rs @@ -68,15 +68,11 @@ fn service( )] fn start_request( router: Arc>, - mut req: Request, + req: Request, info: &ConnInfo, ) -> impl Future> + use<> { - if let Some(peer) = info.peer.as_socket() { - req.extensions_mut().insert(*peer); - } - req.extensions_mut().insert(info.clone()); let multiplexed = matches!(req.version(), http::Version::HTTP_2 | http::Version::HTTP_3); - let pending = match router.begin(req, None) { + let pending = match router.begin_with_info(req, Some(info)) { Dispatch::Handler(handler) => Either::Left(handler), Dispatch::Full(req) => Either::Right(Box::pin(async move { router.dispatch_full(req).await })), }; @@ -90,5 +86,14 @@ fn start_request( } } +/// Dispatches a transport request, providing connection metadata to every middleware and +/// to handlers whose extractors need it. Pre-existing request extensions are preserved. +pub async fn dispatch_with_info(router: &Router, req: Request, info: &ConnInfo) -> Response { + match router.begin_with_info(req, Some(info)) { + Dispatch::Handler(handler) => handler.await, + Dispatch::Full(req) => router.dispatch_full(req).await, + } +} + #[cfg(test)] mod tests; diff --git a/tako-rs-core/src/server_support/http/tests.rs b/tako-rs-core/src/server_support/http/tests.rs index 38e67233..76ab8f7a 100644 --- a/tako-rs-core/src/server_support/http/tests.rs +++ b/tako-rs-core/src/server_support/http/tests.rs @@ -12,7 +12,10 @@ use crate::body::TakoBody; use crate::conn_info::ConnInfo; use crate::conn_info::TlsInfo; use crate::conn_info::Transport; +use crate::extractors::Entries; +use crate::extractors::FromRequest; use crate::router::Router; +use crate::router_state::MatchedPath; use crate::server_support::connection_router; use crate::types::Request; @@ -122,3 +125,227 @@ fn pending_streams_do_not_retain_endpoint_router_references() { drop(connection); assert_eq!(Arc::strong_count(&router), 1); } + +struct WithoutConnection(bool); + +impl<'a, const MATCHED_PATH: bool> FromRequest<'a> for WithoutConnection { + type Error = std::convert::Infallible; + const ENTRIES: Entries = if MATCHED_PATH { + Entries::MATCHED_PATH + } else { + Entries::NONE + }; + + fn from_request( + req: &'a mut Request, + ) -> impl std::future::Future> + Send + 'a { + assert!(req.extensions().get::().is_none()); + assert!(req.extensions().get::().is_none()); + assert!( + req + .extensions() + .get::() + .is_none() + ); + assert_eq!( + req + .extensions() + .get::() + .map(MatchedPath::as_str), + MATCHED_PATH.then_some("/listed") + ); + std::future::ready(Ok(Self(req.extensions().get::() == Some(&42)))) + } +} + +#[tokio::test] +async fn plain_extractors_skip_unrequested_connection_metadata() { + let mut router = Router::new(); + router.get( + "/none", + |WithoutConnection(custom): WithoutConnection| async move { + if custom { "custom" } else { "ok" } + }, + ); + router.get( + "/listed", + |WithoutConnection(custom): WithoutConnection| async move { + if custom { "custom" } else { "ok" } + }, + ); + let router = Arc::new(router); + for (version, info) in [ + ( + Version::HTTP_11, + ConnInfo::h1_tls(peer(), TlsInfo::default()), + ), + (Version::HTTP_2, ConnInfo::h2c(peer())), + ( + Version::HTTP_2, + ConnInfo::h2_tls(peer(), TlsInfo::default()), + ), + (Version::HTTP_3, ConnInfo::h3(peer(), TlsInfo::default())), + ] { + for path in ["/none", "/listed"] { + let mut req = request(Method::GET, path); + *req.version_mut() = version; + req.extensions_mut().insert(42_u32); + let response = start_request(connection_router(&router), req, &info) + .await + .unwrap(); + assert_eq!(response.status(), StatusCode::OK); + assert_eq!( + response.into_body().collect().await.unwrap().to_bytes(), + "custom" + ); + let mut stale = http::Extensions::new(); + stale.insert(ConnInfo::tcp(SocketAddr::from(([127, 0, 0, 2], 54321)))); + stale.insert(SocketAddr::from(([127, 0, 0, 2], 54321))); + stale.insert(MatchedPath("/stale".into())); + stale.insert(crate::extractors::body::BodyLimit(Some(1))); + crate::recycle::recycle_extensions(stale); + let mut req = request(Method::GET, path); + *req.version_mut() = version; + let response = start_request(connection_router(&router), req, &info) + .await + .unwrap(); + assert_eq!( + response.into_body().collect().await.unwrap().to_bytes(), + "ok" + ); + } + } +} + +struct ConnectionMetadata(ConnInfo); + +impl<'a> FromRequest<'a> for ConnectionMetadata { + type Error = std::convert::Infallible; + const ENTRIES: Entries = Entries::CONN; + + fn from_request( + req: &'a mut Request, + ) -> impl std::future::Future> + Send + 'a { + let info = req.extensions().get::().unwrap(); + assert_eq!(req.extensions().get::(), info.peer.as_socket()); + std::future::ready(Ok(Self(info.clone()))) + } +} + +#[tokio::test] +async fn listed_connection_metadata_is_replaced_across_transports() { + let mut router = Router::new(); + router.get( + "/", + |ConnectionMetadata(info): ConnectionMetadata| async move { + let tls = info.tls.unwrap_or_default(); + format!( + "{:?} {:?} {} {}", + info.transport, + info.peer.as_socket(), + tls.sni.as_deref().unwrap_or("none"), + std::str::from_utf8(tls.alpn.as_deref().unwrap_or(b"none")).unwrap() + ) + }, + ); + let router = Arc::new(router); + let tls = TlsInfo { + alpn: Some(Bytes::from_static(b"h2")), + sni: Some(Arc::from("example.com")), + version: Some("TLSv1.3"), + }; + for (info, expected) in [ + ( + ConnInfo::h2_tls(peer(), tls), + "Http2 Some(127.0.0.1:12345) example.com h2", + ), + ( + ConnInfo::h2c(peer()), + "Http2 Some(127.0.0.1:12345) none none", + ), + ( + ConnInfo::h3( + peer(), + TlsInfo { + alpn: Some(Bytes::from_static(b"h3")), + ..TlsInfo::default() + }, + ), + "Http3 Some(127.0.0.1:12345) none h3", + ), + (ConnInfo::unix(None), "Unix None none none"), + ( + ConnInfo::tcp(peer()), + "Http1 Some(127.0.0.1:12345) none none", + ), + ] { + let response = super::dispatch_with_info(&router, request(Method::GET, "/"), &info).await; + assert_eq!( + response.into_body().collect().await.unwrap().to_bytes(), + expected + ); + } +} + +#[tokio::test] +async fn error_formatter_never_observes_a_previous_requests_route_entries() { + use crate::extractors::body::BodyLimit; + use crate::extractors::params::PathParams; + + let mut previous = Router::new(); + previous.get("/users/{id}", || async { "ok" }); + previous.body_limit(64); + previous.middleware(|req, next| async move { next.run(req).await }); + let mut router = Router::new(); + router.get("/error", || async { StatusCode::BAD_REQUEST }); + router.error_handler_with_parts(|parts, response| { + assert_eq!(parts.uri.path(), "/error"); + assert!(parts.extensions.get::().is_none()); + assert!(parts.extensions.get::().is_none()); + assert_eq!( + parts.extensions.get::().unwrap().as_str(), + "/error" + ); + assert_eq!(parts.extensions.get::(), Some(&peer())); + response + }); + let info = ConnInfo::h2c(peer()); + let response = + super::dispatch_with_info(&previous, request(Method::GET, "/users/secret"), &info).await; + assert_eq!(response.status(), StatusCode::OK); + let response = super::dispatch_with_info(&router, request(Method::GET, "/error"), &info).await; + assert_eq!(response.status(), StatusCode::BAD_REQUEST); +} + +#[test] +#[cfg(not(feature = "compio"))] +fn full_request_body_limits_survive_moving_to_another_worker() { + use crate::extractors::body::BodyLimit; + + let mut router = Router::new(); + router.post("/", |_: Bytes| async { StatusCode::OK }); + router.middleware(|req, next| async move { next.run(req).await }); + let router = Arc::new(router); + for (stale_limit, size, expected) in [ + (None, 2 * 1024 * 1024 + 1, StatusCode::PAYLOAD_TOO_LARGE), + (Some(1), 2, StatusCode::OK), + ] { + let mut stale = http::Extensions::new(); + stale.insert(BodyLimit(stale_limit)); + crate::recycle::recycle_extensions(stale); + let mut req = request(Method::POST, "/"); + *req.body_mut() = TakoBody::from(vec![0; size]); + let pending = start_request(connection_router(&router), req, &ConnInfo::h2c(peer())); + let status = std::thread::spawn(move || { + tokio::runtime::Builder::new_current_thread() + .build() + .unwrap() + .block_on(pending) + .unwrap() + .status() + }) + .join() + .unwrap(); + assert_eq!(status, expected, "stale_limit={stale_limit:?}"); + } +} diff --git a/tako-rs-core/src/ws/socket.rs b/tako-rs-core/src/ws/socket.rs index eb14fe27..2b116d9f 100644 --- a/tako-rs-core/src/ws/socket.rs +++ b/tako-rs-core/src/ws/socket.rs @@ -273,12 +273,14 @@ impl WebSocket { /// Queues a message. Called from a task other than the handler's, it writes at once. pub async fn send(&mut self, message: Message) -> Result<(), Error> { - poll_fn(|cx| lock(&self.shared).poll_ready_send(cx)).await?; - let write_through = { + let mut message = Some(message); + let write_through = poll_fn(|cx| { let mut core = lock(&self.shared); - core.start_send(message)?; - !core.owner.is_current() - }; + ready!(core.poll_ready_send(cx))?; + core.start_send(message.take().expect("send is polled until ready"))?; + Poll::Ready(Ok::<_, Error>(!core.owner.is_current())) + }) + .await?; if write_through { self.flush().await } else { @@ -349,3 +351,9 @@ impl Sink for WebSocket { #[cfg(test)] mod tests; + +#[cfg(test)] +mod send_tests; + +#[cfg(test)] +mod benchmarks; diff --git a/tako-rs-core/src/ws/socket/benchmarks.rs b/tako-rs-core/src/ws/socket/benchmarks.rs new file mode 100644 index 00000000..c1147d13 --- /dev/null +++ b/tako-rs-core/src/ws/socket/benchmarks.rs @@ -0,0 +1,53 @@ +use std::hint::black_box; +use std::time::Duration; +use std::time::Instant; + +use bytes::Bytes; + +use super::Config; +use super::Core; +use super::WebSocket; +use crate::ws::runtime::lock; +use crate::ws::runtime::shared; +use crate::ws::testing::BINARY; +use crate::ws::testing::client_frame; +use crate::ws::testing::upgraded_pair; + +#[cfg_attr(not(feature = "compio"), tokio::test)] +#[cfg_attr(feature = "compio", compio::test)] +#[ignore = "manual throughput measurement; run optimized and without concurrent benchmarks"] +async fn buffered_echo_throughput() { + let (upgraded, _client, _) = upgraded_pair(1 << 20).await; + let core = shared(Core::new(upgraded, Config::default())); + let mut ws = WebSocket::new(core.clone()); + crate::ws::testing::spawn(async move { + lock(&core).owner.enter(); + for (payload_len, messages) in [(5, 4096), (64, 512), (1024, 32)] { + let payload = Bytes::from(vec![7; payload_len]); + let batch = client_frame(BINARY, &payload).repeat(messages); + let mut elapsed = Duration::ZERO; + let batches = 2_000; + for _ in 0..batches { + lock(&core).read_buf.extend_from_slice(&batch); + let start = Instant::now(); + for _ in 0..messages { + let message = ws.recv().await.unwrap().unwrap(); + ws.send(black_box(message)).await.unwrap(); + } + elapsed += start.elapsed(); + let mut state = lock(&core); + black_box(&state.write_buf); + assert!(state.read_buf.is_empty()); + state.write_buf.clear(); + } + let total = messages * batches; + eprintln!( + "buffered echo payload={payload_len} messages={total} elapsed_ns={} messages_per_sec={:.0}", + elapsed.as_nanos(), + total as f64 / elapsed.as_secs_f64() + ); + } + }) + .await + .unwrap(); +} diff --git a/tako-rs-core/src/ws/socket/send_tests.rs b/tako-rs-core/src/ws/socket/send_tests.rs new file mode 100644 index 00000000..a0f43b59 --- /dev/null +++ b/tako-rs-core/src/ws/socket/send_tests.rs @@ -0,0 +1,124 @@ +use std::time::Duration; + +use bytes::Bytes; +use futures_util::FutureExt; +use tokio::io::AsyncReadExt; + +use super::Config; +use super::Core; +use super::WebSocket; +use crate::ws::Message; +use crate::ws::runtime::lock; +use crate::ws::runtime::shared; +use crate::ws::testing::timeout; +use crate::ws::testing::upgraded_pair; + +#[cfg_attr(not(feature = "compio"), tokio::test)] +#[cfg_attr(feature = "compio", compio::test)] +async fn cancelling_a_backpressured_send_does_not_enqueue_its_message() { + let (upgraded, mut client, _) = upgraded_pair(64).await; + let config = Config { + write_buffer_size: 16, + ..Config::default() + }; + let core = shared(Core::new(upgraded, config)); + let mut ws = WebSocket::new(core.clone()); + crate::ws::testing::spawn(async move { + lock(&core).owner.enter(); + ws.send(Message::Binary(Bytes::from_static(&[1; 128]))) + .await + .unwrap(); + assert!(ws.send(Message::text("cancelled")).now_or_never().is_none()); + + let mut first = [0; 132]; + let (flushed, read) = timeout(Duration::from_secs(5), async { + futures_util::join!(ws.flush(), client.read_exact(&mut first)) + }) + .await + .expect("the queued frame still flushes after cancellation"); + flushed.unwrap(); + read.unwrap(); + assert_eq!(first[..4], [0x82, 126, 0, 128]); + assert_eq!(first[4..], [1; 128]); + + ws.send(Message::text("next")).await.unwrap(); + ws.flush().await.unwrap(); + let mut next = [0; 6]; + client.read_exact(&mut next).await.unwrap(); + assert_eq!(next, [0x81, 4, b'n', b'e', b'x', b't']); + assert!(client.read_u8().now_or_never().is_none()); + }) + .await + .unwrap(); +} + +#[cfg_attr(not(feature = "compio"), tokio::test)] +#[cfg_attr(feature = "compio", compio::test)] +async fn a_backpressured_send_resumes_without_losing_or_repeating_its_message() { + let (upgraded, mut client, _) = upgraded_pair(64).await; + let config = Config { + write_buffer_size: 16, + ..Config::default() + }; + let core = shared(Core::new(upgraded, config)); + let mut ws = WebSocket::new(core.clone()); + crate::ws::testing::spawn(async move { + lock(&core).owner.enter(); + ws.send(Message::Binary(Bytes::from_static(&[2; 128]))) + .await + .unwrap(); + let writer = async { + { + let send = ws.send(Message::text("next")); + futures_util::pin_mut!(send); + assert!(send.as_mut().now_or_never().is_none()); + send.await.unwrap(); + } + ws.flush().await.unwrap(); + }; + let mut output = [0; 138]; + let ((), read) = timeout(Duration::from_secs(5), async { + futures_util::join!(writer, client.read_exact(&mut output)) + }) + .await + .expect("the pending send resumes when the peer reads"); + read.unwrap(); + assert_eq!(output[..4], [0x82, 126, 0, 128]); + assert_eq!(output[4..132], [2; 128]); + assert_eq!(output[132..], [0x81, 4, b'n', b'e', b'x', b't']); + assert!(lock(&core).write_buf.is_empty()); + assert!(client.read_u8().now_or_never().is_none()); + }) + .await + .unwrap(); +} + +#[cfg_attr(not(feature = "compio"), tokio::test)] +#[cfg_attr(feature = "compio", compio::test)] +async fn cancelling_a_write_through_send_preserves_the_accepted_frame() { + let (upgraded, mut client, _) = upgraded_pair(64).await; + let core = shared(Core::new(upgraded, Config::default())); + let mut ws = WebSocket::new(core.clone()); + assert!( + ws.send(Message::Binary(Bytes::from_static(&[3; 128]))) + .now_or_never() + .is_none() + ); + + let mut output = [0; 138]; + let (sent, read) = timeout(Duration::from_secs(5), async { + futures_util::join!( + ws.send(Message::text("next")), + client.read_exact(&mut output) + ) + }) + .await + .expect("a later send flushes the accepted frame after cancellation"); + sent.unwrap(); + read.unwrap(); + assert_eq!(output[..4], [0x82, 126, 0, 128]); + assert_eq!(output[4..132], [3; 128]); + assert_eq!(output[132..], [0x81, 4, b'n', b'e', b'x', b't']); + assert!(lock(&core).write_buf.is_empty()); + assert!(client.read_u8().now_or_never().is_none()); +} diff --git a/tako-rs-core/tests/grpc_allocations.rs b/tako-rs-core/tests/grpc_allocations.rs new file mode 100644 index 00000000..e684e83f --- /dev/null +++ b/tako-rs-core/tests/grpc_allocations.rs @@ -0,0 +1,78 @@ +#![cfg(feature = "grpc")] + +use std::alloc::GlobalAlloc; +use std::alloc::Layout; +use std::alloc::System; +use std::cell::Cell; + +use bytes::Bytes; +use futures_util::FutureExt; +use prost::Message; +use tako_rs_core::body::TakoBody; +use tako_rs_core::extractors::FromRequest; +use tako_rs_core::extractors::body::BodyLimit; +use tako_rs_core::grpc::GrpcRequest; + +struct CountingAllocator; + +thread_local! { + static ALLOCATIONS: Cell> = const { Cell::new(None) }; +} + +fn count() { + let _ = ALLOCATIONS.try_with(|cell| { + if let Some(calls) = cell.get() { + cell.set(Some(calls + 1)); + } + }); +} + +// Delegation preserves System's allocation and deallocation contracts. +unsafe impl GlobalAlloc for CountingAllocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + count(); + unsafe { System.alloc(layout) } + } + + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + unsafe { System.dealloc(ptr, layout) } + } + + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + count(); + unsafe { System.realloc(ptr, layout, new_size) } + } +} + +#[global_allocator] +static ALLOCATOR: CountingAllocator = CountingAllocator; + +#[derive(Clone, PartialEq, Message)] +struct Number { + #[prost(int32, tag = "1")] + value: i32, +} + +#[test] +fn parameter_free_unary_extraction_avoids_content_type_allocations() { + for content_type in [ + "application/grpc", + "application/grpc+proto", + "APPLICATION/GRPC", + "Application/Grpc+Proto", + ] { + let mut request = http::Request::builder() + .method("POST") + .header("content-type", content_type) + .body(TakoBody::from(Bytes::from_static(&[0, 0, 0, 0, 2, 8, 42]))) + .unwrap(); + request.extensions_mut().insert(BodyLimit(None)); + + ALLOCATIONS.set(Some(0)); + let result = GrpcRequest::::from_request(&mut request).now_or_never(); + let allocations = ALLOCATIONS.replace(None).unwrap(); + + assert_eq!(result.unwrap().unwrap().message.value, 42); + assert_eq!(allocations, 0, "{content_type}"); + } +} diff --git a/tako-rs-core/tests/grpc_unary.rs b/tako-rs-core/tests/grpc_unary.rs index 597dad3b..2b4e446a 100644 --- a/tako-rs-core/tests/grpc_unary.rs +++ b/tako-rs-core/tests/grpc_unary.rs @@ -62,9 +62,18 @@ async fn native_extractors_accept_only_protobuf_media_types() { for content_type in [ "application/grpcjunk", "application/grpc+json", + "application/grpc+protojunk", + "application/grpc+proto+proto", "application/grpc-web", "application/grpc-web+proto", "application/grpc;broken", + "application/grpc+proto;broken", + "application/grpc; charset=\"unterminated", + "application/grpc+proto; charset=\"unterminated", + "application/grpc,application/grpc", + "application/grpc ", + " application/grpc", + "text/grpc", ] { let mut req = request(vec![encoded("one")]); req @@ -92,7 +101,11 @@ async fn native_extractors_accept_only_protobuf_media_types() { for content_type in [ "application/grpc", "application/grpc+proto", + "APPLICATION/GRPC", + "Application/Grpc+Proto", + "application/grpc; charset=utf-8", "Application/Grpc+Proto; charset=utf-8", + "application/grpc; custom=\"a;b\"", ] { let mut req = request(vec![encoded("one")]); req @@ -102,6 +115,20 @@ async fn native_extractors_accept_only_protobuf_media_types() { .await .unwrap(); assert_eq!(parsed.message.value, "one", "{content_type}"); + + let mut req = request(vec![encoded("one")]); + req + .headers_mut() + .insert("content-type", content_type.parse().unwrap()); + let mut parsed = GrpcClientStream::::from_request(&mut req) + .await + .unwrap(); + assert_eq!( + parsed.next().await.unwrap().unwrap().value, + "one", + "{content_type}" + ); + assert!(parsed.next().await.is_none()); } } diff --git a/tako-rs-plugins/benches/compression.rs b/tako-rs-plugins/benches/compression.rs index 91b2008e..351b884e 100644 --- a/tako-rs-plugins/benches/compression.rs +++ b/tako-rs-plugins/benches/compression.rs @@ -1,13 +1,88 @@ use std::hint::black_box; use std::time::Instant; +use bytes::Bytes; +use criterion::BatchSize; +use criterion::BenchmarkId; use criterion::Criterion; use criterion::criterion_group; use criterion::criterion_main; +use futures_util::FutureExt; use tako_rs_core::body::TakoBody; use tako_rs_core::router::Router; use tako_rs_plugins::plugins::compression::CompressionBuilder; +fn buffered_responses(c: &mut Criterion) { + let mut group = c.benchmark_group("compression_buffered"); + for size in [128, 1024, 16 * 1024] { + let payload = Bytes::from(format!( + r#"{{"message":"{}"}}"#, + "response ".repeat(size / 9) + )); + let mut router = Router::new(); + router.plugin(CompressionBuilder::new().build()); + router.get("/", move || { + let payload = payload.clone(); + async move { + http::Response::builder() + .header("content-type", "application/json") + .body(TakoBody::from(payload)) + .unwrap() + } + }); + for encoding in ["identity", "gzip", "br", "deflate"] { + group.bench_with_input( + BenchmarkId::new(encoding, size), + &encoding, + |b, encoding| { + b.iter_batched( + || { + http::Request::builder() + .header("accept-encoding", *encoding) + .body(TakoBody::empty()) + .unwrap() + }, + |request| black_box(router.dispatch(request).now_or_never().unwrap()), + BatchSize::SmallInput, + ); + }, + ); + } + } + group.finish(); +} + +fn negotiation(c: &mut Criterion) { + let mut router = Router::new(); + router.plugin(CompressionBuilder::new().build()); + router.get("/", || async { http::StatusCode::NO_CONTENT }); + let mut group = c.benchmark_group("compression_negotiation"); + for (label, accepted) in [ + ("empty", String::new()), + ("gzip", "gzip".into()), + ("browser", "gzip, deflate, br, zstd".into()), + ( + "parameters", + "gzip;q=0.5, br;q=0, deflate;q=1, *;q=0".into(), + ), + ("unknown_tokens", "unknown, ".repeat(128)), + ] { + group.bench_function(label, |b| { + b.iter_batched( + || { + http::Request::builder() + .header("accept-encoding", accepted.as_str()) + .body(TakoBody::empty()) + .unwrap() + }, + |request| black_box(router.dispatch(request).now_or_never().unwrap()), + BatchSize::SmallInput, + ); + }); + } + group.finish(); +} + fn mixed_requests(c: &mut Criterion) { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() @@ -51,6 +126,9 @@ fn mixed_requests(c: &mut Criterion) { }); }); }); + if health_latency.is_empty() { + return; + } health_latency.sort_unstable(); println!( "health request latency: median {:?}, p95 {:?}, samples {}", @@ -60,5 +138,5 @@ fn mixed_requests(c: &mut Criterion) { ); } -criterion_group!(benches, mixed_requests); +criterion_group!(benches, buffered_responses, negotiation, mixed_requests); criterion_main!(benches); diff --git a/tako-rs-plugins/src/plugins/compression.rs b/tako-rs-plugins/src/plugins/compression.rs index 0a70c8ec..eb3ab9dc 100644 --- a/tako-rs-plugins/src/plugins/compression.rs +++ b/tako-rs-plugins/src/plugins/compression.rs @@ -41,6 +41,8 @@ //! ``` pub mod brotli_stream; +#[cfg(test)] +mod buffered_tests; mod builder; mod config; pub mod deflate_stream; @@ -49,6 +51,8 @@ mod encoding; mod frames; pub mod gzip_stream; mod negotiate; +#[cfg(test)] +mod negotiation_tests; mod plugin; #[cfg(test)] mod tests; diff --git a/tako-rs-plugins/src/plugins/compression/buffered_tests.rs b/tako-rs-plugins/src/plugins/compression/buffered_tests.rs new file mode 100644 index 00000000..8efcb599 --- /dev/null +++ b/tako-rs-plugins/src/plugins/compression/buffered_tests.rs @@ -0,0 +1,105 @@ +use std::collections::VecDeque; +use std::pin::Pin; +use std::task::Context; +use std::task::Poll; + +use bytes::Bytes; +use http::HeaderMap; +use http_body::Body; +use http_body::Frame; +use tako_rs_core::body::TakoBody; +use tako_rs_core::types::BoxError; + +use super::frames::collect_buffered; + +struct Frames(VecDeque, BoxError>>); + +impl Body for Frames { + type Data = Bytes; + type Error = BoxError; + + fn poll_frame( + mut self: Pin<&mut Self>, + _: &mut Context<'_>, + ) -> Poll, BoxError>>> { + Poll::Ready(self.0.pop_front()) + } + + fn is_end_stream(&self) -> bool { + self.0.is_empty() + } +} + +fn trailers() -> HeaderMap { + let mut headers = HeaderMap::new(); + headers.insert("x-final-state", "complete".parse().unwrap()); + headers +} + +#[tokio::test] +async fn buffered_collection_waits_for_pending_data_and_trailers() { + let mut frames = [ + Ok::<_, BoxError>(Frame::data(Bytes::from_static(b"first"))), + Ok(Frame::data(Bytes::new())), + Ok(Frame::data(Bytes::from_static(b" second"))), + Ok(Frame::trailers(trailers())), + ] + .into_iter(); + let mut should_yield = false; + let body = TakoBody::from_try_stream(futures_util::stream::poll_fn(move |cx| { + if should_yield { + should_yield = false; + cx.waker().wake_by_ref(); + return Poll::Pending; + } + let frame = frames.next(); + should_yield = frame.is_some(); + Poll::Ready(frame) + })); + let mut collected = std::pin::pin!(collect_buffered(body)); + assert!(futures_util::poll!(collected.as_mut()).is_pending()); + let (data, received_trailers) = collected.await.unwrap(); + assert_eq!(data, "first second"); + assert_eq!(received_trailers, Some(trailers())); +} + +#[tokio::test] +async fn buffered_collection_preserves_a_final_trailer_frame() { + for frames in [ + VecDeque::from([Ok(Frame::trailers(trailers()))]), + VecDeque::from([ + Ok(Frame::data(Bytes::new())), + Ok(Frame::trailers(trailers())), + ]), + ] { + let (data, received_trailers) = collect_buffered(TakoBody::new(Frames(frames))) + .await + .unwrap(); + assert!(data.is_empty()); + assert_eq!(received_trailers, Some(trailers())); + } +} + +#[tokio::test] +async fn buffered_collection_preserves_empty_bodies() { + for body in [ + TakoBody::empty(), + TakoBody::new(Frames(VecDeque::from([Ok(Frame::data(Bytes::new()))]))), + ] { + let (data, received_trailers) = collect_buffered(body).await.unwrap(); + assert!(data.is_empty()); + assert!(received_trailers.is_none()); + } +} + +#[tokio::test] +async fn buffered_collection_propagates_an_error_after_data() { + let body = TakoBody::new(Frames(VecDeque::from([ + Ok(Frame::data(Bytes::from_static(b"first"))), + Err(std::io::Error::other("source failed").into()), + ]))); + assert_eq!( + collect_buffered(body).await.unwrap_err().to_string(), + "source failed" + ); +} diff --git a/tako-rs-plugins/src/plugins/compression/frames.rs b/tako-rs-plugins/src/plugins/compression/frames.rs index 87f9b202..49c820e0 100644 --- a/tako-rs-plugins/src/plugins/compression/frames.rs +++ b/tako-rs-plugins/src/plugins/compression/frames.rs @@ -9,12 +9,56 @@ use futures_util::Stream; use http::HeaderMap; use http_body::Body; use http_body::Frame; +use http_body_util::BodyExt; use pin_project_lite::pin_project; use tako_rs_core::body::TakoBody; use tako_rs_core::types::BoxError; type Trailers = Arc>>; +pub(super) async fn collect_buffered( + mut body: TakoBody, +) -> Result<(Bytes, Option), BoxError> { + let Some(first) = body.frame().await.transpose()? else { + return Ok((Bytes::new(), None)); + }; + if body.is_end_stream() { + return Ok(match first.into_data() { + Ok(data) => (data, None), + Err(frame) => (Bytes::new(), frame.into_trailers().ok()), + }); + } + let collected = PrefixedBody { + first: Some(first), + body, + } + .collect() + .await?; + let trailers = collected.trailers().cloned(); + Ok((collected.to_bytes(), trailers)) +} + +struct PrefixedBody { + first: Option>, + body: TakoBody, +} + +impl Body for PrefixedBody { + type Data = Bytes; + type Error = BoxError; + + fn poll_frame( + mut self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll, BoxError>>> { + if let Some(first) = self.first.take() { + Poll::Ready(Some(Ok(first))) + } else { + Pin::new(&mut self.body).poll_frame(cx) + } + } +} + pub(super) fn encode(body: B, encoder: impl FnOnce(DataFrames) -> S) -> TakoBody where B: Body + Send + 'static, diff --git a/tako-rs-plugins/src/plugins/compression/negotiate.rs b/tako-rs-plugins/src/plugins/compression/negotiate.rs index 614b888e..6dc0a99e 100644 --- a/tako-rs-plugins/src/plugins/compression/negotiate.rs +++ b/tako-rs-plugins/src/plugins/compression/negotiate.rs @@ -3,62 +3,48 @@ use super::encoding::Encoding; /// RFC 9110 q-values: `q=0` rejects a coding and unlisted codings follow `*`. The server /// prefers br, gzip, deflate, then zstd. pub(crate) fn choose_encoding(header: &str, enabled: &[Encoding]) -> Option { - let parsed = parse_accept_encoding(header); - let wildcard_q = parsed.iter().find(|(c, _)| c == "*").map(|(_, q)| *q); - - let acceptable = |enc: Encoding| -> bool { - let name = enc.as_str(); - match parsed.iter().find(|(c, _)| c == name) { - Some((_, q)) => *q > 0.0, - None => wildcard_q.is_some_and(|q| q > 0.0), - } - }; - - // Server preference order — Brotli first for ratio, Gzip second for compatibility. - let server_order: [Encoding; 3] = [Encoding::Brotli, Encoding::Gzip, Encoding::Deflate]; - if let Some(enc) = server_order - .into_iter() - .find(|&enc| enabled.contains(&enc) && acceptable(enc)) - { - return Some(enc); - } - - #[cfg(feature = "zstd")] - { - if enabled.contains(&Encoding::Zstd) && acceptable(Encoding::Zstd) { - return Some(Encoding::Zstd); + const SERVER_ORDER: &[Encoding] = &[ + Encoding::Brotli, + Encoding::Gzip, + Encoding::Deflate, + #[cfg(feature = "zstd")] + Encoding::Zstd, + ]; + let mut accepted = [None; SERVER_ORDER.len()]; + let mut wildcard = None; + for (coding, allowed) in header.split(',').filter_map(parse_coding) { + if coding == "*" { + wildcard.get_or_insert(allowed); + } else if let Some(index) = SERVER_ORDER + .iter() + .position(|encoding| coding.eq_ignore_ascii_case(encoding.as_str())) + { + accepted[index].get_or_insert(allowed); } } - None + SERVER_ORDER.iter().enumerate().find_map(|(index, &enc)| { + (enabled.contains(&enc) && accepted[index].or(wildcard).unwrap_or(false)).then_some(enc) + }) } -/// Lowercased `(coding, q)` pairs. A missing q is 1.0; per RFC 9110 an entry with an +/// Borrows each coding. A missing q is 1.0; per RFC 9110 an entry with an /// unparsable q is dropped rather than defaulted to full strength. -fn parse_accept_encoding(header: &str) -> Vec<(String, f32)> { - header - .split(',') - .filter_map(|piece| { - let piece = piece.trim(); - if piece.is_empty() { - return None; - } - let mut parts = piece.split(';'); - let coding = parts.next()?.trim().to_ascii_lowercase(); - if coding.is_empty() { - return None; - } - let mut q: f32 = 1.0; - for param in parts { - let param = param.trim(); - let qv = param - .strip_prefix("q=") - .or_else(|| param.strip_prefix("Q=")); - if let Some(qv) = qv { - q = qv.parse().ok()?; - } - } - Some((coding, q)) - }) - .collect() +fn parse_coding(piece: &str) -> Option<(&str, bool)> { + let mut parts = piece.trim().split(';'); + let coding = parts.next()?.trim(); + if coding.is_empty() { + return None; + } + let mut q = 1.0_f32; + for param in parts { + let param = param.trim(); + let qv = param + .strip_prefix("q=") + .or_else(|| param.strip_prefix("Q=")); + if let Some(qv) = qv { + q = qv.parse().ok()?; + } + } + Some((coding, q > 0.0)) } diff --git a/tako-rs-plugins/src/plugins/compression/negotiation_tests.rs b/tako-rs-plugins/src/plugins/compression/negotiation_tests.rs new file mode 100644 index 00000000..88ac1d63 --- /dev/null +++ b/tako-rs-plugins/src/plugins/compression/negotiation_tests.rs @@ -0,0 +1,55 @@ +use super::Encoding; +use super::negotiate::choose_encoding; + +#[test] +fn negotiation_preserves_preferences_exclusions_and_parameters() { + let enabled = [Encoding::Deflate, Encoding::Gzip, Encoding::Brotli]; + for (header, expected) in [ + ("", None), + ("identity", None), + ("gzip", Some(Encoding::Gzip)), + ("GZip", Some(Encoding::Gzip)), + (" gzip ; Q=0.5 ", Some(Encoding::Gzip)), + ("deflate, gzip, br", Some(Encoding::Brotli)), + ("gzip;q=1, br;q=0.1", Some(Encoding::Brotli)), + ("br;q=0, gzip;q=0.5", Some(Encoding::Gzip)), + ("gzip;q=0, br;q=0, *;q=1", Some(Encoding::Deflate)), + ("gzip, *;q=0", Some(Encoding::Gzip)), + ("gzip;q=0, *;q=0", None), + ("unknown;q=1, *;q=0.5", Some(Encoding::Brotli)), + (", , ;q=1, gzip", Some(Encoding::Gzip)), + ("gzip;extension=value;q=0.5", Some(Encoding::Gzip)), + ("gzip;q=invalid", None), + ("gzip;q=invalid;q=1", None), + ("gzip;q=0;q=1", Some(Encoding::Gzip)), + ("gzip;q=1;q=0", None), + ("gzip;q=0, GZIP;q=1", None), + ("gzip;q=invalid, GZIP;q=1", Some(Encoding::Gzip)), + ("*;q=0, *;q=1", None), + ("*;q=invalid, *;q=1", Some(Encoding::Brotli)), + ] { + assert_eq!(choose_encoding(header, &enabled), expected, "{header}"); + } +} + +#[test] +fn negotiation_only_selects_enabled_codecs() { + assert_eq!(choose_encoding("*", &[]), None); + assert_eq!(choose_encoding("gzip, br", &[Encoding::Deflate]), None); + assert_eq!( + choose_encoding("gzip, *", &[Encoding::Deflate]), + Some(Encoding::Deflate) + ); +} + +#[cfg(feature = "zstd")] +#[test] +fn zstd_is_the_last_preference_and_honors_explicit_exclusion() { + let enabled = [Encoding::Zstd, Encoding::Deflate]; + assert_eq!( + choose_encoding("zstd, deflate", &enabled), + Some(Encoding::Deflate) + ); + assert_eq!(choose_encoding("ZSTD", &enabled), Some(Encoding::Zstd)); + assert_eq!(choose_encoding("zstd;q=0, *", &[Encoding::Zstd]), None); +} diff --git a/tako-rs-plugins/src/plugins/compression/plugin.rs b/tako-rs-plugins/src/plugins/compression/plugin.rs index 1c02306c..3dad1721 100644 --- a/tako-rs-plugins/src/plugins/compression/plugin.rs +++ b/tako-rs-plugins/src/plugins/compression/plugin.rs @@ -14,7 +14,6 @@ use http::header::CONTENT_TYPE; use http::header::VARY; use http_body::Body; use http_body::Frame; -use http_body_util::BodyExt; use tako_rs_core::body::TakoBody; use tako_rs_core::middleware::Next; use tako_rs_core::plugins::TakoPlugin; @@ -108,7 +107,8 @@ async fn compress_middleware(req: Request, next: Next, cfg: Arc) -> Resp return resp; }; - let collected = match resp.body_mut().collect().await { + let body = std::mem::replace(resp.body_mut(), TakoBody::empty()); + let (body_bytes, trailers) = match super::frames::collect_buffered(body).await { Ok(collected) => collected, Err(error) => { tracing::warn!(%error, "compression middleware: response body failed"); @@ -124,8 +124,6 @@ async fn compress_middleware(req: Request, next: Next, cfg: Arc) -> Resp return resp; } }; - let trailers = collected.trailers().cloned(); - let body_bytes = collected.to_bytes(); if body_bytes.len() < cfg.min_size { *resp.body_mut() = super::frames::buffered(body_bytes, trailers); return resp; diff --git a/tako-rs-plugins/tests/compression_allocations.rs b/tako-rs-plugins/tests/compression_allocations.rs new file mode 100644 index 00000000..7bb4ad21 --- /dev/null +++ b/tako-rs-plugins/tests/compression_allocations.rs @@ -0,0 +1,135 @@ +#![cfg(feature = "plugins")] + +use std::alloc::GlobalAlloc; +use std::alloc::Layout; +use std::alloc::System; +use std::cell::Cell; + +use bytes::Bytes; +use futures_util::FutureExt; +use http::header::CONTENT_ENCODING; +use http_body_util::BodyExt; +use tako_rs_core::body::TakoBody; +use tako_rs_core::router::Router; +use tako_rs_core::types::Request; +use tako_rs_plugins::plugins::compression::CompressionBuilder; + +struct CountingAllocator; + +thread_local! { + static ALLOCATIONS: Cell> = const { Cell::new(None) }; +} + +fn count(bytes: usize) { + let _ = ALLOCATIONS.try_with(|cell| { + if let Some((calls, total)) = cell.get() { + cell.set(Some((calls + 1, total + bytes))); + } + }); +} + +// Delegation preserves System's allocation and deallocation contracts. +unsafe impl GlobalAlloc for CountingAllocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + count(layout.size()); + unsafe { System.alloc(layout) } + } + + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + count(layout.size()); + unsafe { System.alloc_zeroed(layout) } + } + + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + unsafe { System.dealloc(ptr, layout) } + } + + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + count(new_size); + unsafe { System.realloc(ptr, layout, new_size) } + } +} + +#[global_allocator] +static ALLOCATOR: CountingAllocator = CountingAllocator; + +fn measure(f: impl FnOnce() -> T) -> (T, (usize, usize)) { + ALLOCATIONS.set(Some((0, 0))); + let result = f(); + let counts = ALLOCATIONS.replace(None).unwrap(); + (result, counts) +} + +fn request(accepted: &str) -> Request { + http::Request::builder() + .header("accept-encoding", accepted) + .body(TakoBody::empty()) + .unwrap() +} + +#[test] +fn negotiation_does_not_allocate_for_each_accept_encoding_token() { + let mut router = Router::new(); + router.plugin(CompressionBuilder::new().build()); + router.get("/", || async { Bytes::from_static(b"response") }); + router.dispatch(request("")).now_or_never().unwrap(); + let baseline_request = request(""); + let (_, baseline) = measure(|| router.dispatch(baseline_request).now_or_never().unwrap()); + + for accepted in ["identity".into(), "unknown, ".repeat(1024)] { + let request = request(&accepted); + let (response, actual) = measure(|| router.dispatch(request).now_or_never().unwrap()); + assert!(!response.headers().contains_key(CONTENT_ENCODING)); + assert_eq!( + response + .into_body() + .collect() + .now_or_never() + .unwrap() + .unwrap() + .to_bytes(), + "response" + ); + eprintln!( + "header bytes={}, empty header allocations={baseline:?}, actual={actual:?}", + accepted.len() + ); + assert_eq!( + actual, baseline, + "negotiation should borrow coding names instead of allocating per token" + ); + } +} + +#[test] +fn inspecting_a_buffered_body_below_min_size_does_not_allocate() { + let mut router = Router::new(); + router.plugin(CompressionBuilder::new().build()); + router.get("/", || async { + http::Response::builder() + .header("content-type", "application/json") + .body(TakoBody::from(Bytes::from_static(b"response"))) + .unwrap() + }); + router.dispatch(request("")).now_or_never().unwrap(); + let baseline_request = request(""); + let (_, baseline) = measure(|| router.dispatch(baseline_request).now_or_never().unwrap()); + let request = request("gzip"); + let (response, actual) = measure(|| router.dispatch(request).now_or_never().unwrap()); + assert!(!response.headers().contains_key(CONTENT_ENCODING)); + assert_eq!( + response + .into_body() + .collect() + .now_or_never() + .unwrap() + .unwrap() + .to_bytes(), + "response" + ); + eprintln!("identity allocations={baseline:?}, inspected body={actual:?}"); + assert_eq!( + actual, baseline, + "a single body frame does not need an allocated chunk queue" + ); +} diff --git a/tako-rs-server/Cargo.toml b/tako-rs-server/Cargo.toml index 14a6d863..226ede05 100644 --- a/tako-rs-server/Cargo.toml +++ b/tako-rs-server/Cargo.toml @@ -84,6 +84,10 @@ socket2 = { workspace = true } tako-rs = { workspace = true, features = ["sse"] } wtransport = { workspace = true, features = ["quinn"] } +[[bench]] +name = "http1" +harness = false + [[bench]] name = "http2" harness = false diff --git a/tako-rs-server/benches/http1.rs b/tako-rs-server/benches/http1.rs new file mode 100644 index 00000000..acec84d5 --- /dev/null +++ b/tako-rs-server/benches/http1.rs @@ -0,0 +1,185 @@ +//! Local HTTP/1 keepalive/pipelining control with separate client and server runtimes. +//! Uses the standard Tokio server; this is not the Arena per-thread server profile. + +#[cfg(not(feature = "compio"))] +mod tokio_benchmark { + use std::time::Duration; + use std::time::Instant; + + use bytes::Buf; + use bytes::Bytes; + use bytes::BytesMut; + use tako_rs_core::router::Router; + use tako_rs_server::Server; + use tokio::io::AsyncReadExt; + use tokio::io::AsyncWriteExt; + use tokio::net::TcpListener; + use tokio::net::TcpStream; + use tokio::sync::oneshot; + + const REQUEST: &[u8] = b"GET /baseline HTTP/1.1\r\nHost: localhost\r\n\r\n"; + + struct Client { + socket: TcpStream, + received: BytesMut, + } + + impl Client { + async fn read_more(&mut self) { + assert!(self.received.len() < 64 * 1024, "oversized response header"); + let received = tokio::time::timeout( + Duration::from_secs(30), + self.socket.read_buf(&mut self.received), + ) + .await + .expect("response read timed out") + .unwrap(); + assert!( + received > 0, + "connection closed before all responses arrived" + ); + } + + async fn receive_response(&mut self) { + let header_end = loop { + if let Some(end) = self + .received + .windows(4) + .position(|bytes| bytes == b"\r\n\r\n") + { + break end + 4; + } + self.read_more().await; + }; + let header = std::str::from_utf8(&self.received[..header_end]).unwrap(); + let mut lines = header.split("\r\n"); + let mut status = lines.next().unwrap().split_whitespace(); + assert_eq!(status.next(), Some("HTTP/1.1")); + assert_eq!(status.next(), Some("200")); + let mut content_length = None; + for line in lines.take_while(|line| !line.is_empty()) { + let (name, value) = line.split_once(':').expect("malformed response header"); + assert!( + !name.eq_ignore_ascii_case("transfer-encoding"), + "the buffered baseline response must have a content length" + ); + if name.eq_ignore_ascii_case("content-length") { + assert!(content_length.is_none(), "duplicate content-length"); + content_length = Some(value.trim().parse::().unwrap()); + } + } + assert_eq!(content_length, Some(2)); + let end = header_end + 2; + while self.received.len() < end { + self.read_more().await; + } + assert_eq!(&self.received[header_end..end], b"ok"); + self.received.advance(end); + } + } + + fn setting(name: &str, default: usize) -> usize { + std::env::var(name).map_or(default, |value| value.parse().expect("positive integer")) + } + + pub(super) fn benchmark() { + let connections = setting("CONNECTIONS", 64); + let pipeline = setting("PIPELINE", 16); + let requests = setting("REQUESTS", 8192); + let rounds = setting("ROUNDS", 5); + let workers = setting("WORKERS", 4); + assert!(connections > 0 && pipeline > 0 && requests > 0 && rounds > 0 && workers > 0); + let (address_tx, address_rx) = std::sync::mpsc::channel(); + let (stop_tx, stop_rx) = oneshot::channel(); + let server_thread = std::thread::spawn(move || { + tokio::runtime::Builder::new_multi_thread() + .worker_threads(workers) + .enable_all() + .build() + .unwrap() + .block_on(async move { + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = listener.local_addr().unwrap(); + let mut router = Router::new(); + router.get("/baseline", || async { "ok" }); + let server = Server::builder().build().spawn_http(listener, router); + address_tx.send(address).unwrap(); + stop_rx.await.unwrap(); + server.shutdown(Duration::from_secs(5)).await; + }); + }); + let address = address_rx.recv().unwrap(); + tokio::runtime::Builder::new_multi_thread() + .worker_threads(workers) + .enable_all() + .build() + .unwrap() + .block_on(async { + let mut clients = Vec::with_capacity(connections); + for _ in 0..connections { + let socket = TcpStream::connect(address).await.unwrap(); + socket.set_nodelay(true).unwrap(); + clients.push(Client { + socket, + received: BytesMut::with_capacity(16 * 1024), + }); + } + let batch = Bytes::from(REQUEST.repeat(pipeline)); + run(&mut clients, &batch, pipeline, (requests / 4).max(1)).await; + println!( + "local_http1_control connections={connections} pipeline={pipeline} \ + requests/conn={requests} workers={workers}" + ); + for round in 1..=rounds { + let start = Instant::now(); + run(&mut clients, &batch, pipeline, requests).await; + let elapsed = start.elapsed(); + let rps = (connections * requests) as f64 / elapsed.as_secs_f64(); + println!( + "round={round} rps={rps:.0} elapsed_ms={:.1}", + elapsed.as_secs_f64() * 1000.0 + ); + } + drop(clients); + }); + stop_tx.send(()).unwrap(); + server_thread.join().unwrap(); + } + + async fn run(clients: &mut Vec, batch: &Bytes, pipeline: usize, requests: usize) { + let mut tasks = tokio::task::JoinSet::new(); + for mut client in clients.drain(..) { + let batch = batch.clone(); + tasks.spawn(async move { + let mut remaining = requests; + while remaining > 0 { + let count = remaining.min(pipeline); + client + .socket + .write_all(&batch[..count * REQUEST.len()]) + .await + .unwrap(); + for _ in 0..count { + client.receive_response().await; + } + remaining -= count; + } + assert!( + client.received.is_empty(), + "unexpected extra response bytes" + ); + client + }); + } + while let Some(result) = tasks.join_next().await { + clients.push(result.unwrap()); + } + } +} + +fn main() { + #[cfg(not(feature = "compio"))] + tokio_benchmark::benchmark(); + #[cfg(feature = "compio")] + eprintln!("The HTTP/1 control uses Tokio; run without the compio feature."); +} diff --git a/tako-rs-server/benches/http3.rs b/tako-rs-server/benches/http3.rs index 5d4bb5fd..ce215067 100644 --- a/tako-rs-server/benches/http3.rs +++ b/tako-rs-server/benches/http3.rs @@ -130,7 +130,10 @@ mod tokio_benchmark { .body(()) .unwrap(); let mut stream = client.send_request(request).await.unwrap(); - stream.finish().await.unwrap(); + if let Err(error) = stream.finish().await { + // Quinn can stop an unread request before FIN; the complete response remains valid. + assert!(matches!(&error, h3::error::StreamError::RemoteTerminate { code, .. } if code.value() == 0), "{error}"); + } let response = stream.recv_response().await.unwrap(); assert_eq!(response.status(), 200); assert_eq!(response.version(), http::Version::HTTP_3); diff --git a/tako-rs-server/src/h3_common/request.rs b/tako-rs-server/src/h3_common/request.rs index 9a4aa33d..ae1b8023 100644 --- a/tako-rs-server/src/h3_common/request.rs +++ b/tako-rs-server/src/h3_common/request.rs @@ -16,6 +16,7 @@ use tako_rs_core::body::TakoBody; use tako_rs_core::conn_info::ConnInfo; use tako_rs_core::conn_info::TlsInfo; use tako_rs_core::router::Router; +use tako_rs_core::server_support::dispatch_with_info; use tako_rs_core::server_support::sanitize_response; use tako_rs_core::types::BoxError; @@ -72,30 +73,32 @@ where >::SendStream: RuntimeSend + 'static, >::RecvStream: RuntimeSend + 'static, { - // Split into send and recv halves so the handler can stream the body while we - // hold the send half locally for the response. let (mut send_stream, recv_stream) = stream.split(); let (parts, ()) = req.into_parts(); let body = build_h3_body(recv_stream); - let mut tako_req = Request::from_parts(parts, body); - annotate(&mut tako_req, remote_addr); + let tako_req = Request::from_parts(parts, body); - let response = router.dispatch(tako_req).await; + let response = dispatch_with_info(&router, tako_req, &connection_info(remote_addr)).await; respond(&mut send_stream, response).await } /// Inserts the connection details every HTTP/3 request carries. +#[cfg(feature = "webtransport")] pub(crate) fn annotate(req: &mut Request, remote_addr: SocketAddr) { req.extensions_mut().insert(remote_addr); - req.extensions_mut().insert(ConnInfo::h3( + req.extensions_mut().insert(connection_info(remote_addr)); +} + +fn connection_info(remote_addr: SocketAddr) -> ConnInfo { + ConnInfo::h3( remote_addr, TlsInfo { alpn: Some(bytes::Bytes::from_static(b"h3")), sni: None, version: Some("TLSv1.3"), }, - )); + ) } /// Sends a router response, streaming its body and trailers. diff --git a/tako-rs-server/src/server_tls_compio/accept.rs b/tako-rs-server/src/server_tls_compio/accept.rs index 45f21651..cc1e0ba5 100644 --- a/tako-rs-server/src/server_tls_compio/accept.rs +++ b/tako-rs-server/src/server_tls_compio/accept.rs @@ -1,6 +1,5 @@ //! Compio TLS accept loop: handshake, HTTP/1.1 or HTTP/2 by ALPN, graceful shutdown and draining. -use std::convert::Infallible; use std::future::Future; use std::sync::Arc; @@ -14,16 +13,14 @@ use futures_util::stream::FuturesUnordered; use hyper::server::conn::http1; #[cfg(feature = "http2")] use hyper::server::conn::http2; -use hyper::service::service_fn; use rustls::ServerConfig as RustlsServerConfig; -use tako_rs_core::body::TakoBody; use tako_rs_core::conn_info::ConnInfo; use tako_rs_core::conn_info::TlsInfo; use tako_rs_core::router::Router; use tako_rs_core::server_support::Leased; use tako_rs_core::server_support::UpgradeSupervisor; use tako_rs_core::server_support::drive_connection; -use tako_rs_core::server_support::sanitize_response; +use tako_rs_core::server_support::http_service_with_upgrades; #[cfg(feature = "signals")] use tako_rs_core::signals::transport as signal_tx; use tako_rs_core::types::BoxError; @@ -206,23 +203,7 @@ pub(crate) async fn run_supervised( let io = Leased::new(HyperStream::new_tls(tls_stream), permit); - let svc = service_fn(move |mut req| { - registry.attach(&mut req); - let r = router.clone(); - let conn_info = conn_info.clone(); - async move { - req.extensions_mut().insert(addr); - req.extensions_mut().insert(conn_info); - let multiplexed = req.version() == http::Version::HTTP_2; - let response = r.dispatch(req.map(TakoBody::new)).await; - let response = if multiplexed { - sanitize_response(response) - } else { - response - }; - Ok::<_, Infallible>(response) - } - }); + let svc = http_service_with_upgrades(router, conn_info, registry); #[cfg(feature = "http2")] if proto.as_deref() == Some(b"h2") { diff --git a/tako-rs-server/tests/h3_metadata.rs b/tako-rs-server/tests/h3_metadata.rs new file mode 100644 index 00000000..d1b4cefd --- /dev/null +++ b/tako-rs-server/tests/h3_metadata.rs @@ -0,0 +1,111 @@ +#![cfg(feature = "http3")] + +#[path = "support/h3.rs"] +mod support; + +use std::convert::Infallible; +use std::net::SocketAddr; + +use bytes::Buf; +use tako::extractors::connect_info::ConnectInfo; +use tako_rs_core::conn_info::ConnInfo; +use tako_rs_core::conn_info::Transport; +use tako_rs_core::extractors::Entries; +use tako_rs_core::extractors::FromRequest; +use tako_rs_core::router::Router; +use tako_rs_core::types::Request; + +struct NoConnection; + +impl<'a> FromRequest<'a> for NoConnection { + type Error = Infallible; + const ENTRIES: Entries = Entries::NONE; + + fn from_request( + req: &'a mut Request, + ) -> impl std::future::Future> + Send + 'a { + assert!(req.extensions().get::().is_none()); + assert!(req.extensions().get::().is_none()); + std::future::ready(Ok(Self)) + } +} + +fn assert_metadata(info: &ConnInfo) { + assert_eq!(info.transport, Transport::Http3); + assert!(info.peer.as_socket().unwrap().ip().is_loopback()); + let tls = info.tls.as_ref().unwrap(); + assert_eq!(tls.alpn.as_deref(), Some(b"h3".as_slice())); + assert_eq!(tls.version, Some("TLSv1.3")); +} + +fn assert_request(req: &Request) { + assert_eq!(req.version(), http::Version::HTTP_3); + let info = req.extensions().get::().unwrap(); + assert_metadata(info); + assert_eq!(req.extensions().get::(), info.peer.as_socket()); +} + +#[test] +fn h3_preserves_metadata_for_extractors_middleware_and_fallback() { + let mut router = Router::new(); + router.get("/plain", |_: NoConnection| async { "ok" }); + router.get( + "/typed", + |ConnectInfo(info): ConnectInfo| async move { + assert_metadata(&info); + "ok" + }, + ); + router.get("/raw", |req: Request| async move { + assert_request(&req); + "ok" + }); + router + .get("/middleware", || async { "ok" }) + .middleware(|req, next| async move { + assert_request(&req); + next.run(req).await + }); + router.fallback(|req: Request| async move { + assert_request(&req); + "ok" + }); + support::run(router, |mut client| async move { + for path in [ + "/plain", + "/typed", + "/raw", + "/middleware", + "/missing", + "/plain", + ] { + let mut stream = client + .sender + .send_request( + http::Request::builder() + .uri(format!("https://localhost{path}")) + .body(()) + .unwrap(), + ) + .await + .unwrap(); + if let Err(error) = stream.finish().await { + // Quinn can stop an unread request before FIN; the complete response remains valid. + assert!( + matches!(&error, h3::error::StreamError::RemoteTerminate { code, .. } if code.value() == 0), + "{error}" + ); + } + assert_eq!( + stream.recv_response().await.unwrap().status(), + http::StatusCode::OK + ); + let mut body = Vec::new(); + while let Some(mut chunk) = stream.recv_data().await.unwrap() { + body.extend_from_slice(&chunk.copy_to_bytes(chunk.remaining())); + } + assert_eq!(body, b"ok", "{path}"); + } + client.close().await; + }); +} diff --git a/tako-rs-server/tests/tenant_authority.rs b/tako-rs-server/tests/tenant_authority.rs index 76b3a000..60f0f498 100644 --- a/tako-rs-server/tests/tenant_authority.rs +++ b/tako-rs-server/tests/tenant_authority.rs @@ -40,7 +40,13 @@ fn h3_authority_without_host_resolves_the_tenant() { ) .await .unwrap(); - request.finish().await.unwrap(); + if let Err(error) = request.finish().await { + // Quinn can stop an unread request before FIN; the complete response remains valid. + assert!( + matches!(&error, h3::error::StreamError::RemoteTerminate { code, .. } if code.value() == 0), + "{error}" + ); + } assert_eq!(request.recv_response().await.unwrap().status(), 200); let mut data = request.recv_data().await.unwrap().unwrap(); assert_eq!(data.copy_to_bytes(data.remaining()), "acme"); diff --git a/tako-rs/tests/per_thread_startup.rs b/tako-rs/tests/per_thread_startup.rs index c577d010..1548d5de 100644 --- a/tako-rs/tests/per_thread_startup.rs +++ b/tako-rs/tests/per_thread_startup.rs @@ -11,6 +11,9 @@ use tako::plugins::TakoPlugin; use tako::router::Router; use tako::spawn_per_thread_supervised; +// Cleanup stays gated; the timeout only bounds hangs and allows for slow panic diagnostics. +const FAILURE_TIMEOUT: Duration = Duration::from_secs(5); + #[derive(Clone, Default)] struct BlockingCleanup(Arc<(Mutex, Condvar)>); @@ -72,9 +75,9 @@ async fn assert_failure_precedes_cleanup(panic: bool, kind: PerThreadErrorKind) .unwrap(); let shutdown = server.shutdown_handle(); let (ready, result, stopped) = tokio::join!( - tokio::time::timeout(Duration::from_secs(1), server.wait_ready()), - tokio::time::timeout(Duration::from_secs(1), server.result()), - tokio::time::timeout(Duration::from_secs(1), shutdown.notified()), + tokio::time::timeout(FAILURE_TIMEOUT, server.wait_ready()), + tokio::time::timeout(FAILURE_TIMEOUT, server.result()), + tokio::time::timeout(FAILURE_TIMEOUT, shutdown.notified()), ); cleanup.release(); let joined = server.join();