From 6e4704739d39a6875a3fb61a272b6e6fa9b4c2b6 Mon Sep 17 00:00:00 2001 From: Cameron Bytheway Date: Wed, 7 Feb 2024 09:58:48 -0700 Subject: [PATCH] shrink changes --- .github/workflows/qns.yml | 27 +++++++-------- Cargo.toml | 13 +++---- quic/s2n-quic-qns/Cargo.toml | 4 +-- quic/s2n-quic-qns/src/client.rs | 6 ---- quic/s2n-quic-qns/src/main.rs | 11 ------ quic/s2n-quic-qns/src/server.rs | 6 ---- quic/s2n-quic-qns/src/server/h09.rs | 14 ++++++++ quic/s2n-quic-qns/src/server/interop.rs | 45 +++++++++++++++++++++++-- scripts/perf/bin/s2n-quic | 4 +-- scripts/perf/bin/s2n-quic-null | 4 +-- scripts/perf/build | 2 +- 11 files changed, 80 insertions(+), 56 deletions(-) diff --git a/.github/workflows/qns.yml b/.github/workflows/qns.yml index d83fb94858..dee3539395 100644 --- a/.github/workflows/qns.yml +++ b/.github/workflows/qns.yml @@ -72,9 +72,10 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - profile: ["debug", "release"] + mode: ["debug", "release"] + # enable debug information env: - RUSTFLAGS: "--cfg s2n_internal_dev --cfg s2n_quic_dump_on_panic --cfg s2n_quic_unstable" + RUSTFLAGS: "-g --cfg s2n_internal_dev --cfg s2n_quic_dump_on_panic --cfg s2n_quic_unstable" steps: - uses: actions/checkout@v4 with: @@ -89,25 +90,22 @@ jobs: - uses: camshaft/rust-cache@v1 with: - key: ${{ matrix.profile }}-${{ env.RUSTFLAGS }} + key: ${{ matrix.mode }}-${{ env.RUSTFLAGS }} - name: Run cargo build - env: - QNS_PROFILE: ${{ matrix.profile == 'release' && '--profile=release-debug' || '' }} - working-directory: quic/s2n-quic-qns/ - run: | - cargo build --bin s2n-quic-qns $QNS_PROFILE + uses: actions-rs/cargo@v1.0.3 + with: + command: build + args: --bin s2n-quic-qns ${{ matrix.mode == 'release' && '--release' || '' }} - name: Prepare artifact - env: - QNS_PROFILE: ${{ matrix.profile == 'release' && 'release-debug' || 'debug' }} run: | mkdir -p s2n-quic-qns - cp target/$QNS_PROFILE/s2n-quic-qns s2n-quic-qns/s2n-quic-qns-${{ matrix.profile }} + cp target/${{ matrix.mode }}/s2n-quic-qns s2n-quic-qns/s2n-quic-qns-${{ matrix.mode }} - uses: actions/upload-artifact@v4 with: - name: s2n-quic-qns-${{ matrix.profile }} + name: s2n-quic-qns-${{ matrix.mode }} path: s2n-quic-qns/ interop: @@ -506,9 +504,8 @@ jobs: - name: Setup artifacts run: | - mkdir -p target/release-debug - mv target/release/s2n-quic-qns-release target/release-debug/s2n-quic-qns - chmod +x target/release-debug/s2n-quic-qns + mv target/release/s2n-quic-qns-release target/release/s2n-quic-qns + chmod +x target/release/s2n-quic-qns - name: Run script env: diff --git a/Cargo.toml b/Cargo.toml index 0644bd0903..aaabc3f130 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,11 @@ exclude = [ "tools", ] +[profile.release] +lto = true +codegen-units = 1 +incremental = false + [profile.bench] lto = true codegen-units = 1 @@ -22,11 +27,3 @@ inherits = "dev" opt-level = 3 incremental = false codegen-units = 1 - -[profile.release-debug] -inherits = "release" -debug-assertions = true -debug = true - -[profile.release-bench] -inherits = "bench" diff --git a/quic/s2n-quic-qns/Cargo.toml b/quic/s2n-quic-qns/Cargo.toml index 5a29529cf7..1c1abfa1b2 100644 --- a/quic/s2n-quic-qns/Cargo.toml +++ b/quic/s2n-quic-qns/Cargo.toml @@ -9,9 +9,7 @@ license = "Apache-2.0" publish = false [features] -default = ["interop", "perf"] -interop = [] -perf = [] +default = [] trace = ["s2n-quic-core/branch-tracing", "s2n-quic-core/probe-tracing", "s2n-quic-core/usdt"] xdp = ["s2n-quic/unstable-provider-io-xdp", "aya", "aya-log"] diff --git a/quic/s2n-quic-qns/src/client.rs b/quic/s2n-quic-qns/src/client.rs index 9b6824fa75..18f07dd082 100644 --- a/quic/s2n-quic-qns/src/client.rs +++ b/quic/s2n-quic-qns/src/client.rs @@ -1,18 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#[cfg(feature = "interop")] mod h09; -#[cfg(feature = "interop")] mod h3; -#[cfg(feature = "interop")] pub mod interop; -#[cfg(feature = "perf")] pub mod perf; -#[cfg(feature = "interop")] pub use interop::Interop; -#[cfg(feature = "perf")] pub use perf::Perf; use crate::{ diff --git a/quic/s2n-quic-qns/src/main.rs b/quic/s2n-quic-qns/src/main.rs index 4bd56affb9..230127ca7d 100644 --- a/quic/s2n-quic-qns/src/main.rs +++ b/quic/s2n-quic-qns/src/main.rs @@ -8,14 +8,11 @@ pub type Result = core::result::Result; mod client; mod congestion_control; -#[cfg(feature = "interop")] mod file; mod intercept; -#[cfg(feature = "interop")] mod interop; mod io; mod limits; -#[cfg(feature = "perf")] mod perf; mod runtime; mod server; @@ -68,31 +65,25 @@ fn main() { #[derive(Debug, StructOpt)] enum Arguments { - #[cfg(feature = "interop")] Interop(Interop), - #[cfg(feature = "perf")] Perf(Perf), } impl Arguments { pub fn run(&self) -> Result<()> { match self { - #[cfg(feature = "interop")] Self::Interop(subject) => subject.run(), - #[cfg(feature = "perf")] Self::Perf(subject) => subject.run(), } } } -#[cfg(feature = "interop")] #[derive(Debug, StructOpt)] enum Interop { Server(server::Interop), Client(client::Interop), } -#[cfg(feature = "interop")] impl Interop { pub fn run(&self) -> Result<()> { match self { @@ -102,14 +93,12 @@ impl Interop { } } -#[cfg(feature = "perf")] #[derive(Debug, StructOpt)] enum Perf { Server(server::Perf), Client(client::Perf), } -#[cfg(feature = "perf")] impl Perf { pub fn run(&self) -> Result<()> { match self { diff --git a/quic/s2n-quic-qns/src/server.rs b/quic/s2n-quic-qns/src/server.rs index 496c866100..80c9e59d0b 100644 --- a/quic/s2n-quic-qns/src/server.rs +++ b/quic/s2n-quic-qns/src/server.rs @@ -1,20 +1,14 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -#[cfg(feature = "interop")] mod h09; -#[cfg(feature = "interop")] mod h3; -#[cfg(feature = "interop")] pub mod interop; -#[cfg(feature = "perf")] pub mod perf; #[cfg(all(s2n_quic_unstable, feature = "unstable_client_hello"))] mod unstable; -#[cfg(feature = "interop")] pub use interop::Interop; -#[cfg(feature = "perf")] pub use perf::Perf; use crate::{ diff --git a/quic/s2n-quic-qns/src/server/h09.rs b/quic/s2n-quic-qns/src/server/h09.rs index de223bc003..43f64570c4 100644 --- a/quic/s2n-quic-qns/src/server/h09.rs +++ b/quic/s2n-quic-qns/src/server/h09.rs @@ -3,6 +3,7 @@ use crate::{ file::{abs_path, File}, + server::interop::MyConnectionContext, Result, }; use bytes::Bytes; @@ -19,6 +20,10 @@ pub(crate) async fn handle_connection(mut connection: Connection, www_dir: Arc

