Skip to content

Commit 2e79e7e

Browse files
authoredDec 12, 2024
refactor(bench): remove historical benchmarks (#4940)
1 parent b16dd82 commit 2e79e7e

14 files changed

+29
-2205
lines changed
 

‎bindings/rust/bench/Cargo.toml

+3-32
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,14 @@ name = "bench"
33
version = "0.1.0"
44
edition = "2021"
55

6-
[features]
7-
default = ["rustls", "openssl"]
8-
rustls = ["dep:rustls", "rustls-pemfile"]
9-
openssl = ["dep:openssl"]
10-
memory = ["plotters", "crabgrind", "structopt"]
11-
historical-perf = ["plotters", "serde_json", "semver"]
12-
136
[dependencies]
147
s2n-tls = { path = "../s2n-tls" }
158
errno = "0.3"
169
libc = "0.2"
1710
strum = { version = "0.25", features = ["derive"] }
18-
rustls = { version = "0.23", optional = true }
19-
rustls-pemfile = { version = "2", optional = true }
20-
openssl = { version = "0.10", features = ["vendored"], optional = true }
21-
crabgrind = { version = "0.1", optional = true }
22-
structopt = { version = "0.3", optional = true }
23-
serde_json = { version = "1.0", optional = true }
24-
semver = { version = "1.0", optional = true }
25-
26-
[dependencies.plotters]
27-
version = "0.3"
28-
optional = true
29-
default-features = false
30-
features = ["all_series", "all_elements", "full_palette", "svg_backend"]
11+
rustls = { version = "0.23" }
12+
rustls-pemfile = { version = "2" }
13+
openssl = { version = "0.10", features = ["vendored"] }
3114

3215
[dev-dependencies]
3316
criterion = "0.5"
@@ -37,18 +20,6 @@ pprof = { version = "0.12", features = ["criterion", "flamegraph"] }
3720
env_logger = "0.10"
3821
log = "0.4"
3922

40-
[[bin]]
41-
name = "memory"
42-
required-features = ["memory"]
43-
44-
[[bin]]
45-
name = "graph_memory"
46-
required-features = ["memory"]
47-
48-
[[bin]]
49-
name = "graph_perf"
50-
required-features = ["historical-perf"]
51-
5223
[[bench]]
5324
name = "handshake"
5425
harness = false

‎bindings/rust/bench/README.md

+1-47
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All benchmarks are run in an idealized environment, using only a single thread a
88

99
```
1010
# generate rust bindings
11-
../generate.sh
11+
../generate.sh --skip-tests
1212
1313
# run all benchmarks
1414
cargo bench
@@ -36,37 +36,6 @@ Throughput benchmarks measure round-trip throughput with the client and server c
3636

3737
To generate flamegraphs, run `cargo bench --bench handshake --bench throughput -- --profile-time 5`, which profiles each benchmark for 5 seconds and stores the resulting flamegraph in `target/criterion/[bench-name]/[lib-name]/profile/flamegraph.svg`.
3838

39-
## Memory benchmarks
40-
41-
To run all memory benchmarks, run `scripts/bench-memory.sh`. Graphs of memory usage will be generated in `images/`.
42-
43-
Memory benchmark data is generated using the `memory` binary. Command line arguments can be given to `cargo run` or to the built executable located at `target/release/memory`. The usage is as follows:
44-
45-
```
46-
memory [(pair|client|server)] [(s2n-tls|rustls|openssl)] [--reuse-config (true|false)] [--shrink-buffers (true|false)]
47-
```
48-
49-
- `(pair|client|server)`: target to memory bench, defaults to `server`
50-
- `(s2n-tls|rustls|openssl)`: library to be benched, if unset benches all libraries
51-
- `--reuse-config`: if `true` (default), reuse configs between connections
52-
- `--shrink-buffers`: if `true` (default), shrink buffers owned by connections
53-
54-
To view a callgraph of memory usage, use [KCachegrind](https://github.com/KDE/kcachegrind) on `xtree.out` generated from memory benching:
55-
56-
```
57-
kcachegrind target/memory/<params>/<target>/<library>/xtree.out
58-
```
59-
60-
To view a flamegraph of memory usage, use [heaptrack](https://github.com/KDE/heaptrack) with `heaptrack_gui` also installed. Run heaptrack with the `memory` executable and target/library options:
61-
62-
```
63-
heaptrack target/release/memory (pair|client|server) (s2n-tls|rustls|openssl)
64-
```
65-
66-
## Historical benchmarks
67-
68-
To do historical benchmarks, run `scripts/bench-past.sh`. This will checkout old versions of s2n-tls back to v1.3.16 in `target/` and run benchmarks on those with the `historical-perf` feature, disabling Rustls and OpenSSL benches.
69-
7039
## PKI Structure
7140
```
7241
┌────root──────┐
@@ -88,21 +57,6 @@ The last version benched is v1.3.16, since before that, the s2n-tls Rust binding
8857

8958
v1.3.30-1.3.37 are not benched because of dependency issues when generating the Rust bindings. However, versions before and after are benched, so the overall trend in performance can still be seen without the data from these versions.
9059

91-
### Sample output
92-
93-
Because these benches take a longer time to generate (>30 min), we include the results from historical benching (as of v1.3.47) here.
94-
95-
Notes:
96-
- Two sets of parameters for the handshake couldn't be benched before 1.3.40, since security policies that negotiated those policies as their top choice did not exist before then.
97-
- There is no data from 1.3.30 to 1.3.37 because those versions have a dependency issue that cause the Rust bindings not to build. However, there is data before and after that period, so the performance for those versions can be inferred via interpolation.
98-
- The improvement in throughput in 1.3.28 was most likely caused by the addition of LTO to the default Rust bindings build.
99-
- Since the benches are run over a long time, noise on the machine can cause variability, and background processes can cause spikes.
100-
- The variability can be seen with throughput especially because it is calculated as the inverse of time taken.
101-
102-
![historical-perf-handshake](images/historical-perf-handshake.svg)
103-
104-
![historical-perf-throughput](images/historical-perf-throughput.svg)
105-
10660
## Implementation details
10761

10862
We use Rust bindings for s2n-tls and OpenSSL. All of our benchmarks are run in Rust on a single thread for consistency.

‎bindings/rust/bench/benches/handshake.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
#[cfg(feature = "openssl")]
5-
use bench::OpenSslConnection;
6-
#[cfg(feature = "rustls")]
7-
use bench::RustlsConnection;
84
use bench::{
95
harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup,
10-
Mode, S2NConnection, SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
6+
Mode, OpenSslConnection, RustlsConnection, S2NConnection, SigType, TlsConnPair, TlsConnection,
7+
PROFILER_FREQUENCY,
118
};
129
use criterion::{
1310
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
@@ -27,25 +24,20 @@ fn bench_handshake_for_library<T>(
2724
{
2825
// make configs before benching to reuse
2926
let crypto_config = CryptoConfig::new(CipherSuite::default(), kx_group, sig_type);
30-
let client_config = T::Config::make_config(Mode::Client, crypto_config, handshake_type);
31-
let server_config = T::Config::make_config(Mode::Server, crypto_config, handshake_type);
27+
let client_config =
28+
T::Config::make_config(Mode::Client, crypto_config, handshake_type).unwrap();
29+
let server_config =
30+
T::Config::make_config(Mode::Server, crypto_config, handshake_type).unwrap();
3231

3332
// generate all harnesses (TlsConnPair structs) beforehand so that benchmarks
3433
// only include negotiation and not config/connection initialization
3534
bench_group.bench_function(T::name(), |b| {
3635
b.iter_batched_ref(
3736
|| -> Result<TlsConnPair<T, T>, Box<dyn Error>> {
38-
if let (Ok(client_config), Ok(server_config)) =
39-
(client_config.as_ref(), server_config.as_ref())
40-
{
41-
let connected_buffer = ConnectedBuffer::default();
42-
let client =
43-
T::new_from_config(client_config, connected_buffer.clone_inverse())?;
44-
let server = T::new_from_config(server_config, connected_buffer)?;
45-
Ok(TlsConnPair::wrap(client, server))
46-
} else {
47-
Err("invalid configs".into())
48-
}
37+
let connected_buffer = ConnectedBuffer::default();
38+
let client = T::new_from_config(&client_config, connected_buffer.clone_inverse())?;
39+
let server = T::new_from_config(&server_config, connected_buffer)?;
40+
Ok(TlsConnPair::wrap(client, server))
4941
},
5042
|conn_pair| {
5143
// harnesses with certain parameters fail to initialize for
@@ -67,14 +59,12 @@ fn bench_handshake_with_params(
6759
sig_type: SigType,
6860
) {
6961
bench_handshake_for_library::<S2NConnection>(bench_group, handshake_type, kx_group, sig_type);
70-
#[cfg(feature = "rustls")]
7162
bench_handshake_for_library::<RustlsConnection>(
7263
bench_group,
7364
handshake_type,
7465
kx_group,
7566
sig_type,
7667
);
77-
#[cfg(feature = "openssl")]
7868
bench_handshake_for_library::<OpenSslConnection>(
7969
bench_group,
8070
handshake_type,

‎bindings/rust/bench/benches/throughput.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
#[cfg(feature = "openssl")]
54
use bench::OpenSslConnection;
6-
#[cfg(feature = "rustls")]
75
use bench::RustlsConnection;
86
use bench::{
97
harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup,
@@ -26,25 +24,20 @@ fn bench_throughput_for_library<T>(
2624
T::Config: TlsBenchConfig,
2725
{
2826
let crypto_config = CryptoConfig::new(cipher_suite, KXGroup::default(), SigType::default());
29-
let client_config = T::Config::make_config(Mode::Client, crypto_config, HandshakeType::default());
30-
let server_config = T::Config::make_config(Mode::Server, crypto_config, HandshakeType::default());
27+
let client_config =
28+
T::Config::make_config(Mode::Client, crypto_config, HandshakeType::default()).unwrap();
29+
let server_config =
30+
T::Config::make_config(Mode::Server, crypto_config, HandshakeType::default()).unwrap();
3131

3232
bench_group.bench_function(T::name(), |b| {
3333
b.iter_batched_ref(
3434
|| -> Result<TlsConnPair<T, T>, Box<dyn Error>> {
35-
if let (Ok(client_config), Ok(server_config)) =
36-
(client_config.as_ref(), server_config.as_ref())
37-
{
38-
let connected_buffer = ConnectedBuffer::default();
39-
let client =
40-
T::new_from_config(client_config, connected_buffer.clone_inverse())?;
41-
let server = T::new_from_config(server_config, connected_buffer)?;
42-
let mut conn_pair = TlsConnPair::wrap(client, server);
43-
conn_pair.handshake()?;
44-
Ok(conn_pair)
45-
} else {
46-
Err("invalid configs".into())
47-
}
35+
let connected_buffer = ConnectedBuffer::default();
36+
let client = T::new_from_config(&client_config, connected_buffer.clone_inverse())?;
37+
let server = T::new_from_config(&server_config, connected_buffer)?;
38+
let mut conn_pair = TlsConnPair::wrap(client, server);
39+
conn_pair.handshake()?;
40+
Ok(conn_pair)
4841
},
4942
|conn_pair| {
5043
if let Ok(conn_pair) = conn_pair {
@@ -68,13 +61,11 @@ pub fn bench_throughput_cipher_suites(c: &mut Criterion) {
6861
&mut shared_buf,
6962
cipher_suite,
7063
);
71-
#[cfg(feature = "rustls")]
7264
bench_throughput_for_library::<RustlsConnection>(
7365
&mut bench_group,
7466
&mut shared_buf,
7567
cipher_suite,
7668
);
77-
#[cfg(feature = "openssl")]
7869
bench_throughput_for_library::<OpenSslConnection>(
7970
&mut bench_group,
8071
&mut shared_buf,

0 commit comments

Comments
 (0)
Failed to load comments.