Skip to content

Commit 7cc40c8

Browse files
authored
Merge pull request #25 from c410-f3r/misc
HTTP/2
2 parents 646e015 + d04740e commit 7cc40c8

File tree

17 files changed

+172
-152
lines changed

17 files changed

+172
-152
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ jobs:
1717
with:
1818
override: true
1919
profile: minimal
20-
toolchain: nightly-2024-02-19
20+
toolchain: nightly-2024-04-27
2121
- uses: Swatinem/rust-cache@v2
2222
- run: |
2323
cd evaluator
24-
cargo build --release --features deploy
25-
cargo run --release --features deploy -- "Shared GitHub runner"
24+
cargo build --release --features all-protocols,deploy
25+
cargo run --release --features all-protocols,deploy -- "Shared GitHub runner"
2626
cd ../site
2727
npm install
2828
npm run build

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
components: clippy, rustfmt
1616
override: true
1717
profile: minimal
18-
toolchain: nightly-2024-02-19
18+
toolchain: nightly-2024-04-27
1919
- uses: Swatinem/rust-cache@v2
2020
- run: |
2121
cd evaluator

evaluator/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evaluator/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
[dependencies]
22
flate2 = { default-features = false, features = ["rust_backend"], version = "1.0" }
33
tokio = { default-features = false, features = ["fs", "io-std", "macros", "process", "rt-multi-thread"], version = "1.0" }
4-
wtx = { branch = "http2", default-features = false, features = ["http2", "optimization", "pool", "tokio", "tokio-rustls", "webpki-roots", "web-socket-handshake"], git = "https://github.com/c410-f3r/wtx" }
4+
wtx = { default-features = false, features = ["http2", "optimization", "pool", "tokio", "tokio-rustls", "webpki-roots", "web-socket-handshake"], git = "https://github.com/c410-f3r/wtx" }
55

66
[features]
7+
all-protocols = ["http2", "web-socket"]
78
deploy = []
9+
http2 = []
10+
web-socket = []
811

912
[package]
1013
edition = "2021"

evaluator/assets/rust.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
FROM docker.io/library/rust:1.77-bookworm AS build
1+
FROM ghcr.io/instrumentisto/rust:beta-bookworm AS build
22
ARG IMPLEMENTATION
33
COPY . /$IMPLEMENTATION
44
WORKDIR /$IMPLEMENTATION
5+
ENV CARGO_PROFILE_RELEASE_LTO=true
56
RUN RUSTFLAGS="-Ccodegen-units=1 -Copt-level=3 -Cpanic=abort -Cstrip=symbols -Ctarget-cpu=native" cargo build --release
67

78
FROM docker.io/library/debian:bookworm
89
ARG IMPLEMENTATION
910
WORKDIR /$IMPLEMENTATION
1011
COPY --from=build /$IMPLEMENTATION/target/release/$IMPLEMENTATION .
1112
ENV IMPLEMENTATION ${IMPLEMENTATION}
13+
ENV RUST_BACKTRACE=1
1214
CMD ./${IMPLEMENTATION}

evaluator/src/http2.rs

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,56 @@
1-
use crate::{
2-
bench_stats::BenchStats, manage_tests, report_line::ReportLine, SOCKET_ADDR, SOCKET_STR,
3-
};
1+
use crate::{manage_cases, report_line::ReportLine, SOCKET_ADDR, URI_STR};
42
use tokio::net::TcpStream;
53
use wtx::{
6-
http::{Headers, Method, Request},
7-
http2::{ConnectParams, Http2Buffer, Http2Tokio, ReqResBuffer},
8-
misc::UriRef,
4+
http::Method,
5+
http2::{ErrorCode, Http2Buffer, Http2Params, Http2Tokio, ReqResBuffer},
96
rng::StaticRng,
107
};
118

