#[path = "common/mod.rs"]
mod shared;
use rustress::core::Config;
use shared::start_target;
fn reset_peak_rss() -> bool {
std::fs::write("/proc/self/clear_refs", "5").is_ok()
}
fn peak_rss_kb() -> Option<u64> {
let status = std::fs::read_to_string("/proc/self/status").ok()?;
for line in status.lines() {
if let Some(rest) = line.strip_prefix("VmHWM:") {
return rest
.trim()
.trim_end_matches(" kB")
.trim()
.parse::<u64>()
.ok();
}
}
None
}
async fn peak_at(max_concurrency: u32) -> (u32, Option<u64>) {
if !reset_peak_rss() {
eprintln!(" (cannot reset the peak-RSS watermark; figures will be cumulative)");
}
let base = start_target().await.expect("target starts");
let cfg = Config {
url: format!("{base}/big"),
target_rps: 400,
steady_dur_secs: 4,
timeout_secs: 20,
max_concurrency,
pool_max_idle_per_host: 1_000,
..Default::default()
};
shared::run_to_completion(cfg).await.expect("run completes");
(max_concurrency, peak_rss_kb())
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let Some(_) = peak_rss_kb() else {
println!("peak RSS is only readable from /proc; skipping");
return Ok(());
};
println!("8 MB response bodies, 400 RPS, 4s per run\n");
println!("NOTE: the target server runs in this same process, so these");
println!(" numbers include its own cost and read high.\n");
for ceiling in [8_u32, 32, 64] {
let (c, kb) = peak_at(ceiling).await;
match kb {
Some(kb) => println!(" max_concurrency {c:>4} peak RSS {kb:>7} KB"),
None => println!(" max_concurrency {c:>4} peak RSS unavailable"),
}
}
println!("\nRun your own at a different ceiling with --max-concurrency N.");
Ok(())
}