{ + let _ = connection.query_event_context_mut(|context: &mut MyConnectionContext| { + context.stream_requests += 1 + }); + let www_dir = www_dir.clone(); // spawn a task per stream tokio::spawn(async move { @@ -28,10 +33,19 @@ pub(crate) async fn handle_connection(mut connection: Connection, www_dir: Arc

{ + // the connection was closed without an error + let context = connection + .query_event_context(|context: &MyConnectionContext| *context) + .expect("query should execute"); + debug!("Final stats: {context:?}"); return; } Err(err) => { eprintln!("error while accepting stream: {err}"); + let context = connection + .query_event_context(|context: &MyConnectionContext| *context) + .expect("query should execute"); + debug!("Final stats: {context:?}"); return; } } diff --git a/quic/s2n-quic-qns/src/server/interop.rs b/quic/s2n-quic-qns/src/server/interop.rs index 318b3e9857..24b8b4e42a 100644 --- a/quic/s2n-quic-qns/src/server/interop.rs +++ b/quic/s2n-quic-qns/src/server/interop.rs @@ -8,7 +8,13 @@ use crate::{ server::{h09, h3}, tls, Result, }; -use s2n_quic::{provider::endpoint_limits, Server}; +use s2n_quic::{ + provider::{ + endpoint_limits, + event::{events, Subscriber}, + }, + Server, +}; use std::{ path::{Path, PathBuf}, sync::Arc, @@ -98,7 +104,10 @@ impl Interop { .with_io(io)? .with_endpoint_limits(endpoint_limits)? .with_limits(limits)? - .with_event(s2n_quic::provider::event::tracing::Subscriber::default())?; + .with_event(( + EventSubscriber, + s2n_quic::provider::event::tracing::Subscriber::default(), + ))?; // setup the packet interceptor if internal dev #[cfg(s2n_internal_dev)] @@ -136,3 +145,35 @@ fn is_supported_testcase(testcase: Testcase) -> bool { ConnectionMigration => true, } } + +#[derive(Debug, Clone, Copy)] +pub struct MyConnectionContext { + packet_sent: u64, + pub(crate) stream_requests: u64, +} + +pub struct EventSubscriber; + +impl Subscriber for EventSubscriber { + type ConnectionContext = MyConnectionContext; + + fn create_connection_context( + &mut self, + _meta: &events::ConnectionMeta, + _info: &events::ConnectionInfo, + ) -> Self::ConnectionContext { + MyConnectionContext { + packet_sent: 0, + stream_requests: 0, + } + } + + fn on_packet_sent( + &mut self, + context: &mut Self::ConnectionContext, + _meta: &events::ConnectionMeta, + _event: &events::PacketSent, + ) { + context.packet_sent += 1; + } +} diff --git a/scripts/perf/bin/s2n-quic b/scripts/perf/bin/s2n-quic index 806c01906f..86a15c174e 100755 --- a/scripts/perf/bin/s2n-quic +++ b/scripts/perf/bin/s2n-quic @@ -9,7 +9,7 @@ set -e case "$PS" in server*) - exec ../../target/release-debug/s2n-quic-qns \ + exec ../../target/release/s2n-quic-qns \ perf \ server \ --port $SERVER_PORT \ @@ -17,7 +17,7 @@ case "$PS" in --stats ;; client*) - exec ../../target/release-debug/s2n-quic-qns \ + exec ../../target/release/s2n-quic-qns \ perf \ client \ --receive "${DOWNLOAD_BYTES}" \ diff --git a/scripts/perf/bin/s2n-quic-null b/scripts/perf/bin/s2n-quic-null index 42d1259b1a..1dc11a22cf 100755 --- a/scripts/perf/bin/s2n-quic-null +++ b/scripts/perf/bin/s2n-quic-null @@ -9,7 +9,7 @@ set -e case "$PS" in server*) - exec ../../target/release-debug/s2n-quic-qns \ + exec ../../target/release/s2n-quic-qns \ perf \ server \ --port $SERVER_PORT \ @@ -18,7 +18,7 @@ case "$PS" in --stats ;; client*) - exec ../../target/release-debug/s2n-quic-qns \ + exec ../../target/release/s2n-quic-qns \ perf \ client \ --receive "${DOWNLOAD_BYTES}" \ diff --git a/scripts/perf/build b/scripts/perf/build index 91223afa74..e31b79d473 100755 --- a/scripts/perf/build +++ b/scripts/perf/build @@ -19,6 +19,6 @@ cargo \ +stable \ build \ --bin s2n-quic-qns \ - --profile release-debug \ + --profile bench \ --no-default-features \ --features perf