Skip to content

Commit

Permalink
refactor(bench): remove non-generic connection logic (#4236)
Browse files Browse the repository at this point in the history
This commit shifts the TlsConnection trait to make it more generic. The
purpose of this is to allow more general usage of the TlsConnection
objects. In the future, "purpose-specific" logic will be implemented on
the Config type rather than the connection type.
  • Loading branch information
jmayclin authored Oct 19, 2023
1 parent fa58945 commit dec039d
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 222 deletions.
15 changes: 9 additions & 6 deletions bindings/rust/bench/benches/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bench::OpenSslConnection;
#[cfg(feature = "rustls")]
use bench::RustlsConnection;
use bench::{
CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, S2NConnection,
SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup,
Mode, S2NConnection, SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
};
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
Expand All @@ -16,16 +16,19 @@ use pprof::criterion::{Output, PProfProfiler};
use std::error::Error;
use strum::IntoEnumIterator;

fn bench_handshake_for_library<T: TlsConnection>(
fn bench_handshake_for_library<T>(
bench_group: &mut BenchmarkGroup<WallTime>,
handshake_type: HandshakeType,
kx_group: KXGroup,
sig_type: SigType,
) {
) where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
// make configs before benching to reuse
let crypto_config = CryptoConfig::new(CipherSuite::default(), kx_group, sig_type);
let client_config = T::make_config(Mode::Client, crypto_config, handshake_type);
let server_config = T::make_config(Mode::Server, crypto_config, handshake_type);
let client_config = T::Config::make_config(Mode::Client, crypto_config, handshake_type);
let server_config = T::Config::make_config(Mode::Server, crypto_config, handshake_type);

// generate all harnesses (TlsConnPair structs) beforehand so that benchmarks
// only include negotiation and not config/connection initialization
Expand Down
28 changes: 14 additions & 14 deletions bindings/rust/bench/benches/resumption.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use bench::{
CipherSuite, CryptoConfig, HandshakeType, KXGroup, S2NConnection, SigType, TlsConnPair,
TlsConnection,
harness::TlsBenchConfig, CipherSuite, CryptoConfig, HandshakeType, KXGroup, S2NConnection,
SigType, TlsConnPair, TlsConnection,
};
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
};

fn bench_handshake_pair<T: TlsConnection>(
bench_group: &mut BenchmarkGroup<WallTime>,
sig_type: SigType,
) {
fn bench_handshake_pair<T>(bench_group: &mut BenchmarkGroup<WallTime>, sig_type: SigType)
where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
// generate all harnesses (TlsConnPair structs) beforehand so that benchmarks
// only include negotiation and not config/connection initialization
for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] {
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| {
b.iter_batched_ref(
|| {
TlsConnPair::<T, T>::new(
TlsConnPair::<T, T>::new_bench_pair(
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type),
handshake,
Default::default(),
)
},
|conn_pair_res| {
Expand All @@ -33,18 +33,18 @@ fn bench_handshake_pair<T: TlsConnection>(
}
}

fn bench_handshake_server_1rtt<T: TlsConnection>(
bench_group: &mut BenchmarkGroup<WallTime>,
sig_type: SigType,
) {
fn bench_handshake_server_1rtt<T>(bench_group: &mut BenchmarkGroup<WallTime>, sig_type: SigType)
where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] {
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| {
b.iter_batched_ref(
|| {
let pair = TlsConnPair::<T, T>::new(
let pair = TlsConnPair::<T, T>::new_bench_pair(
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type),
handshake,
Default::default(),
)
.unwrap();
let (mut c, s) = pair.split();
Expand Down
15 changes: 9 additions & 6 deletions bindings/rust/bench/benches/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bench::OpenSslConnection;
#[cfg(feature = "rustls")]
use bench::RustlsConnection;
use bench::{
CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, S2NConnection,
SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup,
Mode, S2NConnection, SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
};
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
Expand All @@ -17,14 +17,17 @@ use pprof::criterion::{Output, PProfProfiler};
use std::error::Error;
use strum::IntoEnumIterator;

fn bench_throughput_for_library<T: TlsConnection>(
fn bench_throughput_for_library<T>(
bench_group: &mut BenchmarkGroup<WallTime>,
shared_buf: &mut [u8],
cipher_suite: CipherSuite,
) {
) where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
let crypto_config = CryptoConfig::new(cipher_suite, KXGroup::default(), SigType::default());
let client_config = T::make_config(Mode::Client, crypto_config, HandshakeType::default());
let server_config = T::make_config(Mode::Server, crypto_config, HandshakeType::default());
let client_config = T::Config::make_config(Mode::Client, crypto_config, HandshakeType::default());
let server_config = T::Config::make_config(Mode::Server, crypto_config, HandshakeType::default());

bench_group.bench_function(T::name(), |b| {
b.iter_batched_ref(
Expand Down
Loading

0 comments on commit dec039d

Please sign in to comment.