Skip to content

Commit e25e80c

Browse files
[Rust] Update WTX - HTTP/2 (#813)
* [Rust] Update WTX - HTTP/2 * Benchmark results: wtx-http2 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1ae067f commit e25e80c

9 files changed

Lines changed: 100 additions & 97 deletions

File tree

frameworks/wtx-http2/Cargo.lock

Lines changed: 19 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/wtx-http2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024"
77
serde = { default-features = false, features = ["derive"], version = "1.0", }
88
serde_json = { default-features = false, features = ["std"], version = "1.0" }
99
tokio = { default-features = false, features = ["macros", "rt-multi-thread"], version = "1.0" }
10-
wtx = { default-features = false, features = ["http-server-framework", "macros", "matchit", "nightly", "optimization", "serde_json", "tokio"], version = "0.44"}
10+
wtx = { default-features = false, features = ["http-server-framework", "macros", "nightly", "optimizations", "optioned-server", "serde_json", "tokio"], version = "0.47" }
1111

1212
[profile.release]
1313
codegen-units = 1

frameworks/wtx-http2/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM rust:1.95 AS build
2-
RUN rustup default nightly-2026-03-08
2+
RUN rustup default nightly-2026-05-07
33
WORKDIR /app
44
COPY Cargo.toml .
55
RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release && rm -rf src/ target/release/httparena-wtx-http2* target/release/deps/httparena_wtx-http2*

frameworks/wtx-http2/src/main.rs

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,73 @@ use wtx::{
33
codec::i64_string,
44
collection::{ArrayVectorU8, Vector},
55
http::{
6-
Header, HttpRecvParams, KnownHeaderName, ReqResBuffer, StatusCode,
6+
Header, HttpRecvParams, KnownHeaderName, MsgBufferString, MsgDataMut, StatusCode,
77
server_framework::{
8-
JsonReply, PathOwned, Router, ServerFrameworkBuilder, State, VerbatimParams, get,
8+
JsonReply, PathOwned, Router, ServerFrameworkBuilder, State, VerbatimParams, get,
99
},
1010
},
1111
misc::Wrapper,
1212
sync::Arc,
1313
};
1414

15+
fn main() {
16+
let dataset = load_dataset();
17+
let threads = std::thread::available_parallelism().map(|el| el.get()).unwrap_or(1);
18+
let mut handlers = Vector::new();
19+
for _ in 0..threads {
20+
let dataset_thread = dataset.clone();
21+
let handle = std::thread::spawn(|| {
22+
tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
23+
let router = Router::paths(wtx::paths!(
24+
("/baseline2", get(endpoint_baseline2)),
25+
("/json/{count}", get(endpoint_json)),
26+
)).unwrap();
27+
let _rslt = ServerFrameworkBuilder::new(HttpRecvParams::with_permissive_params(), router)
28+
.with_conn_aux(move || Ok(ConnAux { dataset: dataset_thread.clone() }))
29+
.tokio(
30+
"0.0.0.0:8082",
31+
|_error| {},
32+
|_| Ok(()),
33+
|_stream| Ok(()),
34+
|_error| {},
35+
)
36+
.await;
37+
})
38+
});
39+
handlers.push(handle).unwrap();
40+
}
41+
for handle in handlers {
42+
handle.join().unwrap();
43+
}
44+
}
45+
1546
#[derive(Clone, wtx::ConnAux)]
1647
struct ConnAux {
1748
dataset: Arc<Vector<DatasetItem>>,
1849
}
1950

