From 7b57a1848c5f8ff5f6823d8125bf599753e81a58 Mon Sep 17 00:00:00 2001 From: Andrew Hariri <31301117+hariria@users.noreply.github.com> Date: Sun, 22 Nov 2026 11:53:07 -0800 Subject: [PATCH 1/5] proa: subscribe to CON-1M and CON-1M-TLS --- frameworks/proa/meta.json | 2 ++ frameworks/proa/src/main.rs | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frameworks/proa/meta.json b/frameworks/proa/meta.json index 423757769..5a85893ec 100644 --- a/frameworks/proa/meta.json +++ b/frameworks/proa/meta.json @@ -21,6 +21,8 @@ "async", "latency-10k", "latency-1m", + "connections-1m", + "connections-1m-tls", "json-comp", "json-tls", "8gbit", diff --git a/frameworks/proa/src/main.rs b/frameworks/proa/src/main.rs index 0eacc224b..ece797736 100644 --- a/frameworks/proa/src/main.rs +++ b/frameworks/proa/src/main.rs @@ -274,6 +274,7 @@ fn load_tls_config() -> Option> { .ok()?; config.ignore_client_order = true; config.send_half_rtt_data = true; + config.send_tls13_tickets = 0; config.alpn_protocols = vec![b"http/1.1".to_vec()]; Some(Arc::new(config)) } @@ -322,10 +323,7 @@ async fn serve_plain(listener: TcpListener, app: Router) -> std::io::Result<()> }; let _ = stream.set_nodelay(true); let service = TowerToHyperService::new(app.clone()); - let h1 = h1.clone(); - tokio::spawn(async move { - let _ = h1.serve_connection(TokioIo::new(stream), service).await; - }); + tokio::spawn(h1.serve_connection(TokioIo::new(stream), service)); } } @@ -374,6 +372,7 @@ fn main() -> Result<(), Box> { if let (Some(tls_cfg), Some(std_tls)) = (tls_config, std_tls) { let tls_app = Router::new() + .route("/baseline11", get(baseline_get).post(baseline_post)) .route("/json/{count}", get(json_items_plain)) .route("/echo", post(echo_body)); serve_tls( From 55454c5fbf58340684992153021d5ad0453cd9c0 Mon Sep 17 00:00:00 2001 From: Andrew Hariri <31301117+hariria@users.noreply.github.com> Date: Sun, 22 Nov 2026 12:09:03 -0800 Subject: [PATCH 2/5] proa: add HTTP/2, h2c, HTTP/3, gRPC, and WebSocket profiles --- frameworks/proa/Cargo.lock | 209 +++++++++++++++++++ frameworks/proa/Cargo.toml | 7 +- frameworks/proa/Dockerfile | 2 +- frameworks/proa/README.md | 8 +- frameworks/proa/meta.json | 13 +- frameworks/proa/src/grpc.rs | 164 +++++++++++++++ frameworks/proa/src/h3_server.rs | 267 ++++++++++++++++++++++++ frameworks/proa/src/main.rs | 311 +++++++++++++++++++++++++--- frameworks/proa/src/static_files.rs | 154 ++++++++++++++ frameworks/proa/src/ws.rs | 311 ++++++++++++++++++++++++++++ 10 files changed, 1410 insertions(+), 36 deletions(-) create mode 100644 frameworks/proa/src/grpc.rs create mode 100644 frameworks/proa/src/h3_server.rs create mode 100644 frameworks/proa/src/static_files.rs create mode 100644 frameworks/proa/src/ws.rs diff --git a/frameworks/proa/Cargo.lock b/frameworks/proa/Cargo.lock index caf8ade8e..d69c748fc 100644 --- a/frameworks/proa/Cargo.lock +++ b/frameworks/proa/Cargo.lock @@ -179,6 +179,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + [[package]] name = "chacha20" version = "0.10.2" @@ -333,6 +339,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + [[package]] name = "faststr" version = "0.2.34" @@ -351,6 +363,12 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -366,6 +384,21 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.34" @@ -382,6 +415,34 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "futures-sink" version = "0.3.34" @@ -400,9 +461,13 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "slab", ] @@ -414,8 +479,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.1+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -444,6 +511,53 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "h2" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h3" +version = "0.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10872b55cfb02a821b69dc7cf8dc6a71d6af25eb9a79662bec4a9d016056b3be" +dependencies = [ + "bytes", + "fastrand", + "futures-util", + "http", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "h3-quinn" +version = "0.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2e732c8d91a74731663ac8479ab505042fbf547b9a207213ab7fbcbfc4f8b4" +dependencies = [ + "bytes", + "futures", + "h3", + "quinn", + "tokio", + "tokio-util", +] + [[package]] name = "hash32" version = "0.3.1" @@ -524,6 +638,8 @@ dependencies = [ "arrayvec", "axum", "deadpool-postgres", + "h3", + "h3-quinn", "http-body", "http-body-util", "hyper", @@ -532,6 +648,7 @@ dependencies = [ "libdeflater", "mimalloc", "proa", + "quinn", "rustls", "rustls-pemfile", "serde", @@ -572,7 +689,9 @@ checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c" dependencies = [ "atomic-waker", "bytes", + "futures-channel", "futures-core", + "h2", "http", "http-body", "httparse", @@ -807,6 +926,12 @@ version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" +[[package]] +name = "lru-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" + [[package]] name = "matchit" version = "0.8.4" @@ -1110,6 +1235,64 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "quinn" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11" +dependencies = [ + "bytes", + "cfg_aliases", + "futures-io", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e750cca55fe4f0439a15d0bb529da9651e79993e8e72c61a899a36d462befbe" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + [[package]] name = "quote" version = "1.0.47" @@ -1157,6 +1340,15 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" +[[package]] +name = "rand_pcg" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb95882a1e14462c69aea9984bb261293ccfe6022ef8de0eda18bd5afb0052df" +dependencies = [ + "rand_core", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -1264,6 +1456,12 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + [[package]] name = "rustls" version = "0.23.46" @@ -1293,6 +1491,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "102f35f7de7b06d8c61f1cff6592f5253e0dea431c74867aad5dfd70f44663fb" dependencies = [ + "web-time", "zeroize", ] @@ -1915,6 +2114,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "whoami" version = "2.1.3" diff --git a/frameworks/proa/Cargo.toml b/frameworks/proa/Cargo.toml index 7ead48ebe..f12ad893f 100644 --- a/frameworks/proa/Cargo.toml +++ b/frameworks/proa/Cargo.toml @@ -8,21 +8,24 @@ publish = false arrayvec = "0.7.8" axum = "0.8.9" deadpool-postgres = "0.14.1" +h3 = "0.0.8" +h3-quinn = "0.0.10" http-body = "1" http-body-util = "0.1" -hyper = { version = "1", features = ["http1", "server"] } +hyper = { version = "1", features = ["http1", "http2", "server"] } hyper-util = { version = "0.1", features = ["service", "tokio"] } itoa = "1.0" libdeflater = "1" mimalloc = { version = "0.1", default-features = false, features = ["v2"] } proa = { git = "https://github.com/Proa-Labs/proa.git", rev = "141a0c7d88e312269f0715130f9fceb421dfe3a5", default-features = false } +quinn = { version = "0.11", default-features = false, features = ["runtime-tokio", "rustls-aws-lc-rs"] } rustls = { version = "0.23", default-features = false, features = ["aws-lc-rs", "std"] } rustls-pemfile = "2" serde = { version = "1.0", features = ["derive"] } serde_json = "1" socket2 = { version = "0.6", features = ["all"] } sonic-rs = "0.5" -tokio = { version = "1", features = ["net", "rt", "time"] } +tokio = { version = "1", features = ["io-util", "net", "rt", "time"] } tokio-postgres = { version = "0.7", features = ["with-serde_json-1"] } tokio-rustls = { version = "0.26", default-features = false, features = ["aws-lc-rs"] } diff --git a/frameworks/proa/Dockerfile b/frameworks/proa/Dockerfile index aeaa3b88c..776fc176c 100644 --- a/frameworks/proa/Dockerfile +++ b/frameworks/proa/Dockerfile @@ -9,5 +9,5 @@ RUN cargo build --release --locked FROM debian:bookworm-slim COPY --from=build /work/target/release/httparena-proa /usr/local/bin/httparena-proa -EXPOSE 8080 8081 +EXPOSE 8080 8081 8082 8443 8443/udp ENTRYPOINT ["/usr/local/bin/httparena-proa"] diff --git a/frameworks/proa/README.md b/frameworks/proa/README.md index 4dc9d287f..9a24b5e75 100644 --- a/frameworks/proa/README.md +++ b/frameworks/proa/README.md @@ -1,5 +1,9 @@ # Proa -Proa compiles the Fortunes HTML component and serves HTTP/1.1 (with TLS 1.3 on `:8081` via `rustls`/`aws-lc-rs`) over thread-per-core Axum/Hyper workers with `mimalloc` v2, `SO_REUSEPORT`, `TCP_NODELAY`, `sonic-rs`, thread-local `libdeflater` gzip compression, and per-worker `deadpool-postgres` pools. +Proa compiles the Fortunes HTML component and serves HTTP/1.1, HTTP/2 (TLS + h2c), HTTP/3 (QUIC), gRPC, and WebSocket over thread-per-core Axum/Hyper workers with `mimalloc` v2, `SO_REUSEPORT`, `TCP_NODELAY`, `sonic-rs`, thread-local `libdeflater` gzip compression, TLS 1.3 (`TLS_AES_128_GCM_SHA256` via `aws-lc-rs`), `quinn` + `h3`, and per-worker `deadpool-postgres` pools. -On `/fortunes`, each request queries PostgreSQL, borrows row strings, appends the runtime row, sorts in byte order, and renders escaped HTML directly into one owned response buffer. The remaining HTTP/1.1 profiles exercise the same Axum/Hyper server stack (`sonic-rs` + `libdeflater` gzip on `/json/{count}`, zero-copy `/echo` over TLS, `/async-db`, `/baseline11`, `/pipeline`, and `/delay/{ms}`). +- **`:8080` TCP**: HTTP/1.1 (`/baseline11`, `/pipeline`, `/delay/{ms}`, `/json/{count}`, `/echo`, `/async-db`, `/fortunes`), WebSocket (`/ws`), and cleartext h2c gRPC (`/benchmark.BenchmarkService/GetSum`). +- **`:8081` TCP (TLS 1.3, ALPN `http/1.1`)**: `/baseline11`, `/json/{count}`, and zero-copy `/echo`. +- **`:8082` TCP (h2c)**: `/baseline2` and `/json/{count}`. +- **`:8443` TCP (TLS 1.3, ALPN `h2`)**: `/baseline2`, `/static/*` (read fresh from disk with `.br`/`.gz` precompressed selection), and TLS gRPC (`/benchmark.BenchmarkService/GetSum`). +- **`:8443` UDP (QUIC / TLS 1.3, ALPN `h3`)**: per-worker `SO_REUSEPORT` `quinn` + `h3` serving `/baseline2` and `/static/*`. diff --git a/frameworks/proa/meta.json b/frameworks/proa/meta.json index 5a85893ec..48d511af4 100644 --- a/frameworks/proa/meta.json +++ b/frameworks/proa/meta.json @@ -10,7 +10,7 @@ "request": true, "response": true }, - "description": "Compiled Proa HTML components served over thread-per-core Axum/Hyper workers with mimalloc v2, sonic-rs JSON serialization, thread-local libdeflater gzip compression, TLS 1.3 (AES-128-GCM via aws-lc-rs) on :8081, and per-worker deadpool-postgres pools.", + "description": "Compiled Proa HTML components served over thread-per-core Axum/Hyper workers with mimalloc v2, sonic-rs JSON serialization, thread-local libdeflater gzip compression, TLS 1.3 (AES-128-GCM via aws-lc-rs) for HTTP/1.1 (:8081), HTTP/2 (:8443), h2c (:8082), HTTP/3/QUIC via quinn+h3 (:8443/udp), gRPC, batched WebSocket echo, and per-worker deadpool-postgres pools.", "repo": "https://github.com/Proa-Labs/proa", "website": "https://proa.so", "enabled": true, @@ -26,6 +26,17 @@ "json-comp", "json-tls", "8gbit", + "baseline-h2", + "static-h2", + "baseline-h2c", + "json-h2c", + "baseline-h3", + "static-h3", + "unary-grpc", + "unary-grpc-tls", + "echo-ws", + "echo-ws-pipeline", + "echo-ws-limited", "async-db", "fortunes" ], diff --git a/frameworks/proa/src/grpc.rs b/frameworks/proa/src/grpc.rs new file mode 100644 index 000000000..fda492121 --- /dev/null +++ b/frameworks/proa/src/grpc.rs @@ -0,0 +1,164 @@ +use std::{ + convert::Infallible, + pin::Pin, + task::{Context, Poll}, +}; + +use axum::{ + body::{Body, Bytes}, + http::{ + HeaderMap, HeaderName, HeaderValue, StatusCode, + header::CONTENT_TYPE, + }, + response::Response, +}; +use http_body::{Body as HttpBody, Frame, SizeHint}; + +const APP_GRPC: HeaderValue = HeaderValue::from_static("application/grpc"); +const GRPC_STATUS_NAME: HeaderName = HeaderName::from_static("grpc-status"); +const GRPC_STATUS_OK: HeaderValue = HeaderValue::from_static("0"); + +struct GrpcReplyBody { + data: Option, + sent_trailers: bool, +} + +impl GrpcReplyBody { + fn new(data: Bytes) -> Self { + Self { + data: Some(data), + sent_trailers: false, + } + } +} + +impl HttpBody for GrpcReplyBody { + type Data = Bytes; + type Error = Infallible; + + fn poll_frame( + mut self: Pin<&mut Self>, + _cx: &mut Context<'_>, + ) -> Poll, Self::Error>>> { + if let Some(data) = self.data.take() { + return Poll::Ready(Some(Ok(Frame::data(data)))); + } + if !self.sent_trailers { + self.sent_trailers = true; + let mut trailers = HeaderMap::with_capacity(1); + trailers.insert(GRPC_STATUS_NAME, GRPC_STATUS_OK); + return Poll::Ready(Some(Ok(Frame::trailers(trailers)))); + } + Poll::Ready(None) + } + + fn is_end_stream(&self) -> bool { + self.data.is_none() && self.sent_trailers + } + + fn size_hint(&self) -> SizeHint { + let len = self.data.as_ref().map_or(0, Bytes::len) as u64; + SizeHint::with_exact(len) + } +} + +#[inline] +fn decode_varint(buf: &[u8], pos: &mut usize) -> Option { + let mut val = 0u64; + let mut shift = 0u32; + while *pos < buf.len() { + let byte = buf[*pos]; + *pos += 1; + val |= u64::from(byte & 0x7f) << shift; + if byte & 0x80 == 0 { + return Some(val); + } + shift += 7; + if shift >= 70 { + return None; + } + } + None +} + +#[inline] +fn decode_sum_request(payload: &[u8]) -> Option<(i32, i32)> { + let mut pos = 0usize; + let mut a = 0i32; + let mut b = 0i32; + while pos < payload.len() { + let tag = decode_varint(payload, &mut pos)?; + let field = tag >> 3; + let wire = tag & 0x07; + match (field, wire) { + (1, 0) => a = decode_varint(payload, &mut pos)? as i32, + (2, 0) => b = decode_varint(payload, &mut pos)? as i32, + (_, 0) => { + decode_varint(payload, &mut pos)?; + } + (_, 1) => { + pos = pos.checked_add(8)?; + if pos > payload.len() { + return None; + } + } + (_, 2) => { + let len = usize::try_from(decode_varint(payload, &mut pos)?).ok()?; + pos = pos.checked_add(len)?; + if pos > payload.len() { + return None; + } + } + (_, 5) => { + pos = pos.checked_add(4)?; + if pos > payload.len() { + return None; + } + } + _ => return None, + } + } + Some((a, b)) +} + +#[inline] +fn encode_sum_reply_frame(result: i32) -> Bytes { + let mut frame = [0u8; 16]; + let mut n = 5usize; + if result != 0 { + frame[n] = 0x08; // field 1, varint + n += 1; + // Proto3 int32 encodes negative values as 10-byte sign-extended two's complement u64. + let mut v = i64::from(result) as u64; + loop { + let byte = (v & 0x7f) as u8; + v >>= 7; + if v == 0 { + frame[n] = byte; + n += 1; + break; + } + frame[n] = byte | 0x80; + n += 1; + } + } + let msg_len = (n - 5) as u32; + frame[1..5].copy_from_slice(&msg_len.to_be_bytes()); + Bytes::copy_from_slice(&frame[..n]) +} + +pub async fn get_sum(body: Bytes) -> Result { + if body.len() < 5 || body[0] != 0 { + return Err(StatusCode::BAD_REQUEST); + } + let msg_len = u32::from_be_bytes([body[1], body[2], body[3], body[4]]) as usize; + let payload = body.get(5..5 + msg_len).ok_or(StatusCode::BAD_REQUEST)?; + let (a, b) = decode_sum_request(payload).ok_or(StatusCode::BAD_REQUEST)?; + let reply = encode_sum_reply_frame(a.wrapping_add(b)); + + Response::builder() + .status(StatusCode::OK) + .header(CONTENT_TYPE, APP_GRPC) + .body(Body::new(GrpcReplyBody::new(reply))) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) +} diff --git a/frameworks/proa/src/h3_server.rs b/frameworks/proa/src/h3_server.rs new file mode 100644 index 000000000..2dbd349e0 --- /dev/null +++ b/frameworks/proa/src/h3_server.rs @@ -0,0 +1,267 @@ +use std::{net::SocketAddr, sync::Arc}; + +use axum::{ + body::Bytes, + http::{ + HeaderValue, Response, StatusCode, + header::{ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_TYPE, VARY}, + }, +}; +use quinn::{ + Endpoint, EndpointConfig, ServerConfig as QuinnServerConfig, TransportConfig, + crypto::rustls::QuicServerConfig, +}; +use rustls::ServerConfig; +use socket2::{Domain, Protocol, Socket, Type}; + +use crate::{baseline_get_bytes, static_files::read_static}; + +const TEXT_PLAIN: HeaderValue = HeaderValue::from_static("text/plain"); +const VARY_AE: HeaderValue = HeaderValue::from_static("Accept-Encoding"); + +pub fn build_quinn_config(tls: Arc) -> Option { + let quic_crypto = QuicServerConfig::try_from(tls).ok()?; + let mut server_config = QuinnServerConfig::with_crypto(Arc::new(quic_crypto)); + let mut transport = TransportConfig::default(); + transport.max_concurrent_bidi_streams(256u32.into()); + transport.max_concurrent_uni_streams(32u32.into()); + transport.send_window(8 * 1024 * 1024); + transport.receive_window((16 * 1024 * 1024u32).into()); + transport.stream_receive_window((2 * 1024 * 1024u32).into()); + transport.datagram_receive_buffer_size(None); + server_config.transport_config(Arc::new(transport)); + Some(server_config) +} + +pub fn reuseport_udp(addr: SocketAddr) -> std::io::Result { + let sock = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?; + sock.set_reuse_address(true)?; + #[cfg(unix)] + sock.set_reuse_port(true)?; + let _ = sock.set_recv_buffer_size(4 * 1024 * 1024); + let _ = sock.set_send_buffer_size(4 * 1024 * 1024); + sock.set_nonblocking(true)?; + sock.bind(&addr.into())?; + Ok(sock.into()) +} + +pub fn spawn_h3_worker( + std_udp: std::net::UdpSocket, + server_config: QuinnServerConfig, +) -> std::io::Result<()> { + let endpoint = Endpoint::new( + EndpointConfig::default(), + Some(server_config), + std_udp, + Arc::new(quinn::TokioRuntime), + )?; + + tokio::spawn(async move { + while let Some(incoming) = endpoint.accept().await { + tokio::spawn(async move { + let Ok(conn) = incoming.await else { + return; + }; + let Ok(mut h3_conn) = + h3::server::Connection::<_, Bytes>::new(h3_quinn::Connection::new(conn)).await + else { + return; + }; + while let Ok(Some(resolver)) = h3_conn.accept().await { + tokio::spawn(async move { + let Ok((req, mut stream)) = resolver.resolve_request().await else { + return; + }; + let path = req.uri().path(); + let (resp, body) = if path == "/baseline2" { + match baseline_get_bytes(req.uri()) { + Ok(bytes) => { + let resp = Response::builder() + .status(StatusCode::OK) + .header(CONTENT_TYPE, TEXT_PLAIN) + .body(()) + .unwrap(); + (resp, bytes) + } + Err(status) => ( + Response::builder().status(status).body(()).unwrap(), + Bytes::new(), + ), + } + } else if let Some(rel) = path.strip_prefix("/static/") { + let ae = req + .headers() + .get(ACCEPT_ENCODING) + .and_then(|v| v.to_str().ok()); + match read_static(rel, ae) { + Some(file) => { + let mut builder = Response::builder() + .status(StatusCode::OK) + .header(CONTENT_TYPE, file.content_type); + if let Some(enc) = file.content_encoding { + builder = builder + .header(CONTENT_ENCODING, enc) + .header(VARY, VARY_AE); + } + (builder.body(()).unwrap(), file.body) + } + None => ( + Response::builder() + .status(StatusCode::NOT_FOUND) + .body(()) + .unwrap(), + Bytes::new(), + ), + } + } else { + ( + Response::builder() + .status(StatusCode::NOT_FOUND) + .body(()) + .unwrap(), + Bytes::new(), + ) + }; + + if stream.send_response(resp).await.is_err() { + return; + } + if !body.is_empty() && stream.send_data(body).await.is_err() { + return; + } + let _ = stream.finish().await; + }); + } + }); + } + }); + + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use hyper::body::Buf; + use rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}; + use rustls::pki_types::{CertificateDer, ServerName, UnixTime}; + use rustls::{ClientConfig, DigitallySignedStruct, Error as TlsError, SignatureScheme}; + + #[derive(Debug)] + struct AcceptAnyCert; + + impl ServerCertVerifier for AcceptAnyCert { + fn verify_server_cert( + &self, + _end_entity: &CertificateDer<'_>, + _intermediates: &[CertificateDer<'_>], + _server_name: &ServerName<'_>, + _ocsp: &[u8], + _now: UnixTime, + ) -> Result { + Ok(ServerCertVerified::assertion()) + } + + fn verify_tls12_signature( + &self, + _message: &[u8], + _cert: &CertificateDer<'_>, + _dss: &DigitallySignedStruct, + ) -> Result { + Ok(HandshakeSignatureValid::assertion()) + } + + fn verify_tls13_signature( + &self, + _message: &[u8], + _cert: &CertificateDer<'_>, + _dss: &DigitallySignedStruct, + ) -> Result { + Ok(HandshakeSignatureValid::assertion()) + } + + fn supported_verify_schemes(&self) -> Vec { + rustls::crypto::aws_lc_rs::default_provider() + .signature_verification_algorithms + .supported_schemes() + } + } + + #[test] + fn h3_serves_baseline2_over_quic() { + let cert_path = std::env::var("TLS_CERT").unwrap_or_default(); + if cert_path.is_empty() { + return; + } + let rt = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + rt.block_on(async { + let bundle = crate::load_tls_bundle().expect("tls bundle"); + let q_cfg = bundle.h3.expect("quinn config"); + let std_udp = reuseport_udp("127.0.0.1:0".parse().unwrap()).unwrap(); + let addr = std_udp.local_addr().unwrap(); + spawn_h3_worker(std_udp, q_cfg).unwrap(); + + let mut tls_client = ClientConfig::builder_with_provider(Arc::new( + rustls::crypto::aws_lc_rs::default_provider(), + )) + .with_protocol_versions(&[&rustls::version::TLS13]) + .unwrap() + .dangerous() + .with_custom_certificate_verifier(Arc::new(AcceptAnyCert)) + .with_no_client_auth(); + tls_client.alpn_protocols = vec![b"h3".to_vec()]; + let client_cfg = quinn::ClientConfig::new(Arc::new( + quinn::crypto::rustls::QuicClientConfig::try_from(tls_client).unwrap(), + )); + let mut client = Endpoint::client("127.0.0.1:0".parse().unwrap()).unwrap(); + client.set_default_client_config(client_cfg); + let conn = client.connect(addr, "localhost").unwrap().await.unwrap(); + let (mut driver, mut send_req) = + h3::client::new(h3_quinn::Connection::new(conn)).await.unwrap(); + let driver_task = tokio::spawn(async move { + let _ = std::future::poll_fn(|cx| driver.poll_close(cx)).await; + }); + + // 1. GET /baseline2?a=13&b=42 + let req = axum::http::Request::builder() + .uri("https://localhost/baseline2?a=13&b=42") + .body(()) + .unwrap(); + let mut stream = send_req.send_request(req).await.unwrap(); + stream.finish().await.unwrap(); + let resp = stream.recv_response().await.unwrap(); + assert_eq!(resp.status(), StatusCode::OK); + assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "text/plain"); + let mut body = Vec::new(); + while let Some(chunk) = stream.recv_data().await.unwrap() { + body.extend_from_slice(chunk.chunk()); + } + assert_eq!(body, b"55"); + + // 2. GET /static/reset.css (with br) and 404 + if std::env::var("STATIC_DIR").is_ok() { + let req = axum::http::Request::builder() + .uri("https://localhost/static/reset.css") + .header(ACCEPT_ENCODING, "br;q=1, gzip;q=0.8") + .body(()) + .unwrap(); + let mut stream = send_req.send_request(req).await.unwrap(); + stream.finish().await.unwrap(); + let resp = stream.recv_response().await.unwrap(); + assert_eq!(resp.status(), StatusCode::OK); + assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "text/css"); + assert_eq!(resp.headers().get(CONTENT_ENCODING).unwrap(), "br"); + let mut body = Vec::new(); + while let Some(chunk) = stream.recv_data().await.unwrap() { + body.extend_from_slice(chunk.chunk()); + } + assert_eq!(body, b"FAKE_BR_BYTES"); + } + + driver_task.abort(); + }); + } +} diff --git a/frameworks/proa/src/main.rs b/frameworks/proa/src/main.rs index ece797736..2e0ff5272 100644 --- a/frameworks/proa/src/main.rs +++ b/frameworks/proa/src/main.rs @@ -1,11 +1,15 @@ mod fortunes; +mod grpc; +mod h3_server; +mod static_files; +mod ws; use std::{ cell::RefCell, convert::Infallible, env, fs::File, - io::BufReader, + io::{self, BufReader}, net::SocketAddr, pin::Pin, sync::{Arc, LazyLock}, @@ -31,14 +35,21 @@ use deadpool_postgres::{ }; use http_body::{Body as HttpBody, Frame, SizeHint}; use http_body_util::BodyExt as _; -use hyper::server::conn::http1; -use hyper_util::{rt::TokioIo, service::TowerToHyperService}; +use hyper::server::conn::{http1, http2}; +use hyper_util::{ + rt::{TokioExecutor, TokioIo}, + service::TowerToHyperService, +}; use libdeflater::{CompressionLvl, Compressor}; use proa::{WebContext, WebRenderSync}; use rustls::ServerConfig; use serde::{Deserialize, Serialize}; use socket2::{Domain, Protocol, Socket, Type}; -use tokio::{net::TcpListener, time::sleep}; +use tokio::{ + io::{AsyncRead, AsyncReadExt, AsyncWrite, ReadBuf}, + net::{TcpListener, TcpStream}, + time::sleep, +}; use tokio_rustls::TlsAcceptor; use crate::fortunes::{Fortune, Fortunes}; @@ -248,16 +259,19 @@ impl HttpBody for EchoBody { } } -fn load_tls_config() -> Option> { - let cert_path = env::var("TLS_CERT").unwrap_or_else(|_| "/certs/server.crt".to_string()); - let key_path = env::var("TLS_KEY").unwrap_or_else(|_| "/certs/server.key".to_string()); - let cert_file = File::open(cert_path).ok()?; - let key_file = File::open(key_path).ok()?; - let certs: Vec<_> = rustls_pemfile::certs(&mut BufReader::new(cert_file)) - .collect::>() - .ok()?; - let key = rustls_pemfile::private_key(&mut BufReader::new(key_file)).ok()??; +const H2_PREFACE: &[u8; 4] = b"PRI "; +struct TlsBundle { + h1: Arc, + h2: Arc, + h3: Option, +} + +fn build_tls_config( + certs: Vec>, + key: rustls::pki_types::PrivateKeyDer<'static>, + alpn: &[&[u8]], +) -> Option> { // Prefer TLS_AES_128_GCM_SHA256 over AES-256-GCM for faster bulk AES-NI throughput // while enforcing TLS 1.3 AEAD-only posture. let mut provider = rustls::crypto::aws_lc_rs::default_provider(); @@ -275,11 +289,28 @@ fn load_tls_config() -> Option> { config.ignore_client_order = true; config.send_half_rtt_data = true; config.send_tls13_tickets = 0; - config.alpn_protocols = vec![b"http/1.1".to_vec()]; + config.alpn_protocols = alpn.iter().map(|p| p.to_vec()).collect(); Some(Arc::new(config)) } -fn reuseport_listener(addr: SocketAddr) -> std::io::Result { +fn load_tls_bundle() -> Option { + let cert_path = env::var("TLS_CERT").unwrap_or_else(|_| "/certs/server.crt".to_string()); + let key_path = env::var("TLS_KEY").unwrap_or_else(|_| "/certs/server.key".to_string()); + let cert_file = File::open(cert_path).ok()?; + let key_file = File::open(key_path).ok()?; + let certs: Vec<_> = rustls_pemfile::certs(&mut BufReader::new(cert_file)) + .collect::>() + .ok()?; + let key = rustls_pemfile::private_key(&mut BufReader::new(key_file)).ok()??; + + let h1 = build_tls_config(certs.clone(), key.clone_key(), &[b"http/1.1"])?; + let h2 = build_tls_config(certs.clone(), key.clone_key(), &[b"h2"])?; + let h3_tls = build_tls_config(certs, key, &[b"h3"])?; + let h3 = h3_server::build_quinn_config(h3_tls); + Some(TlsBundle { h1, h2, h3 }) +} + +fn reuseport_listener(addr: SocketAddr) -> io::Result { let sock = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP))?; sock.set_reuse_address(true)?; #[cfg(unix)] @@ -290,7 +321,109 @@ fn reuseport_listener(addr: SocketAddr) -> std::io::Result http2::Builder { + let mut h2 = http2::Builder::new(TokioExecutor::new()); + h2.max_concurrent_streams(256) + .initial_stream_window_size(1024 * 1024) + .initial_connection_window_size(4 * 1024 * 1024) + .max_frame_size(65535) + .adaptive_window(false); + h2 +} + +struct PrefixedStream { + prefix: [u8; 4], + pos: usize, + len: usize, + inner: TcpStream, +} + +impl AsyncRead for PrefixedStream { + fn poll_read( + mut self: Pin<&mut Self>, + cx: &mut Context<'_>, + buf: &mut ReadBuf<'_>, + ) -> Poll> { + if self.pos < self.len { + let rem = self.len - self.pos; + let take = rem.min(buf.remaining()); + buf.put_slice(&self.prefix[self.pos..self.pos + take]); + self.pos += take; + return Poll::Ready(Ok(())); + } + Pin::new(&mut self.inner).poll_read(cx, buf) + } +} + +impl AsyncWrite for PrefixedStream { + fn poll_write( + mut self: Pin<&mut Self>, + cx: &mut Context<'_>, + buf: &[u8], + ) -> Poll> { + Pin::new(&mut self.inner).poll_write(cx, buf) + } + + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + Pin::new(&mut self.inner).poll_flush(cx) + } + + fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + Pin::new(&mut self.inner).poll_shutdown(cx) + } + + fn poll_write_vectored( + mut self: Pin<&mut Self>, + cx: &mut Context<'_>, + bufs: &[io::IoSlice<'_>], + ) -> Poll> { + Pin::new(&mut self.inner).poll_write_vectored(cx, bufs) + } + + fn is_write_vectored(&self) -> bool { + self.inner.is_write_vectored() + } +} + +async fn serve_ambiguous_prefix( + mut stream: TcpStream, + h1: http1::Builder, + h2: http2::Builder, + h1_app: Router, + grpc_app: Router, +) { + let mut prefix = [0u8; 4]; + let mut len = 0usize; + while len < 4 { + match stream.read(&mut prefix[len..4]).await { + Ok(0) | Err(_) => return, + Ok(n) => { + len += n; + if prefix[..len] != H2_PREFACE[..len] { + break; + } + } + } + } + let io = TokioIo::new(PrefixedStream { + prefix, + pos: 0, + len, + inner: stream, + }); + if len == 4 && &prefix == H2_PREFACE { + let _ = h2 + .serve_connection(io, TowerToHyperService::new(grpc_app)) + .await; + } else { + let _ = h1 + .serve_connection(io, TowerToHyperService::new(h1_app)) + .with_upgrades() + .await; + } +} + +fn serve_tls_h1(listener: TcpListener, acceptor: TlsAcceptor, app: Router) { tokio::spawn(async move { let mut h1 = http1::Builder::new(); h1.keep_alive(true).pipeline_flush(true); @@ -314,16 +447,83 @@ fn serve_tls(listener: TcpListener, acceptor: TlsAcceptor, app: Router) { }); } -async fn serve_plain(listener: TcpListener, app: Router) -> std::io::Result<()> { +fn serve_h2c(listener: TcpListener, app: Router) { + tokio::spawn(async move { + let h2 = build_h2(); + loop { + let Ok((stream, _)) = listener.accept().await else { + continue; + }; + let _ = stream.set_nodelay(true); + let service = TowerToHyperService::new(app.clone()); + tokio::spawn(h2.serve_connection(TokioIo::new(stream), service)); + } + }); +} + +fn serve_tls_h2(listener: TcpListener, acceptor: TlsAcceptor, app: Router) { + tokio::spawn(async move { + let h2 = build_h2(); + loop { + let Ok((stream, _)) = listener.accept().await else { + continue; + }; + let _ = stream.set_nodelay(true); + let acceptor = acceptor.clone(); + let service = TowerToHyperService::new(app.clone()); + let h2 = h2.clone(); + tokio::spawn(async move { + let Ok(tls_stream) = acceptor.accept(stream).await else { + return; + }; + let _ = h2 + .serve_connection(TokioIo::new(tls_stream), service) + .await; + }); + } + }); +} + +async fn serve_port_8080( + listener: TcpListener, + h1_app: Router, + grpc_app: Router, +) -> io::Result<()> { let mut h1 = http1::Builder::new(); h1.keep_alive(true).pipeline_flush(true); + let h2 = build_h2(); loop { let Ok((stream, _)) = listener.accept().await else { continue; }; let _ = stream.set_nodelay(true); - let service = TowerToHyperService::new(app.clone()); - tokio::spawn(h1.serve_connection(TokioIo::new(stream), service)); + let h1 = h1.clone(); + let h2 = h2.clone(); + let h1_app = h1_app.clone(); + let grpc_app = grpc_app.clone(); + tokio::spawn(async move { + let mut peek = [0u8; 4]; + let Ok(n) = stream.peek(&mut peek).await else { + return; + }; + if n == 0 { + return; + } + if peek[0] == b'P' && (n == 1 || peek[..n] == H2_PREFACE[..n]) { + if n == 4 && &peek == H2_PREFACE { + let service = TowerToHyperService::new(grpc_app); + let _ = Box::pin(h2.serve_connection(TokioIo::new(stream), service)).await; + } else { + Box::pin(serve_ambiguous_prefix(stream, h1, h2, h1_app, grpc_app)).await; + } + return; + } + let service = TowerToHyperService::new(h1_app); + let _ = h1 + .serve_connection(TokioIo::new(stream), service) + .with_upgrades() + .await; + }); } } @@ -343,21 +543,35 @@ fn main() -> Result<(), Box> { }; LazyLock::force(&DATASET); - let tls_config = load_tls_config(); + let tls_bundle = load_tls_bundle(); let http_addr: SocketAddr = "0.0.0.0:8080".parse()?; - let tls_addr: SocketAddr = "0.0.0.0:8081".parse()?; + let tls_h1_addr: SocketAddr = "0.0.0.0:8081".parse()?; + let h2c_addr: SocketAddr = "0.0.0.0:8082".parse()?; + let h2_h3_addr: SocketAddr = "0.0.0.0:8443".parse()?; let mut handles = Vec::with_capacity(workers); for _ in 0..workers { let db_config = db_config.clone(); - let tls_config = tls_config.clone(); + let tls_h1_cfg = tls_bundle.as_ref().map(|b| b.h1.clone()); + let tls_h2_cfg = tls_bundle.as_ref().map(|b| b.h2.clone()); + let quinn_cfg = tls_bundle.as_ref().and_then(|b| b.h3.clone()); + let std_http = reuseport_listener(http_addr)?; - let std_tls = tls_config + let std_h2c = reuseport_listener(h2c_addr)?; + let std_tls_h1 = tls_h1_cfg + .as_ref() + .map(|_| reuseport_listener(tls_h1_addr)) + .transpose()?; + let std_tls_h2 = tls_h2_cfg .as_ref() - .map(|_| reuseport_listener(tls_addr)) + .map(|_| reuseport_listener(h2_h3_addr)) + .transpose()?; + let std_h3_udp = quinn_cfg + .as_ref() + .map(|_| h3_server::reuseport_udp(h2_h3_addr)) .transpose()?; - handles.push(std::thread::spawn(move || -> std::io::Result<()> { + handles.push(std::thread::spawn(move || -> io::Result<()> { let rt = tokio::runtime::Builder::new_current_thread() .enable_all() .build()?; @@ -370,28 +584,58 @@ fn main() -> Result<(), Box> { PG_POOL.with(|slot| *slot.borrow_mut() = Some(pool)); } - if let (Some(tls_cfg), Some(std_tls)) = (tls_config, std_tls) { + // Port 8081: HTTP/1.1 + TLS 1.3 (json-tls, 8gbit, connections-1m-tls) + if let (Some(tls_cfg), Some(std_tls)) = (tls_h1_cfg, std_tls_h1) { let tls_app = Router::new() .route("/baseline11", get(baseline_get).post(baseline_post)) .route("/json/{count}", get(json_items_plain)) .route("/echo", post(echo_body)); - serve_tls( + serve_tls_h1( TcpListener::from_std(std_tls)?, TlsAcceptor::from(tls_cfg), tls_app, ); } - let app = Router::new() + // Port 8082: cleartext HTTP/2 prior-knowledge (baseline-h2c, json-h2c) + let h2c_app = Router::new() + .route("/baseline2", get(baseline_get)) + .route("/json/{count}", get(json_items_plain)); + serve_h2c(TcpListener::from_std(std_h2c)?, h2c_app); + + // Port 8443 TCP: HTTP/2 + TLS 1.3 (baseline-h2, static-h2, unary-grpc-tls) + if let (Some(tls_cfg), Some(std_tls)) = (tls_h2_cfg, std_tls_h2) { + let h2_app = Router::new() + .route("/baseline2", get(baseline_get)) + .route("/static/{*path}", get(static_files::static_handler)) + .route("/benchmark.BenchmarkService/GetSum", post(grpc::get_sum)); + serve_tls_h2( + TcpListener::from_std(std_tls)?, + TlsAcceptor::from(tls_cfg), + h2_app, + ); + } + + // Port 8443 UDP: HTTP/3 + QUIC (baseline-h3, static-h3) + if let (Some(q_cfg), Some(std_udp)) = (quinn_cfg, std_h3_udp) { + h3_server::spawn_h3_worker(std_udp, q_cfg)?; + } + + // Port 8080: HTTP/1.1 + WebSocket (/ws) + cleartext gRPC (h2c) + let h1_app = Router::new() .route("/baseline11", get(baseline_get).post(baseline_post)) .route("/pipeline", get(pipeline)) .route("/delay/{ms}", get(delay)) .route("/json/{count}", get(json_items_comp)) .route("/echo", post(echo_body)) .route("/async-db", get(async_db)) - .route("/fortunes", get(fortunes)); + .route("/fortunes", get(fortunes)) + .route("/ws", get(ws::ws_handler)); + + let grpc_app = Router::new() + .route("/benchmark.BenchmarkService/GetSum", post(grpc::get_sum)); - serve_plain(TcpListener::from_std(std_http)?, app).await + serve_port_8080(TcpListener::from_std(std_http)?, h1_app, grpc_app).await }) })); } @@ -446,6 +690,13 @@ async fn pipeline() -> impl IntoResponse { ([(CONTENT_TYPE, TEXT_PLAIN)], Bytes::from_static(b"ok")) } +pub(crate) fn baseline_get_bytes(uri: &Uri) -> Result { + let query = parse_baseline_query(uri)?; + let sum = query.a.checked_add(query.b).ok_or(StatusCode::BAD_REQUEST)?; + let mut buffer = itoa::Buffer::new(); + Ok(Bytes::copy_from_slice(buffer.format(sum).as_bytes())) +} + async fn baseline_get(uri: Uri) -> Result { let query = parse_baseline_query(&uri)?; baseline_response(query, 0) diff --git a/frameworks/proa/src/static_files.rs b/frameworks/proa/src/static_files.rs new file mode 100644 index 000000000..40a5e9422 --- /dev/null +++ b/frameworks/proa/src/static_files.rs @@ -0,0 +1,154 @@ +use std::{env, fs, sync::LazyLock}; + +use axum::{ + body::Bytes, + extract::Path, + http::{ + HeaderMap, HeaderValue, StatusCode, + header::{ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_TYPE, VARY}, + }, + response::{IntoResponse, Response}, +}; + +const TEXT_CSS: HeaderValue = HeaderValue::from_static("text/css"); +const APP_JS: HeaderValue = HeaderValue::from_static("application/javascript"); +const TEXT_HTML: HeaderValue = HeaderValue::from_static("text/html; charset=utf-8"); +const APP_JSON: HeaderValue = HeaderValue::from_static("application/json"); +const IMAGE_SVG: HeaderValue = HeaderValue::from_static("image/svg+xml"); +const FONT_WOFF2: HeaderValue = HeaderValue::from_static("font/woff2"); +const IMAGE_WEBP: HeaderValue = HeaderValue::from_static("image/webp"); +const APP_OCTET: HeaderValue = HeaderValue::from_static("application/octet-stream"); +const ENC_BR: HeaderValue = HeaderValue::from_static("br"); +const ENC_GZIP: HeaderValue = HeaderValue::from_static("gzip"); +const VARY_AE: HeaderValue = HeaderValue::from_static("Accept-Encoding"); + +static STATIC_DIR: LazyLock = LazyLock::new(|| { + env::var("STATIC_DIR").unwrap_or_else(|_| "/data/static".to_string()) +}); + +pub struct StaticFile { + pub content_type: HeaderValue, + pub content_encoding: Option, + pub body: Bytes, +} + +#[inline] +fn content_type_and_compressible(path: &str) -> (HeaderValue, bool) { + let ext = path.rsplit_once('.').map_or("", |(_, e)| e); + match ext { + "css" => (TEXT_CSS, true), + "js" => (APP_JS, true), + "html" => (TEXT_HTML, true), + "json" => (APP_JSON, true), + "svg" => (IMAGE_SVG, true), + "woff2" => (FONT_WOFF2, false), + "webp" => (IMAGE_WEBP, false), + _ => (APP_OCTET, false), + } +} + +#[inline] +fn parse_accept_encoding(header: Option<&str>) -> (bool, bool) { + let Some(raw) = header else { + return (false, false); + }; + let mut br = false; + let mut gzip = false; + for part in raw.split(',') { + let mut iter = part.split(';'); + let token = iter.next().unwrap_or("").trim(); + let rejected = iter.any(|param| { + let p = param.trim(); + p == "q=0" || p == "q=0.0" || p == "q=0.00" || p == "q=0.000" + }); + if rejected { + continue; + } + if token.eq_ignore_ascii_case("br") { + br = true; + } else if token.eq_ignore_ascii_case("gzip") { + gzip = true; + } + } + (br, gzip) +} + +#[inline] +fn is_safe_rel_path(rel: &str) -> bool { + !rel.is_empty() + && !rel.starts_with('/') + && !rel.contains("..") + && !rel.contains('\\') + && !rel.as_bytes().contains(&0) +} + +/// Reads the requested file (or its pre-compressed `.br`/`.gz` sibling) directly +/// from disk on every request so modifications on disk are reflected immediately. +pub fn read_static(rel_path: &str, accept_encoding: Option<&str>) -> Option { + let rel_path = rel_path.strip_prefix('/').unwrap_or(rel_path); + if !is_safe_rel_path(rel_path) { + return None; + } + + let (content_type, compressible) = content_type_and_compressible(rel_path); + let base_dir = STATIC_DIR.as_str(); + let mut full = String::with_capacity(base_dir.len() + 1 + rel_path.len() + 3); + full.push_str(base_dir); + full.push('/'); + full.push_str(rel_path); + let base_len = full.len(); + + if compressible { + let (accepts_br, accepts_gzip) = parse_accept_encoding(accept_encoding); + if accepts_br { + full.push_str(".br"); + if let Ok(data) = fs::read(&full) { + return Some(StaticFile { + content_type, + content_encoding: Some(ENC_BR), + body: Bytes::from(data), + }); + } + full.truncate(base_len); + } + if accepts_gzip { + full.push_str(".gz"); + if let Ok(data) = fs::read(&full) { + return Some(StaticFile { + content_type, + content_encoding: Some(ENC_GZIP), + body: Bytes::from(data), + }); + } + full.truncate(base_len); + } + } + + let data = fs::read(&full).ok()?; + Some(StaticFile { + content_type, + content_encoding: None, + body: Bytes::from(data), + }) +} + +pub async fn static_handler( + Path(path): Path, + headers: HeaderMap, +) -> Result { + let ae = headers.get(ACCEPT_ENCODING).and_then(|v| v.to_str().ok()); + let file = read_static(&path, ae).ok_or(StatusCode::NOT_FOUND)?; + if let Some(enc) = file.content_encoding { + Ok(( + [ + (CONTENT_TYPE, file.content_type), + (CONTENT_ENCODING, enc), + (VARY, VARY_AE), + ], + file.body, + ) + .into_response()) + } else { + Ok(([(CONTENT_TYPE, file.content_type)], file.body).into_response()) + } +} diff --git a/frameworks/proa/src/ws.rs b/frameworks/proa/src/ws.rs new file mode 100644 index 000000000..03c2c3f39 --- /dev/null +++ b/frameworks/proa/src/ws.rs @@ -0,0 +1,311 @@ +use axum::{ + body::Body, + extract::Request, + http::{ + HeaderValue, StatusCode, + header::{CONNECTION, SEC_WEBSOCKET_ACCEPT, SEC_WEBSOCKET_KEY, UPGRADE}, + }, + response::Response, +}; +use hyper_util::rt::TokioIo; +use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; + +const WS_GUID: &[u8] = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; +const MAX_FRAME: u64 = 16 << 20; +const READ_CAP: usize = 16 * 1024; + +const HDR_UPGRADE_WS: HeaderValue = HeaderValue::from_static("websocket"); +const HDR_CONN_UPGRADE: HeaderValue = HeaderValue::from_static("Upgrade"); + +pub async fn ws_handler(req: Request) -> Response { + let is_upgrade = req + .headers() + .get(UPGRADE) + .and_then(|v| v.to_str().ok()) + .is_some_and(|v| v.eq_ignore_ascii_case("websocket")); + let Some(key) = req + .headers() + .get(SEC_WEBSOCKET_KEY) + .and_then(|v| v.to_str().ok()) + .filter(|_| is_upgrade) + else { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::empty()) + .unwrap(); + }; + + let accept = ws_accept(key.as_bytes()); + let accept_hdr = HeaderValue::from_bytes(&accept).expect("valid base64 header"); + + tokio::spawn(async move { + if let Ok(upgraded) = hyper::upgrade::on(req).await { + let _ = echo_loop(TokioIo::new(upgraded)).await; + } + }); + + Response::builder() + .status(StatusCode::SWITCHING_PROTOCOLS) + .header(UPGRADE, HDR_UPGRADE_WS) + .header(CONNECTION, HDR_CONN_UPGRADE) + .header(SEC_WEBSOCKET_ACCEPT, accept_hdr) + .body(Body::empty()) + .unwrap() +} + +#[derive(Clone, Copy)] +struct WsFrame { + fin: bool, + opcode: u8, + mask: Option<[u8; 4]>, + payload_off: usize, + payload_len: usize, + total: usize, +} + +enum Parse { + Frame(WsFrame), + Incomplete, + Error, +} + +async fn echo_loop(mut io: S) -> std::io::Result<()> +where + S: AsyncRead + AsyncWrite + Unpin, +{ + let mut buf = Vec::::with_capacity(READ_CAP); + let mut out = Vec::::with_capacity(READ_CAP); + + loop { + if buf.capacity() - buf.len() < 4096 { + buf.reserve(READ_CAP); + } + let n = io.read_buf(&mut buf).await?; + if n == 0 { + return Ok(()); + } + + let mut pos = 0usize; + loop { + let f = match parse_frame(&buf[pos..]) { + Parse::Frame(f) => f, + Parse::Incomplete => break, + Parse::Error => return Ok(()), + }; + + let start = pos + f.payload_off; + let end = start + f.payload_len; + if let Some(mask) = f.mask { + apply_mask(&mut buf[start..end], mask); + } + + match f.opcode { + 0x0..=0x2 => { + push_header(&mut out, f.fin, f.opcode, f.payload_len); + out.extend_from_slice(&buf[start..end]); + } + 0x9 => { + push_header(&mut out, true, 0xA, f.payload_len); + out.extend_from_slice(&buf[start..end]); + } + 0x8 => { + push_header(&mut out, true, 0x8, f.payload_len); + out.extend_from_slice(&buf[start..end]); + io.write_all(&out).await?; + return Ok(()); + } + _ => {} + } + pos += f.total; + } + + if !out.is_empty() { + io.write_all(&out).await?; + out.clear(); + } + if pos == buf.len() { + buf.clear(); + } else if pos > 0 { + let rem = buf.len() - pos; + buf.copy_within(pos.., 0); + buf.truncate(rem); + } + } +} + +#[inline] +fn apply_mask(payload: &mut [u8], mask: [u8; 4]) { + let mask8 = u64::from_ne_bytes([ + mask[0], mask[1], mask[2], mask[3], mask[0], mask[1], mask[2], mask[3], + ]); + let mut chunks = payload.chunks_exact_mut(8); + for chunk in &mut chunks { + let word = u64::from_ne_bytes(chunk.try_into().unwrap()) ^ mask8; + chunk.copy_from_slice(&word.to_ne_bytes()); + } + for (i, byte) in chunks.into_remainder().iter_mut().enumerate() { + *byte ^= mask[i & 3]; + } +} + +#[inline] +fn parse_frame(buf: &[u8]) -> Parse { + if buf.len() < 2 { + return Parse::Incomplete; + } + let b0 = buf[0]; + let b1 = buf[1]; + let fin = b0 & 0x80 != 0; + let opcode = b0 & 0x0F; + let masked = b1 & 0x80 != 0; + let len7 = (b1 & 0x7F) as usize; + + let (payload_len, mut off) = if len7 < 126 { + (len7, 2usize) + } else if len7 == 126 { + if buf.len() < 4 { + return Parse::Incomplete; + } + (u16::from_be_bytes([buf[2], buf[3]]) as usize, 4) + } else { + if buf.len() < 10 { + return Parse::Incomplete; + } + let l = u64::from_be_bytes([ + buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], + ]); + if l > MAX_FRAME { + return Parse::Error; + } + (l as usize, 10) + }; + + let mask = if masked { + if buf.len() < off + 4 { + return Parse::Incomplete; + } + let m = [buf[off], buf[off + 1], buf[off + 2], buf[off + 3]]; + off += 4; + Some(m) + } else { + None + }; + + if buf.len() < off + payload_len { + return Parse::Incomplete; + } + + Parse::Frame(WsFrame { + fin, + opcode, + mask, + payload_off: off, + payload_len, + total: off + payload_len, + }) +} + +#[inline] +fn push_header(out: &mut Vec, fin: bool, opcode: u8, len: usize) { + out.push(if fin { 0x80 } else { 0 } | (opcode & 0x0F)); + if len < 126 { + out.push(len as u8); + } else if len <= u16::MAX as usize { + out.push(126); + out.extend_from_slice(&(len as u16).to_be_bytes()); + } else { + out.push(127); + out.extend_from_slice(&(len as u64).to_be_bytes()); + } +} + +fn ws_accept(key: &[u8]) -> [u8; 28] { + let mut input = [0u8; 128]; + let n = key.len().min(input.len() - WS_GUID.len()); + input[..n].copy_from_slice(&key[..n]); + input[n..n + WS_GUID.len()].copy_from_slice(WS_GUID); + let digest = sha1(&input[..n + WS_GUID.len()]); + base64_20(&digest) +} + +fn sha1(data: &[u8]) -> [u8; 20] { + let mut h: [u32; 5] = [ + 0x6745_2301, + 0xEFCD_AB89, + 0x98BA_DCFE, + 0x1032_5476, + 0xC3D2_E1F0, + ]; + let bit_len = (data.len() as u64).wrapping_mul(8); + let mut msg = Vec::with_capacity(data.len() + 72); + msg.extend_from_slice(data); + msg.push(0x80); + while msg.len() % 64 != 56 { + msg.push(0); + } + msg.extend_from_slice(&bit_len.to_be_bytes()); + + let mut w = [0u32; 80]; + for chunk in msg.chunks_exact(64) { + for (i, word) in chunk.chunks_exact(4).enumerate() { + w[i] = u32::from_be_bytes([word[0], word[1], word[2], word[3]]); + } + for i in 16..80 { + w[i] = (w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]).rotate_left(1); + } + let [mut a, mut b, mut c, mut d, mut e] = h; + for (i, &wi) in w.iter().enumerate() { + let (f, k) = match i { + 0..=19 => ((b & c) | ((!b) & d), 0x5A82_7999u32), + 20..=39 => (b ^ c ^ d, 0x6ED9_EBA1u32), + 40..=59 => ((b & c) | (b & d) | (c & d), 0x8F1B_BCDC_u32), + _ => (b ^ c ^ d, 0xCA62_C1D6u32), + }; + let temp = a + .rotate_left(5) + .wrapping_add(f) + .wrapping_add(e) + .wrapping_add(k) + .wrapping_add(wi); + e = d; + d = c; + c = b.rotate_left(30); + b = a; + a = temp; + } + h[0] = h[0].wrapping_add(a); + h[1] = h[1].wrapping_add(b); + h[2] = h[2].wrapping_add(c); + h[3] = h[3].wrapping_add(d); + h[4] = h[4].wrapping_add(e); + } + + let mut out = [0u8; 20]; + for (i, word) in h.iter().enumerate() { + out[i * 4..i * 4 + 4].copy_from_slice(&word.to_be_bytes()); + } + out +} + +fn base64_20(src: &[u8; 20]) -> [u8; 28] { + const TABLE: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + let mut out = [b'='; 28]; + let mut o = 0usize; + let mut i = 0usize; + while i + 3 <= 20 { + let v = (u32::from(src[i]) << 16) | (u32::from(src[i + 1]) << 8) | u32::from(src[i + 2]); + out[o] = TABLE[((v >> 18) & 0x3f) as usize]; + out[o + 1] = TABLE[((v >> 12) & 0x3f) as usize]; + out[o + 2] = TABLE[((v >> 6) & 0x3f) as usize]; + out[o + 3] = TABLE[(v & 0x3f) as usize]; + i += 3; + o += 4; + } + // 20 % 3 == 2 remaining bytes (src[18], src[19]) + let v = (u32::from(src[18]) << 16) | (u32::from(src[19]) << 8); + out[24] = TABLE[((v >> 18) & 0x3f) as usize]; + out[25] = TABLE[((v >> 12) & 0x3f) as usize]; + out[26] = TABLE[((v >> 6) & 0x3f) as usize]; + out[27] = b'='; + out +} From fd7d2e6dfd42a769cccb5ebbcf8616a4b1d4dc3e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Nov 2026 21:51:13 +0000 Subject: [PATCH 3/5] Benchmark results: proa connections-1m,connections-1m-tls,baseline-h2,static-h2,baseline-h2c,json-h2c,baseline-h3,static-h3,unary-grpc,unary-grpc-tls,echo-ws,echo-ws-pipeline,echo-ws-limited [skip ci] --- site/data/frameworks.json | 2 +- site/data/results/proa.json | 476 ++++++++++++++++++ site/static/logs/baseline-h2/1024/proa.log | 0 site/static/logs/baseline-h2/256/proa.log | 0 site/static/logs/baseline-h2c/1024/proa.log | 0 site/static/logs/baseline-h2c/256/proa.log | 0 site/static/logs/baseline-h2c/4096/proa.log | 0 site/static/logs/baseline-h3/64/proa.log | 0 .../logs/connections-1m-tls/1000000/proa.log | 0 .../logs/connections-1m/1000000/proa.log | 0 .../static/logs/echo-ws-limited/4096/proa.log | 0 site/static/logs/echo-ws-limited/512/proa.log | 0 .../logs/echo-ws-pipeline/16384/proa.log | 0 .../logs/echo-ws-pipeline/4096/proa.log | 0 .../static/logs/echo-ws-pipeline/512/proa.log | 0 site/static/logs/echo-ws/16384/proa.log | 0 site/static/logs/echo-ws/4096/proa.log | 0 site/static/logs/echo-ws/512/proa.log | 0 site/static/logs/json-h2c/1024/proa.log | 0 site/static/logs/json-h2c/4096/proa.log | 0 site/static/logs/static-h2/1024/proa.log | 0 site/static/logs/static-h2/256/proa.log | 0 site/static/logs/static-h3/64/proa.log | 0 site/static/logs/unary-grpc-tls/1024/proa.log | 0 site/static/logs/unary-grpc-tls/256/proa.log | 0 site/static/logs/unary-grpc/1024/proa.log | 0 site/static/logs/unary-grpc/256/proa.log | 0 27 files changed, 477 insertions(+), 1 deletion(-) create mode 100644 site/static/logs/baseline-h2/1024/proa.log create mode 100644 site/static/logs/baseline-h2/256/proa.log create mode 100644 site/static/logs/baseline-h2c/1024/proa.log create mode 100644 site/static/logs/baseline-h2c/256/proa.log create mode 100644 site/static/logs/baseline-h2c/4096/proa.log create mode 100644 site/static/logs/baseline-h3/64/proa.log create mode 100644 site/static/logs/connections-1m-tls/1000000/proa.log create mode 100644 site/static/logs/connections-1m/1000000/proa.log create mode 100644 site/static/logs/echo-ws-limited/4096/proa.log create mode 100644 site/static/logs/echo-ws-limited/512/proa.log create mode 100644 site/static/logs/echo-ws-pipeline/16384/proa.log create mode 100644 site/static/logs/echo-ws-pipeline/4096/proa.log create mode 100644 site/static/logs/echo-ws-pipeline/512/proa.log create mode 100644 site/static/logs/echo-ws/16384/proa.log create mode 100644 site/static/logs/echo-ws/4096/proa.log create mode 100644 site/static/logs/echo-ws/512/proa.log create mode 100644 site/static/logs/json-h2c/1024/proa.log create mode 100644 site/static/logs/json-h2c/4096/proa.log create mode 100644 site/static/logs/static-h2/1024/proa.log create mode 100644 site/static/logs/static-h2/256/proa.log create mode 100644 site/static/logs/static-h3/64/proa.log create mode 100644 site/static/logs/unary-grpc-tls/1024/proa.log create mode 100644 site/static/logs/unary-grpc-tls/256/proa.log create mode 100644 site/static/logs/unary-grpc/1024/proa.log create mode 100644 site/static/logs/unary-grpc/256/proa.log diff --git a/site/data/frameworks.json b/site/data/frameworks.json index 463174e77..0e9032f1f 100644 --- a/site/data/frameworks.json +++ b/site/data/frameworks.json @@ -2057,7 +2057,7 @@ }, "Proa": { "dir": "proa", - "description": "Compiled Proa HTML components served over thread-per-core Axum/Hyper workers with mimalloc v2, sonic-rs JSON serialization, thread-local libdeflater gzip compression, TLS 1.3 (AES-128-GCM via aws-lc-rs) on :8081, and per-worker deadpool-postgres pools.", + "description": "Compiled Proa HTML components served over thread-per-core Axum/Hyper workers with mimalloc v2, sonic-rs JSON serialization, thread-local libdeflater gzip compression, TLS 1.3 (AES-128-GCM via aws-lc-rs) for HTTP/1.1 (:8081), HTTP/2 (:8443), h2c (:8082), HTTP/3/QUIC via quinn+h3 (:8443/udp), gRPC, batched WebSocket echo, and per-worker deadpool-postgres pools.", "repo": "https://github.com/Proa-Labs/proa", "type": "emerging", "engine": "hyper", diff --git a/site/data/results/proa.json b/site/data/results/proa.json index 8b750e03e..5fe1c8765 100644 --- a/site/data/results/proa.json +++ b/site/data/results/proa.json @@ -87,6 +87,322 @@ "status_4xx": 0, "status_5xx": 0 }, + "baseline-h2-1024": { + "framework": "Proa", + "language": "Rust", + "rps": 8355355, + "avg_latency": "11.84ms", + "p99_latency": "21.63ms", + "max_latency": "71.88ms", + "cpu": "6304.2%", + "memory": "595MiB", + "connections": 1024, + "threads": 64, + "duration": "5.06s", + "pipeline": 1, + "bandwidth": "209.70MB/s", + "reconnects": 0, + "status_2xx": 42278100, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "baseline-h2-256": { + "framework": "Proa", + "language": "Rust", + "rps": 9584183, + "avg_latency": "2.55ms", + "p99_latency": "7.11ms", + "max_latency": "14.86ms", + "cpu": "6002.4%", + "memory": "356MiB", + "connections": 256, + "threads": 64, + "duration": "5.02s", + "pipeline": 1, + "bandwidth": "238.61MB/s", + "reconnects": 0, + "status_2xx": 48112600, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "baseline-h2c-1024": { + "framework": "Proa", + "language": "Rust", + "rps": 8699980, + "avg_latency": "12.07ms", + "p99_latency": "36.30ms", + "max_latency": "83.49ms", + "cpu": "6116.4%", + "memory": "594MiB", + "connections": 1024, + "threads": 64, + "duration": "5.06s", + "pipeline": 1, + "bandwidth": "218.35MB/s", + "reconnects": 0, + "status_2xx": 44021900, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "baseline-h2c-256": { + "framework": "Proa", + "language": "Rust", + "rps": 9903061, + "avg_latency": "2.42ms", + "p99_latency": "5.38ms", + "max_latency": "8.35ms", + "cpu": "6030.2%", + "memory": "383MiB", + "connections": 256, + "threads": 64, + "duration": "5.03s", + "pipeline": 1, + "bandwidth": "247.03MB/s", + "reconnects": 0, + "status_2xx": 49812400, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "baseline-h2c-4096": { + "framework": "Proa", + "language": "Rust", + "rps": 7538333, + "avg_latency": "53.43ms", + "p99_latency": "80.79ms", + "max_latency": "106.44ms", + "cpu": "6188.5%", + "memory": "1.6GiB", + "connections": 4096, + "threads": 64, + "duration": "5.10s", + "pipeline": 1, + "bandwidth": "190.81MB/s", + "reconnects": 0, + "status_2xx": 38445500, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "connections-1m-1000000": { + "framework": "Proa", + "language": "Rust", + "rps": 249999, + "avg_latency": "73.1us", + "p99_latency": "134.0us", + "max_latency": "", + "cpu": "785.1%", + "memory": "20.5GiB", + "connections": 1000000, + "threads": 64, + "duration": "20s", + "pipeline": 1, + "bandwidth": "25.50MB/s", + "reconnects": 0, + "status_2xx": 4999979, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0, + "cpu_usec": 158585251, + "cpu_per_req_us": 31.7172, + "target_rate": 250000, + "rate_ratio": 1.0, + "p99_9_latency": "181.0us", + "p50_latency": "70.0us", + "connections_open": 1000000, + "window_connect_errors": 0 + }, + "connections-1m-tls-1000000": { + "framework": "Proa", + "language": "Rust", + "rps": 249968, + "avg_latency": "70.0us", + "p99_latency": "112.0us", + "max_latency": "", + "cpu": "1448.9%", + "memory": "28.1GiB", + "connections": 1000000, + "threads": 64, + "duration": "20s", + "pipeline": 1, + "bandwidth": "25.50MB/s", + "reconnects": 0, + "status_2xx": 5000366, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0, + "cpu_usec": 188257398, + "cpu_per_req_us": 37.6487, + "target_rate": 250000, + "rate_ratio": 0.9999, + "p99_9_latency": "149.0us", + "p50_latency": "69.0us", + "connections_open": 1000000, + "window_connect_errors": 0 + }, + "echo-ws-16384": { + "framework": "Proa", + "language": "Rust", + "rps": 4104885, + "avg_latency": "3.99ms", + "p99_latency": "4.55ms", + "max_latency": "", + "cpu": "5958.7%", + "memory": "742MiB", + "connections": 16384, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "27.40MB/s", + "reconnects": 0, + "status_2xx": 20524427, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-4096": { + "framework": "Proa", + "language": "Rust", + "rps": 4354138, + "avg_latency": "940us", + "p99_latency": "1.24ms", + "max_latency": "", + "cpu": "5977.3%", + "memory": "295MiB", + "connections": 4096, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "29.06MB/s", + "reconnects": 0, + "status_2xx": 21770692, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-512": { + "framework": "Proa", + "language": "Rust", + "rps": 4252156, + "avg_latency": "119us", + "p99_latency": "261us", + "max_latency": "", + "cpu": "6226.9%", + "memory": "171MiB", + "connections": 512, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "28.38MB/s", + "reconnects": 0, + "status_2xx": 21260780, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-limited-4096": { + "framework": "Proa", + "language": "Rust", + "rps": 2587800, + "avg_latency": "1.33ms", + "p99_latency": "2.37ms", + "max_latency": "", + "cpu": "5674.6%", + "memory": "299MiB", + "connections": 4096, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "58.20MB/s", + "reconnects": 1293593, + "status_2xx": 12939003, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-limited-512": { + "framework": "Proa", + "language": "Rust", + "rps": 2382511, + "avg_latency": "178us", + "p99_latency": "583us", + "max_latency": "", + "cpu": "5387.4%", + "memory": "257MiB", + "connections": 512, + "threads": 64, + "duration": "5s", + "pipeline": 1, + "bandwidth": "53.61MB/s", + "reconnects": 1191269, + "status_2xx": 11912558, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-pipeline-16384": { + "framework": "Proa", + "language": "Rust", + "rps": 61820115, + "avg_latency": "4.24ms", + "p99_latency": "5.01ms", + "max_latency": "", + "cpu": "6101.9%", + "memory": "737MiB", + "connections": 16384, + "threads": 64, + "duration": "5s", + "pipeline": 16, + "bandwidth": "412.63MB/s", + "reconnects": 0, + "status_2xx": 309100576, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-pipeline-4096": { + "framework": "Proa", + "language": "Rust", + "rps": 67055366, + "avg_latency": "976us", + "p99_latency": "1.35ms", + "max_latency": "", + "cpu": "6012.7%", + "memory": "298MiB", + "connections": 4096, + "threads": 64, + "duration": "5s", + "pipeline": 16, + "bandwidth": "447.53MB/s", + "reconnects": 0, + "status_2xx": 335276832, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "echo-ws-pipeline-512": { + "framework": "Proa", + "language": "Rust", + "rps": 65358985, + "avg_latency": "124us", + "p99_latency": "259us", + "max_latency": "", + "cpu": "6259.8%", + "memory": "168MiB", + "connections": 512, + "threads": 64, + "duration": "5s", + "pipeline": 16, + "bandwidth": "436.28MB/s", + "reconnects": 0, + "status_2xx": 326794928, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, "fortunes-1024": { "framework": "Proa", "language": "Rust", @@ -147,6 +463,46 @@ "status_4xx": 0, "status_5xx": 0 }, + "json-h2c-1024": { + "framework": "Proa", + "language": "Rust", + "rps": 2257871, + "avg_latency": "14.12ms", + "p99_latency": "27.11ms", + "max_latency": "40.60ms", + "cpu": "6473.8%", + "memory": "458MiB", + "connections": 1024, + "threads": 64, + "duration": "5.05s", + "pipeline": 1, + "bandwidth": "7.53GB/s", + "reconnects": 0, + "status_2xx": 11402712, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "json-h2c-4096": { + "framework": "Proa", + "language": "Rust", + "rps": 2070143, + "avg_latency": "61.82ms", + "p99_latency": "126.75ms", + "max_latency": "179.83ms", + "cpu": "6156.2%", + "memory": "1.1GiB", + "connections": 4096, + "threads": 64, + "duration": "5.12s", + "pipeline": 1, + "bandwidth": "7.00GB/s", + "reconnects": 0, + "status_2xx": 10599657, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, "json-tls-4096": { "framework": "Proa", "language": "Rust", @@ -252,6 +608,126 @@ "status_3xx": 0, "status_4xx": 0, "status_5xx": 0 + }, + "static-h2-1024": { + "framework": "Proa", + "language": "Rust", + "rps": 678553, + "avg_latency": "47.10ms", + "p99_latency": "90.04ms", + "max_latency": "211.72ms", + "cpu": "6259.7%", + "memory": "895MiB", + "connections": 1024, + "threads": 64, + "duration": "5.07s", + "pipeline": 1, + "bandwidth": "10.45GB/s", + "reconnects": 0, + "status_2xx": 3440423, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "static-h2-256": { + "framework": "Proa", + "language": "Rust", + "rps": 758506, + "avg_latency": "11.43ms", + "p99_latency": "25.03ms", + "max_latency": "57.17ms", + "cpu": "6223.8%", + "memory": "499MiB", + "connections": 256, + "threads": 64, + "duration": "5.03s", + "pipeline": 1, + "bandwidth": "11.59GB/s", + "reconnects": 0, + "status_2xx": 3815436, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "unary-grpc-1024": { + "framework": "Proa", + "language": "Rust", + "rps": 6456942, + "avg_latency": "8.68ms", + "p99_latency": "20.60ms", + "max_latency": "45.94ms", + "cpu": "5349.0%", + "memory": "779MiB", + "connections": 1024, + "threads": 64, + "duration": "5.07s", + "pipeline": 1, + "bandwidth": "262.29MB/s", + "reconnects": 0, + "status_2xx": 32736700, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "unary-grpc-256": { + "framework": "Proa", + "language": "Rust", + "rps": 6414652, + "avg_latency": "3.16ms", + "p99_latency": "6.62ms", + "max_latency": "13.67ms", + "cpu": "5046.4%", + "memory": "430MiB", + "connections": 256, + "threads": 64, + "duration": "5.03s", + "pipeline": 1, + "bandwidth": "258.49MB/s", + "reconnects": 0, + "status_2xx": 32265700, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "unary-grpc-tls-1024": { + "framework": "Proa", + "language": "Rust", + "rps": 6034011, + "avg_latency": "15.61ms", + "p99_latency": "37.65ms", + "max_latency": "125.24ms", + "cpu": "6241.8%", + "memory": "712MiB", + "connections": 1024, + "threads": 64, + "duration": "5.06s", + "pipeline": 1, + "bandwidth": "244.63MB/s", + "reconnects": 0, + "status_2xx": 30532100, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, + "unary-grpc-tls-256": { + "framework": "Proa", + "language": "Rust", + "rps": 6285734, + "avg_latency": "3.22ms", + "p99_latency": "6.72ms", + "max_latency": "11.43ms", + "cpu": "5063.1%", + "memory": "437MiB", + "connections": 256, + "threads": 64, + "duration": "5.04s", + "pipeline": 1, + "bandwidth": "253.80MB/s", + "reconnects": 0, + "status_2xx": 31680100, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 } } } diff --git a/site/static/logs/baseline-h2/1024/proa.log b/site/static/logs/baseline-h2/1024/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/baseline-h2/256/proa.log b/site/static/logs/baseline-h2/256/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/baseline-h2c/1024/proa.log b/site/static/logs/baseline-h2c/1024/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/baseline-h2c/256/proa.log b/site/static/logs/baseline-h2c/256/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/baseline-h2c/4096/proa.log b/site/static/logs/baseline-h2c/4096/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/baseline-h3/64/proa.log b/site/static/logs/baseline-h3/64/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/connections-1m-tls/1000000/proa.log b/site/static/logs/connections-1m-tls/1000000/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/connections-1m/1000000/proa.log b/site/static/logs/connections-1m/1000000/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws-limited/4096/proa.log b/site/static/logs/echo-ws-limited/4096/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws-limited/512/proa.log b/site/static/logs/echo-ws-limited/512/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws-pipeline/16384/proa.log b/site/static/logs/echo-ws-pipeline/16384/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws-pipeline/4096/proa.log b/site/static/logs/echo-ws-pipeline/4096/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws-pipeline/512/proa.log b/site/static/logs/echo-ws-pipeline/512/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws/16384/proa.log b/site/static/logs/echo-ws/16384/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws/4096/proa.log b/site/static/logs/echo-ws/4096/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/echo-ws/512/proa.log b/site/static/logs/echo-ws/512/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/json-h2c/1024/proa.log b/site/static/logs/json-h2c/1024/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/json-h2c/4096/proa.log b/site/static/logs/json-h2c/4096/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/static-h2/1024/proa.log b/site/static/logs/static-h2/1024/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/static-h2/256/proa.log b/site/static/logs/static-h2/256/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/static-h3/64/proa.log b/site/static/logs/static-h3/64/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/unary-grpc-tls/1024/proa.log b/site/static/logs/unary-grpc-tls/1024/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/unary-grpc-tls/256/proa.log b/site/static/logs/unary-grpc-tls/256/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/unary-grpc/1024/proa.log b/site/static/logs/unary-grpc/1024/proa.log new file mode 100644 index 000000000..e69de29bb diff --git a/site/static/logs/unary-grpc/256/proa.log b/site/static/logs/unary-grpc/256/proa.log new file mode 100644 index 000000000..e69de29bb From f1868cf03a92e9c443602d1a3fd9282b207b5c91 Mon Sep 17 00:00:00 2001 From: Andrew Hariri <31301117+hariria@users.noreply.github.com> Date: Sun, 22 Nov 2026 13:56:49 -0800 Subject: [PATCH 4/5] proa: drain H3 request stream to FIN before drop to avoid STOP_SENDING --- frameworks/proa/src/h3_server.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frameworks/proa/src/h3_server.rs b/frameworks/proa/src/h3_server.rs index 2dbd349e0..947ae2207 100644 --- a/frameworks/proa/src/h3_server.rs +++ b/frameworks/proa/src/h3_server.rs @@ -4,7 +4,7 @@ use axum::{ body::Bytes, http::{ HeaderValue, Response, StatusCode, - header::{ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_TYPE, VARY}, + header::{ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE, VARY}, }, }; use quinn::{ @@ -72,6 +72,10 @@ pub fn spawn_h3_worker( let Ok((req, mut stream)) = resolver.resolve_request().await else { return; }; + // Drain the request receive stream to FIN so quinn's RecvStream::drop + // does not emit STOP_SENDING(0), which nghttp3/h2load treats as a stream error. + while let Ok(Some(_)) = stream.recv_data().await {} + let path = req.uri().path(); let (resp, body) = if path == "/baseline2" { match baseline_get_bytes(req.uri()) { @@ -79,6 +83,7 @@ pub fn spawn_h3_worker( let resp = Response::builder() .status(StatusCode::OK) .header(CONTENT_TYPE, TEXT_PLAIN) + .header(CONTENT_LENGTH, bytes.len()) .body(()) .unwrap(); (resp, bytes) @@ -97,7 +102,8 @@ pub fn spawn_h3_worker( Some(file) => { let mut builder = Response::builder() .status(StatusCode::OK) - .header(CONTENT_TYPE, file.content_type); + .header(CONTENT_TYPE, file.content_type) + .header(CONTENT_LENGTH, file.body.len()); if let Some(enc) = file.content_encoding { builder = builder .header(CONTENT_ENCODING, enc) From 8530a5e10b44e889952a96c7e5c5ed645f1cfd78 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Nov 2026 22:01:19 +0000 Subject: [PATCH 5/5] Benchmark results: proa baseline-h3,static-h3 [skip ci] --- site/data/results/proa.json | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/site/data/results/proa.json b/site/data/results/proa.json index 5fe1c8765..a5a393479 100644 --- a/site/data/results/proa.json +++ b/site/data/results/proa.json @@ -187,6 +187,26 @@ "status_4xx": 0, "status_5xx": 0 }, + "baseline-h3-64": { + "framework": "Proa", + "language": "Rust", + "rps": 5231188, + "avg_latency": "798us", + "p99_latency": "1.37ms", + "max_latency": "4.61ms", + "cpu": "3365.9%", + "memory": "246MiB", + "connections": 64, + "threads": 64, + "duration": "5.01s", + "pipeline": 1, + "bandwidth": "59.99MB/s", + "reconnects": 0, + "status_2xx": 26208256, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, "connections-1m-1000000": { "framework": "Proa", "language": "Rust", @@ -649,6 +669,26 @@ "status_4xx": 0, "status_5xx": 0 }, + "static-h3-64": { + "framework": "Proa", + "language": "Rust", + "rps": 617280, + "avg_latency": "8.31ms", + "p99_latency": "44.76ms", + "max_latency": "83.29ms", + "cpu": "4204.8%", + "memory": "690MiB", + "connections": 64, + "threads": 64, + "duration": "5.01s", + "pipeline": 1, + "bandwidth": "9.39GB/s", + "reconnects": 0, + "status_2xx": 3094648, + "status_3xx": 0, + "status_4xx": 0, + "status_5xx": 0 + }, "unary-grpc-1024": { "framework": "Proa", "language": "Rust",