129
pub(crate) async fn bench_all(
1310
(generic_rp, rps): (ReportLine, &mut Vec<ReportLine>),
1411
) -> wtx::Result<()> {
15-
macro_rules! name {
16-
($msg_size:expr) => {
17-
concat!(
18-
connections!(),
19-
" connection(s) opening one stream that sends requests of ",
12+
macro_rules! case {
13+
(($msg_size:expr, $streams:expr), $ex:expr) => {{
14+
let name = concat!(
15+
http2_connections!(),
16+
" connection(s) opening ",
17+
$streams,
18+
" stream(s) sending requests of ",
2019
$msg_size
20+
);
21+
(
22+
name,
23+
manage_case!(http2_connections!(), name, generic_rp, $ex),
2124
)
22-
};
25+
}};
2326
}
24-
25-
manage_tests(
26-
generic_rp,
27-
rps,
28-
[(name!("0B"), manage_bench!(write().await))],
29-
);
27+
let params = [
28+
case!(("64 bytes", 1), write(1, &[4; 64]).await),
29+
case!(("64 bytes", 16), write(16, &[4; 64]).await),
30+
];
31+
manage_cases(generic_rp, rps, params);
3032
Ok(())
3133
}
3234

33-
async fn write() -> wtx::Result<()> {
34-
let uri = &UriRef::new(SOCKET_STR);
35+
async fn write(streams: usize, payload: &[u8]) -> wtx::Result<()> {
3536
let mut http2 = Http2Tokio::connect(
36-
ConnectParams::default(),
37-
Http2Buffer::builder(StaticRng::default()).build(),
37+
Http2Buffer::new(StaticRng::default()),
38+
Http2Params::default(),
3839
TcpStream::connect(SOCKET_ADDR).await?,
3940
)
4041
.await?;
4142
let rrb = &mut ReqResBuffer::default();
42-
let mut stream = http2.stream().await?;
43-
let _res = stream
44-
.send_req_recv_res(
45-
Request::http2(&[], &Headers::new(4096), Method::Get, uri.to_ref()),
46-
rrb,
47-
)
48-
.await;
43+
rrb.uri.push_str(URI_STR).unwrap();
44+
rrb.data.reserve(payload.len());
45+
rrb.data.extend_from_slice(payload).unwrap();
46+
for _ in 0..streams {
47+
let mut stream = http2.stream().await?;
48+
stream
49+
.send_req(rrb.as_http2_request_ref(Method::Get))
50+
.await?;
51+
let _res = stream.recv_res(rrb).await?;
52+
stream.send_reset(ErrorCode::NoError).await?;
53+
}
54+
http2.send_go_away(ErrorCode::NoError).await?;
4955
Ok(())
5056
}

evaluator/src/macros.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
#[cfg(feature = "deploy")]
2-
macro_rules! connections {
2+
macro_rules! http2_connections {
3+
() => {
4+
8
5+
};
6+
}
7+
#[cfg(feature = "deploy")]
8+
macro_rules! web_socket_connections {
39
() => {
410
64
511
};
612
}
13+
14+
#[cfg(not(feature = "deploy"))]
15+
macro_rules! http2_connections {
16+
() => {
17+
1
18+
};
19+
}
720
#[cfg(not(feature = "deploy"))]
8-
macro_rules! connections {
21+
macro_rules! web_socket_connections {
922
() => {
1023
1
1124
};
1225
}
1326

14-
macro_rules! manage_bench {
15-
($ex:expr) => {{
16-
let mut data = [0.0; connections!()];
27+
macro_rules! manage_case {
28+
($n:expr, $name:expr, $generic_rp:expr, $ex:expr) => {{
29+
println!(
30+
"***** Running case '{}' of implementation '{}' of protocol '{}' *****",
31+
$name, &$generic_rp.implementation, &$generic_rp.protocol
32+
);
33+
let mut data = [0.0; $n];
1734
let mut set = tokio::task::JoinSet::new();
18-
for idx in 0..connections!() {
35+
for idx in 0..$n {
1936
let _handle = set.spawn(async move {
2037
let now = wtx::misc::GenericTime::now().unwrap();
2138
$ex?;
@@ -26,6 +43,6 @@ macro_rules! manage_bench {
2643
let (idx, value) = rslt.unwrap()?;
2744
data[idx] = value;
2845
}
29-
BenchStats::new(&data)
46+
crate::BenchStats::new(&data)
3047
}};
3148
}

evaluator/src/main.rs

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use tokio::{
2929
time::sleep,
3030
};
3131
use wtx::{
32-
http::{Headers, Method, Request},
33-
http2::{ConnectParams, Http2Buffer, Http2Tokio, ReqResBuffer},
32+
http::Method,
33+
http2::{Http2Buffer, Http2Params, Http2Tokio, ReqResBuffer},
3434
misc::{ArrayString, FnMutFut, GenericTime, TokioRustlsConnector, UriRef},
3535
rng::StaticRng,
3636
};
@@ -39,6 +39,7 @@ const _30_DAYS: Duration = Duration::from_secs(30 * 24 * 60 * 60);
3939
const CSV_HEADER: &str = "environment,protocol,test,implementation,timestamp,min,max,mean,sd\n";
4040
const SOCKET_ADDR: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 9000);
4141
const SOCKET_STR: &str = "127.0.0.1:9000";
42+
const URI_STR: &str = "http://127.0.0.1:9000";
4243

4344
#[tokio::main]
4445
async fn main() {
@@ -93,13 +94,28 @@ async fn handle_cmd_output(cmd: &mut Command) {
9394
);
9495
}
9596

97+
fn manage_cases(
98+
mut generic_rp: ReportLine,
99+
rps: &mut Vec<ReportLine>,
100+
params: impl IntoIterator<Item = (&'static str, BenchStats)>,
101+
) {
102+
for test_params in params {
103+
generic_rp.implementation_specific(test_params);
104+
rps.push(generic_rp.clone());
105+
generic_rp.implementation_clear();
106+
}
107+
}
108+
96109
async fn manage_prev_csv(curr_timestamp: u64, rps: &mut Vec<ReportLine>) {
97110
let csv_fun = || async move {
98-
let cp = ConnectParams::default();
99-
let uri = UriRef::new("https://c410-f3r.github.io:443/wtx-bench/report.csv.gzip");
111+
let mut rrb = ReqResBuffer::default();
112+
rrb.uri
113+
.push_str("https://c410-f3r.github.io:443/wtx-bench/report.csv.gzip")
114+
.unwrap();
115+
let uri = UriRef::new(&rrb.uri);
100116
let mut http2 = Http2Tokio::connect(
101-
cp,
102-
Http2Buffer::builder(StaticRng::default()).build(),
117+
Http2Buffer::new(StaticRng::default()),
118+
Http2Params::default(),
103119
TokioRustlsConnector::from_webpki_roots()
104120
.http2()
105121
.with_tcp_stream(
@@ -109,14 +125,11 @@ async fn manage_prev_csv(curr_timestamp: u64, rps: &mut Vec<ReportLine>) {
109125
.await?,
110126
)
111127
.await?;
112-
let mut rrb = ReqResBuffer::default();
113128
let mut stream = http2.stream().await?;
114-
let res = stream
115-
.send_req_recv_res(
116-
Request::http2(&[], &Headers::new(4096), Method::Get, uri.to_ref()),
117-
&mut rrb,
118-
)
129+
stream
130+
.send_req(rrb.as_http2_request_ref(Method::Get))
119131
.await?;
132+
let res = stream.recv_res(&mut rrb).await?;
120133
decode_report(res.resource().unwrap().body())
121134
};
122135
let Ok(csv) = csv_fun().await else {
@@ -204,26 +217,30 @@ async fn manage_protocols_dir(
204217
let protocol_name = protocol.file_name().into_string().unwrap();
205218
match protocol_name.as_str() {
206219
"http2" => {
207-
manage_protocol_dir(
208-
environment,
209-
Protocol::Http2,
210-
&protocol.path(),
211-
rps,
212-
timestamp,
213-
http2::bench_all,
214-
)
215-
.await
220+
if cfg!(feature = "http2") {
221+
manage_protocol_dir(
222+
environment,
223+
Protocol::Http2,
224+
&protocol.path(),
225+
rps,
226+
timestamp,
227+
http2::bench_all,
228+
)
229+
.await
230+
}
216231
}
217232
"web-socket" => {
218-
manage_protocol_dir(
219-
environment,
220-
Protocol::WebSocket,
221-
&protocol.path(),
222-
rps,
223-
timestamp,
224-
web_socket::bench_all,
225-
)
226-
.await
233+
if cfg!(feature = "web-socket") {
234+
manage_protocol_dir(
235+
environment,
236+
Protocol::WebSocket,
237+
&protocol.path(),
238+
rps,
239+
timestamp,
240+
web_socket::bench_all,
241+
)
242+
.await
243+
}
227244
}
228245
_ => {
229246
panic!("'{protocol_name}' is an unknown protocol");
@@ -232,18 +249,6 @@ async fn manage_protocols_dir(
232249
}
233250
}
234251

235-
fn manage_tests(
236-
mut generic_rp: ReportLine,
237-
rps: &mut Vec<ReportLine>,
238-
tests_params: impl IntoIterator<Item = (&'static str, BenchStats)>,
239-
) {
240-
for test_params in tests_params {
241-
generic_rp.implementation_specific(test_params);
242-
rps.push(generic_rp.clone());
243-
generic_rp.implementation_clear();
244-
}
245-
}
246-
247252
async fn podman_build(implementation: &str, protocol: Protocol) {
248253
handle_cmd_output(
249254
Command::new("podman").args([

evaluator/src/report_line.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl ReportLine {
3636

3737
pub(crate) fn implementation_specific(&mut self, (test, bench_stats): (&str, BenchStats)) {
3838
self.bench_stats = bench_stats;
39-
self.test.try_push_str(test).unwrap();
39+
self.test.push_str(test).unwrap();
4040
}
4141

4242
pub(crate) fn push_to_string(&self, string: &mut String) {

0 commit comments

Comments
 (0)