Skip to content

Commit

Permalink
shrink changes
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Feb 7, 2024
1 parent 336a8dd commit 6e47047
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 56 deletions.
27 changes: 12 additions & 15 deletions .github/workflows/qns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/[email protected]
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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ exclude = [
"tools",
]

[profile.release]
lto = true
codegen-units = 1
incremental = false

[profile.bench]
lto = true
codegen-units = 1
Expand All @@ -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"
4 changes: 1 addition & 3 deletions quic/s2n-quic-qns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 0 additions & 6 deletions quic/s2n-quic-qns/src/client.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
11 changes: 0 additions & 11 deletions quic/s2n-quic-qns/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ pub type Result<T, E = Error> = core::result::Result<T, E>;

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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions quic/s2n-quic-qns/src/server.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
14 changes: 14 additions & 0 deletions quic/s2n-quic-qns/src/server/h09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::{
file::{abs_path, File},
server::interop::MyConnectionContext,
Result,
};
use bytes::Bytes;
Expand All @@ -19,6 +20,10 @@ pub(crate) async fn handle_connection(mut connection: Connection, www_dir: Arc<P
loop {
match connection.accept_bidirectional_stream().await {
Ok(Some(stream)) => {
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 {
Expand All @@ -28,10 +33,19 @@ pub(crate) async fn handle_connection(mut connection: Connection, www_dir: Arc<P
});
}
Ok(None) => {
// 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;
}
}
Expand Down
45 changes: 43 additions & 2 deletions quic/s2n-quic-qns/src/server/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions scripts/perf/bin/s2n-quic
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ set -e

case "$PS" in
server*)
exec ../../target/release-debug/s2n-quic-qns \
exec ../../target/release/s2n-quic-qns \
perf \
server \
--port $SERVER_PORT \
--max-mtu 16000 \
--stats
;;
client*)
exec ../../target/release-debug/s2n-quic-qns \
exec ../../target/release/s2n-quic-qns \
perf \
client \
--receive "${DOWNLOAD_BYTES}" \
Expand Down
4 changes: 2 additions & 2 deletions scripts/perf/bin/s2n-quic-null
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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}" \
Expand Down
2 changes: 1 addition & 1 deletion scripts/perf/build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ cargo \
+stable \
build \
--bin s2n-quic-qns \
--profile release-debug \
--profile bench \
--no-default-features \
--features perf

0 comments on commit 6e47047

Please sign in to comment.