Skip to content

Commit

Permalink
feat(s2n-quic-qns): add client perf implementation (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft authored Jun 3, 2022
1 parent b9a6c7d commit 6d41761
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 115 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/qns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,11 @@ jobs:
needs: [quinn, s2n-quic-qns]
strategy:
matrix:
tls: ["s2n-tls", "rustls"]
include:
- client: "quinn"
server: "s2n-quic"
- client: "s2n-quic"
server: "s2n-quic"

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -637,11 +638,11 @@ jobs:
run: |
set -e
mkdir -p target/perf/results
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 1000 0 ${{ matrix.server }} ${{ matrix.client }} ${{ matrix.tls }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 750 250 ${{ matrix.server }} ${{ matrix.client }} ${{ matrix.tls }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 500 500 ${{ matrix.server }} ${{ matrix.client }} ${{ matrix.tls }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 250 750 ${{ matrix.server }} ${{ matrix.client }} ${{ matrix.tls }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 0 1000 ${{ matrix.server }} ${{ matrix.client }} ${{ matrix.tls }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 1000 0 ${{ matrix.server }} ${{ matrix.client }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 750 250 ${{ matrix.server }} ${{ matrix.client }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 500 500 ${{ matrix.server }} ${{ matrix.client }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 250 750 ${{ matrix.server }} ${{ matrix.client }}
sudo env "PATH=$PATH" "SHELL=$SHELL" ./scripts/perf/test 0 1000 ${{ matrix.server }} ${{ matrix.client }}
sudo chown -R $(whoami) target/perf/results
- name: Prepare artifacts
Expand All @@ -652,7 +653,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: perf-${{ matrix.tls }}
name: perf-results-${{ matrix.server }}-${{ matrix.client }}
path: target/perf/results

perf-report:
Expand All @@ -661,15 +662,15 @@ jobs:
steps:
- uses: actions/checkout@v3

# add any additional perf tests here
- uses: actions/download-artifact@v3
with:
name: perf-rustls
path: ./perf-results/rustls

name: perf-results-s2n-quic-quinn
path: perf-results/
- uses: actions/download-artifact@v3
with:
name: perf-s2n-tls
path: ./perf-results/s2n-tls
name: perf-results-s2n-quic-s2n-quic
path: perf-results/

- name: Generate report
run: |
Expand Down
1 change: 1 addition & 0 deletions quic/s2n-quic-qns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bytes = { version = "1", default-features = false }
cfg-if = "1"
futures = "0.3"
http = "0.2"
humansize = "1"
openssl-sys = { version = "<= 0.9.68", features = ["vendored"] }
s2n-quic-core = { path = "../s2n-quic-core", features = ["testing"] }
s2n-quic-h3 = { path = "../s2n-quic-h3" }
Expand Down
6 changes: 4 additions & 2 deletions quic/s2n-quic-qns/etc/run_endpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ if [ "$QNS_MODE" == "interop" ]; then
fi
fi

SERVER_PARAMS+=" --tls $TLS"
CLIENT_PARAMS+=" --tls $TLS"
if [ "$QNS_MODE" == "interop" ]; then
SERVER_PARAMS+=" --tls $TLS"
CLIENT_PARAMS+=" --tls $TLS"
fi

if [ "$TEST_TYPE" == "MEASUREMENT" ] && [ -x "$(command -v s2n-quic-qns-release)" ]; then
echo "using optimized build"
Expand Down
2 changes: 1 addition & 1 deletion quic/s2n-quic-qns/src/client/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Interop {

let client = Client::builder()
.with_io(io)?
.with_event(event::tracing::Provider::default())?;
.with_event(event::tracing::Subscriber::default())?;
let client = match self.tls {
#[cfg(unix)]
TlsProviders::S2N => {
Expand Down
100 changes: 53 additions & 47 deletions quic/s2n-quic-qns/src/client/perf.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use crate::{tls, tls::TlsProviders, Result};
use crate::{perf, tls, Result};
use futures::future::try_join_all;
use s2n_quic::{
client,
provider::{event, io},
Client, Connection,
};
use s2n_quic::{client, provider::io, Client, Connection};
use std::path::PathBuf;
use structopt::StructOpt;

Expand Down Expand Up @@ -40,7 +36,17 @@ pub struct Perf {
local_ip: std::net::IpAddr,

#[structopt(long, default_value)]
tls: TlsProviders,
send: u64,

#[structopt(long, default_value)]
receive: u64,

#[structopt(flatten)]
limits: perf::Limits,

/// Logs statistics for the endpoint
#[structopt(long)]
stats: bool,
}

impl Perf {
Expand All @@ -60,40 +66,43 @@ impl Perf {
}
let connection = client.connect(connect).await?;

requests.push(handle_connection(connection));
requests.push(handle_connection(connection, self.send, self.receive));
}

try_join_all(requests).await?;
client.wait_idle().await?;

return Ok(());

async fn handle_connection(connection: Connection) -> Result<()> {
let (_handle, acceptor) = connection.split();
let (bidi, uni) = acceptor.split();
async fn handle_connection(
mut connection: Connection,
send: u64,
receive: u64,
) -> Result<()> {
if send == 0 && receive == 0 {
return Ok(());
}

let bidi = tokio::spawn(async move {
let _ = bidi;
// TODO implement requests
<Result<()>>::Ok(())
});
let stream = connection.open_bidirectional_stream().await?;
let (receive_stream, mut send_stream) = stream.split();

let uni = tokio::spawn(async move {
let _ = uni;
// TODO implement requests
let s = tokio::spawn(async move {
perf::write_stream_size(&mut send_stream, receive).await?;
perf::handle_send_stream(send_stream, send).await?;
<Result<()>>::Ok(())
});

let (bidi, uni) = futures::try_join!(bidi, uni)?;
bidi?;
uni?;
let r = tokio::spawn(perf::handle_receive_stream(receive_stream));

let (s, r) = tokio::try_join!(s, r)?;
s?;
r?;

Ok(())
}
}

fn client(&self) -> Result<Client> {
// TODO support specifying a local addr
let mut io_builder =
io::Default::builder().with_receive_address((self.local_ip, 0u16).into())?;

Expand All @@ -103,32 +112,29 @@ impl Perf {

let io = io_builder.build()?;

let tls = s2n_quic::provider::tls::default::Client::builder()
.with_certificate(tls::default::ca(self.ca.as_ref())?)?
.with_application_protocols(self.application_protocols.iter().map(String::as_bytes))?
.build()?;

let subscriber = perf::Subscriber::default();

if self.stats {
subscriber.spawn(core::time::Duration::from_secs(1));
}

let subscriber = (
subscriber,
s2n_quic::provider::event::tracing::Subscriber::default(),
);

let client = Client::builder()
.with_limits(self.limits.limits())?
.with_io(io)?
.with_event(event::disabled::Provider)?;
let client = match self.tls {
#[cfg(unix)]
TlsProviders::S2N => {
let tls = s2n_quic::provider::tls::s2n_tls::Client::builder()
.with_certificate(tls::s2n::ca(self.ca.as_ref())?)?
.with_application_protocols(
self.application_protocols.iter().map(String::as_bytes),
)?
.with_key_logging()?
.build()?;
client.with_tls(tls)?.start().unwrap()
}
TlsProviders::Rustls => {
let tls = s2n_quic::provider::tls::rustls::Client::builder()
.with_certificate(tls::rustls::ca(self.ca.as_ref())?)?
.with_application_protocols(
self.application_protocols.iter().map(String::as_bytes),
)?
.with_key_logging()?
.build()?;
client.with_tls(tls)?.start().unwrap()
}
};
.with_event(subscriber)?
.with_tls(tls)?
.start()
.unwrap();

Ok(client)
}
Expand Down
Loading

0 comments on commit 6d41761

Please sign in to comment.