Skip to content

Commit c853db1

Browse files
committed
perf(isolation): add TCP and DNS benchmark harnesses
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 163a191 commit c853db1

8 files changed

Lines changed: 944 additions & 0 deletions

File tree

‎crates/openshell-sandbox/Cargo.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ repository.workspace = true
1414
name = "openshell-sandbox"
1515
path = "src/main.rs"
1616

17+
[[bin]]
18+
name = "openshell-seccomp-perf"
19+
path = "src/bin/seccomp-perf.rs"
20+
required-features = ["perf-harness"]
21+
1722
[features]
1823
perf-harness = []
1924

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Microbenchmark entry point for the production seccomp network broker.
5+
6+
use std::net::SocketAddr;
7+
8+
use clap::{Parser, Subcommand};
9+
use openshell_sandbox::perf::{BenchmarkOptions, Layer, Protocol};
10+
11+
#[derive(Debug, Parser)]
12+
#[command(
13+
about = "Measure native and seccomp-filtered socket performance",
14+
long_about = "Measure native and seccomp-filtered socket performance. UDP unconnected means destination-bearing SOCK_DGRAM traffic, not SOCK_RAW. General external UDP and SOCK_RAW are currently denied by the sandbox."
15+
)]
16+
struct Cli {
17+
/// Benchmark layer: native, filtered, or all.
18+
#[arg(long, default_value = "all", value_parser = ["native", "filtered", "all"])]
19+
layer: String,
20+
/// Protocol: tcp-connect, tcp-stream, udp-connected, udp-unconnected, or all.
21+
#[arg(
22+
long,
23+
default_value = "all",
24+
value_parser = ["tcp-connect", "tcp-stream", "udp-connected", "udp-unconnected", "all"]
25+
)]
26+
protocol: String,
27+
#[arg(long, default_value_t = 10_000)]
28+
iterations: u64,
29+
#[arg(long, default_value_t = 1_000)]
30+
warmup: u64,
31+
#[arg(long, default_value_t = 1)]
32+
concurrency: usize,
33+
#[arg(long, default_value_t = 64)]
34+
payload_bytes: usize,
35+
#[command(subcommand)]
36+
command: Option<Command>,
37+
}
38+
39+
#[derive(Debug, Subcommand)]
40+
enum Command {
41+
#[command(hide = true)]
42+
Worker {
43+
#[arg(long)]
44+
protocol: Protocol,
45+
#[arg(long)]
46+
target: SocketAddr,
47+
#[arg(long)]
48+
iterations: u64,
49+
#[arg(long)]
50+
warmup: u64,
51+
#[arg(long)]
52+
concurrency: usize,
53+
#[arg(long)]
54+
payload_bytes: usize,
55+
},
56+
}
57+
58+
fn main() -> anyhow::Result<()> {
59+
let cli = Cli::parse();
60+
if let Some(Command::Worker {
61+
protocol,
62+
target,
63+
iterations,
64+
warmup,
65+
concurrency,
66+
payload_bytes,
67+
}) = cli.command
68+
{
69+
let report = openshell_sandbox::perf::run_worker(
70+
protocol,
71+
target,
72+
iterations,
73+
warmup,
74+
concurrency,
75+
payload_bytes,
76+
)?;
77+
println!("{}", serde_json::to_string(&report)?);
78+
return Ok(());
79+
}
80+
81+
let options = BenchmarkOptions {
82+
layers: Layer::selection(&cli.layer)?,
83+
protocols: Protocol::selection(&cli.protocol)?,
84+
iterations: cli.iterations,
85+
warmup: cli.warmup,
86+
concurrency: cli.concurrency,
87+
payload_bytes: cli.payload_bytes,
88+
};
89+
for report in openshell_sandbox::perf::run(options)? {
90+
println!("{}", serde_json::to_string(&report)?);
91+
}
92+
Ok(())
93+
}

‎crates/openshell-sandbox/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub mod main_session;
1818
pub mod managed_children;
1919
#[cfg(target_os = "linux")]
2020
mod network_broker;
21+
#[cfg(all(target_os = "linux", feature = "perf-harness"))]
22+
pub mod perf;
2123
#[cfg(unix)]
2224
pub mod process;
2325
mod pty;

0 commit comments

Comments
 (0)