Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bindings/bench): Prevent IO from going out of scope #5007

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Benchmarking

on:
pull_request:
branches: [main]
push:
branches: [main]
schedule:
Expand Down Expand Up @@ -29,23 +31,25 @@ jobs:
pip3 install "boto3[crt]"

- name: Generate
working-directory: bindings/rust
working-directory: bindings/rust/extended
run: ./generate.sh --skip-tests

- name: Benchmark
working-directory: bindings/rust/bench
working-directory: bindings/rust/standard/bench
run: cargo criterion --message-format json > criterion_output.log

- name: Configure AWS Credentials
if: github.event_name == 'push'
uses: aws-actions/[email protected]
with:
role-to-assume: arn:aws:iam::024603541914:role/GitHubOIDCRole
role-session-name: s2ntlsghabenchsession
aws-region: us-west-2

- name: Emit CloudWatch metrics
if: github.event_name == 'push'
run: |
python3 .github/bin/criterion_to_cloudwatch.py \
--criterion_output_path bindings/rust/bench/criterion_output.log \
--criterion_output_path bindings/rust/standard/bench/criterion_output.log \
--namespace s2n-tls-bench \
--platform ${{ runner.os }}-${{ runner.arch }}
11 changes: 5 additions & 6 deletions bindings/rust/standard/bench/benches/resumption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,18 @@ where
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| {
b.iter_batched_ref(
|| {
let pair = TlsConnPair::<T, T>::new_bench_pair(
let mut pair = TlsConnPair::<T, T>::new_bench_pair(
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type),
handshake,
)
.unwrap();
let (mut c, s) = pair.split();
c.handshake().unwrap();
s
pair.client_mut().handshake().unwrap();
pair
},
|server| {
|pair| {
// this represents the work that the server does during the
// first RTT
server.handshake().unwrap()
pair.server_mut().handshake().unwrap();
},
BatchSize::SmallInput,
)
Expand Down
20 changes: 15 additions & 5 deletions bindings/rust/standard/bench/src/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,20 @@ where
Self { client, server, io }
}

/// Take back ownership of individual connections in the TlsConnPair
pub fn split(self) -> (C, S) {
(self.client, self.server)
pub fn client(&self) -> &C {
&self.client
}

pub fn client_mut(&mut self) -> &mut C {
&mut self.client
}

pub fn server(&self) -> &S {
&self.server
}

pub fn server_mut(&mut self) -> &mut S {
&mut self.server
}

/// Run handshake on connections
Expand Down Expand Up @@ -386,8 +397,7 @@ mod tests {
TlsConnPair::<C, S>::new_bench_pair(CryptoConfig::default(), HandshakeType::Resumption)
.unwrap();
conn_pair.handshake().unwrap();
let (_, server) = conn_pair.split();
assert!(server.resumed_connection());
assert!(conn_pair.server().resumed_connection());
}

#[test]
Expand Down
Loading