Measure cached Dosh attach fast path
ci / test (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
DuProcess
2026-06-12 22:45:13 -04:00
parent 3a38a9da80
commit 93374162ff
4 changed files with 94 additions and 38 deletions
+65 -33
View File
@@ -40,6 +40,10 @@ struct Args {
#[arg(long)]
no_cache: bool,
#[arg(long)]
warm_cache: bool,
#[arg(long)]
skip_ssh_baseline: bool,
#[arg(long)]
include_mosh: bool,
#[arg(long, default_value = "mosh")]
mosh: PathBuf,
@@ -51,6 +55,8 @@ struct Args {
assert_ssh_plus_ms: Option<f64>,
#[arg(long)]
assert_mosh_minus_ms: Option<f64>,
#[arg(long)]
assert_dosh_max_ms: Option<f64>,
}
fn main() -> Result<()> {
@@ -72,46 +78,25 @@ fn main() -> Result<()> {
} else {
None
};
if args.no_cache && args.warm_cache {
return Err(anyhow!("--warm-cache cannot be used with --no-cache"));
}
let dosh_label = if args.warm_cache {
let _ = time_dosh_attach(&client, &args, control_path)?;
"dosh_cached_attach_ms"
} else {
"dosh_attach_ms"
};
for _ in 0..args.iterations.max(1) {
if !args.local_auth {
if !args.local_auth && !args.skip_ssh_baseline {
let mut ssh = Command::new("ssh");
add_ssh_options(&mut ssh, &args, control_path);
ssh.arg(&args.server).arg("true");
ssh_times.push(time_command(&mut ssh)?);
}
let mut cmd = Command::new(&client);
cmd.arg("--attach-only")
.arg("--session")
.arg(&args.session)
.arg("--dosh-port")
.arg(args.dosh_port.to_string());
if let Some(host) = &args.dosh_host {
cmd.arg("--dosh-host").arg(host);
}
if args.local_auth {
cmd.arg("--local-auth").arg(&args.server);
} else {
cmd.arg("--ssh-port")
.arg(args.ssh_port.to_string())
.arg("--ssh-auth-command")
.arg(&args.ssh_auth_command);
if args.no_cache {
cmd.arg("--no-cache");
}
if let Some(key) = &args.ssh_key {
cmd.arg("--ssh-key").arg(key);
}
if let Some(known_hosts) = &args.ssh_known_hosts {
cmd.arg("--ssh-known-hosts").arg(known_hosts);
}
if let Some(control_path) = control_path {
cmd.arg("--ssh-control-path").arg(control_path);
}
cmd.arg(&args.server);
}
dosh_times.push(time_command(&mut cmd)?);
dosh_times.push(time_dosh_attach(&client, &args, control_path)?);
if args.include_mosh {
mosh_times.push(time_mosh_in_pty(&args)?);
@@ -126,7 +111,7 @@ fn main() -> Result<()> {
);
}
println!(
"dosh_attach_ms avg={:.2} samples={:?}",
"{dosh_label} avg={:.2} samples={:?}",
avg_ms(&dosh_times),
dosh_times
);
@@ -167,9 +152,56 @@ fn main() -> Result<()> {
}
println!("gate ok: dosh avg {dosh_avg:.2}ms + {margin:.2}ms <= mosh avg {mosh_avg:.2}ms");
}
if let Some(max_ms) = args.assert_dosh_max_ms {
let dosh_avg = avg_ms(&dosh_times);
if dosh_avg > max_ms {
return Err(anyhow!(
"{dosh_label} avg {dosh_avg:.2}ms exceeded max {max_ms:.2}ms"
));
}
println!("gate ok: {dosh_label} avg {dosh_avg:.2}ms <= {max_ms:.2}ms");
}
Ok(())
}
fn time_dosh_attach(
client: &PathBuf,
args: &Args,
control_path: Option<&PathBuf>,
) -> Result<Duration> {
let mut cmd = Command::new(client);
cmd.arg("--attach-only")
.arg("--session")
.arg(&args.session)
.arg("--dosh-port")
.arg(args.dosh_port.to_string());
if let Some(host) = &args.dosh_host {
cmd.arg("--dosh-host").arg(host);
}
if args.local_auth {
cmd.arg("--local-auth").arg(&args.server);
} else {
cmd.arg("--ssh-port")
.arg(args.ssh_port.to_string())
.arg("--ssh-auth-command")
.arg(&args.ssh_auth_command);
if args.no_cache {
cmd.arg("--no-cache");
}
if let Some(key) = &args.ssh_key {
cmd.arg("--ssh-key").arg(key);
}
if let Some(known_hosts) = &args.ssh_known_hosts {
cmd.arg("--ssh-known-hosts").arg(known_hosts);
}
if let Some(control_path) = control_path {
cmd.arg("--ssh-control-path").arg(control_path);
}
cmd.arg(&args.server);
}
time_command(&mut cmd)
}
fn add_ssh_options(cmd: &mut Command, args: &Args, control_path: Option<&PathBuf>) {
cmd.arg("-p").arg(args.ssh_port.to_string()).arg("-T");
if let Some(key) = &args.ssh_key {