20-
#[tokio::main]
21-
async fn main() -> wtx::Result<()> {
22-
let dataset = load_dataset();
23-
let router = Router::paths(wtx::paths!(
24-
("/baseline2", get(endpoint_baseline2)),
25-
("/json/{count}", get(endpoint_json)),
26-
))?;
27-
ServerFrameworkBuilder::new(HttpRecvParams::with_permissive_params(), router)
28-
.with_conn_aux(move || Ok(ConnAux { dataset: dataset.clone() }))
29-
.tokio(
30-
"0.0.0.0:8082",
31-
|_error| {},
32-
|_| Ok(()),
33-
|stream| {
34-
stream.set_nodelay(true)?;
35-
Ok(())
36-
},
37-
|_error| {},
38-
)
39-
.await
40-
}
41-
4251
async fn endpoint_baseline2(
43-
state: State<'_, ConnAux, (), ReqResBuffer>,
52+
state: State<'_, ConnAux, (), MsgBufferString>,
4453
) -> wtx::Result<VerbatimParams> {
4554
let mut sum: i64 = 0;
46-
for (_, value) in state.req.rrd.uri.query_params() {
55+
for (_, value) in state.req.msg_data.uri.query_params() {
4756
sum = sum.wrapping_add(value.parse()?);
4857
}
49-
state.req.rrd.clear();
50-
state.req.rrd.body.extend_from_copyable_slice(i64_string(sum).as_bytes())?;
51-
state.req.rrd.headers.push_from_iter_many([
58+
state.req.msg_data.clear();
59+
state.req.msg_data.body.extend_from_copyable_slice(i64_string(sum).as_bytes())?;
60+
state.req.msg_data.headers.push_from_iter_many([
5261
Header::from_name_and_value(KnownHeaderName::ContentType.into(), ["text/plain"].into_iter()),
53-
Header::from_name_and_value(KnownHeaderName::Server.into(), ["wtx"].into_iter())
62+
Header::from_name_and_value(KnownHeaderName::Server.into(), ["wtx"].into_iter()),
5463
])?;
5564
Ok(VerbatimParams(StatusCode::Ok))
5665
}
5766

5867
async fn endpoint_json(
59-
state: State<'_, ConnAux, (), ReqResBuffer>,
68+
state: State<'_, ConnAux, (), MsgBufferString>,
6069
PathOwned(count): PathOwned<usize>,
6170
) -> wtx::Result<JsonReply> {
6271
let mut m: f64 = 1.0;
63-
for (key, value) in state.req.rrd.uri.query_params() {
72+
for (key, value) in state.req.msg_data.uri.query_params() {
6473
if key != "m" {
6574
continue;
6675
}
@@ -69,7 +78,7 @@ async fn endpoint_json(
6978
}
7079
let dataset_len = state.conn_aux.dataset.len();
7180
let clamped = if count > dataset_len { dataset_len } else { count };
72-
state.req.rrd.clear();
81+
state.req.msg_data.clear();
7382
let items = state.conn_aux.dataset.iter().take(clamped).map(move |el| {
7483
Ok(ProcessedItem {
7584
id: el.id,
@@ -84,9 +93,9 @@ async fn endpoint_json(
8493
})
8594
});
8695
let resp = JsonResponse { count: clamped, items: Wrapper(items) };
87-
serde_json::to_writer(&mut state.req.rrd.body, &resp).unwrap_or_default();
96+
serde_json::to_writer(&mut state.req.msg_data.body, &resp)?;
8897
let header = Header::from_name_and_value(KnownHeaderName::Server.into(), ["wtx"]);
89-
state.req.rrd.headers.push_from_iter(header)?;
98+
state.req.msg_data.headers.push_from_iter(header)?;
9099
Ok(JsonReply(StatusCode::Ok))
91100
}
92101

site/data/baseline-h2c-1024.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@
135135
{
136136
"framework": "wtx",
137137
"language": "Rust",
138-
"rps": 651217,
139-
"avg_latency": "117.30ms",
140-
"p99_latency": "117.30ms",
141-
"cpu": "4364.3%",
142-
"memory": "1.4GiB",
138+
"rps": 4090632,
139+
"avg_latency": "24.22ms",
140+
"p99_latency": "24.22ms",
141+
"cpu": "6362.4%",
142+
"memory": "945MiB",
143143
"connections": 1024,
144144
"threads": 64,
145145
"duration": "5s",
146146
"pipeline": 1,
147-
"bandwidth": "22.68MB/s",
147+
"bandwidth": "142.14MB/s",
148148
"reconnects": 0,
149-
"status_2xx": 3301674,
149+
"status_2xx": 20698598,
150150
"status_3xx": 0,
151151
"status_4xx": 0,
152152
"status_5xx": 0

site/data/baseline-h2c-256.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@
135135
{
136136
"framework": "wtx",
137137
"language": "Rust",
138-
"rps": 681334,
139-
"avg_latency": "36.59ms",
140-
"p99_latency": "36.59ms",
141-
"cpu": "4593.7%",
142-
"memory": "657MiB",
138+
"rps": 4317835,
139+
"avg_latency": "6.20ms",
140+
"p99_latency": "6.20ms",
141+
"cpu": "6450.6%",
142+
"memory": "675MiB",
143143
"connections": 256,
144144
"threads": 64,
145145
"duration": "5s",
146146
"pipeline": 1,
147-
"bandwidth": "23.54MB/s",
147+
"bandwidth": "149.13MB/s",
148148
"reconnects": 0,
149-
"status_2xx": 3427112,
149+
"status_2xx": 21718714,
150150
"status_3xx": 0,
151151
"status_4xx": 0,
152152
"status_5xx": 0

site/data/baseline-h2c-4096.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@
135135
{
136136
"framework": "wtx",
137137
"language": "Rust",
138-
"rps": 675669,
139-
"avg_latency": "284.85ms",
140-
"p99_latency": "284.85ms",
141-
"cpu": "5253.3%",
142-
"memory": "2.8GiB",
138+
"rps": 3968140,
139+
"avg_latency": "99.18ms",
140+
"p99_latency": "99.18ms",
141+
"cpu": "6449.7%",
142+
"memory": "1.9GiB",
143143
"connections": 4096,
144144
"threads": 64,
145145
"duration": "5s",
146146
"pipeline": 1,
147-
"bandwidth": "23.75MB/s",
147+
"bandwidth": "139.01MB/s",
148148
"reconnects": 0,
149-
"status_2xx": 3452670,
149+
"status_2xx": 20237514,
150150
"status_3xx": 0,
151151
"status_4xx": 0,
152152
"status_5xx": 0

site/data/json-h2c-1024.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@
135135
{
136136
"framework": "wtx",
137137
"language": "Rust",
138-
"rps": 599466,
139-
"avg_latency": "46.46ms",
140-
"p99_latency": "46.46ms",
141-
"cpu": "4670.1%",
142-
"memory": "766MiB",
138+
"rps": 1905215,
139+
"avg_latency": "16.81ms",
140+
"p99_latency": "16.81ms",
141+
"cpu": "6572.6%",
142+
"memory": "422MiB",
143143
"connections": 1024,
144144
"threads": 64,
145145
"duration": "5s",
146146
"pipeline": 1,
147-
"bandwidth": "2.08GB/s",
147+
"bandwidth": "6.69GB/s",
148148
"reconnects": 0,
149-
"status_2xx": 3033298,
149+
"status_2xx": 9640392,
150150
"status_3xx": 0,
151151
"status_4xx": 0,
152152
"status_5xx": 0

site/data/json-h2c-4096.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@
135135
{
136136
"framework": "wtx",
137137
"language": "Rust",
138-
"rps": 575992,
139-
"avg_latency": "142.43ms",
140-
"p99_latency": "142.43ms",
141-
"cpu": "4293.4%",
142-
"memory": "1.8GiB",
138+
"rps": 1782497,
139+
"avg_latency": "73.45ms",
140+
"p99_latency": "73.45ms",
141+
"cpu": "6198.2%",
142+
"memory": "806MiB",
143143
"connections": 4096,
144144
"threads": 64,
145145
"duration": "5s",
146146
"pipeline": 1,
147-
"bandwidth": "2.01GB/s",
147+
"bandwidth": "6.27GB/s",
148148
"reconnects": 0,
149-
"status_2xx": 2937560,
149+
"status_2xx": 9037262,
150150
"status_3xx": 0,
151151
"status_4xx": 0,
152152
"status_5xx": 0

0 commit comments

Comments
 (0)