Skip to content

Add compilation benchmark timeout #1652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ semver = "1.0"
reqwest = { version = "0.11", features = ["json"] }
xz2 = "0.1.3"
tar = "0.4"
tokio = { version = "1.6", features = ["rt"] }
tokio = { version = "1.6", features = ["rt", "process"] }
database = { path = "../database" }
intern = { path = "../intern" }
futures = "0.3.5"
Expand Down
33 changes: 27 additions & 6 deletions collector/src/bin/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ use std::cmp::Ordering;
use std::ffi::OsStr;
use std::fs;
use std::fs::File;
use std::future::Future;
use std::io::BufWriter;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process;
use std::process::{Command, Stdio};
use std::time::Duration;
use std::{str, time::Instant};
use tokio::runtime::Runtime;

Expand All @@ -34,6 +36,7 @@ use collector::runtime::{
use collector::toolchain::{
create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain,
};
use collector::utils::wait_for_future;

fn n_normal_benchmarks_remaining(n: usize) -> String {
let suffix = if n == 1 { "" } else { "s" };
Expand Down Expand Up @@ -262,7 +265,13 @@ fn profile(
let benchmark_id = format!("{} ({}/{})", benchmark.name, i + 1, benchmarks.len());
eprintln!("Executing benchmark {benchmark_id}");
let mut processor = ProfileProcessor::new(profiler, out_dir, &toolchain.id);
let result = benchmark.measure(&mut processor, profiles, scenarios, toolchain, Some(1));
let result = wait_for_future(benchmark.measure(
&mut processor,
profiles,
scenarios,
toolchain,
Some(1),
));
eprintln!("Finished benchmark {benchmark_id}");

if let Err(ref s) = result {
Expand Down Expand Up @@ -611,6 +620,7 @@ fn main_result() -> anyhow::Result<i32> {
builder
.worker_threads(1)
.max_blocking_threads(1)
.enable_time()
.enable_io();
let mut rt = builder.build().expect("built runtime");

Expand Down Expand Up @@ -1077,6 +1087,18 @@ fn bench_published_artifact(
)
}

const COMPILE_BENCHMARK_TIMEOUT: Duration = Duration::from_secs(60 * 30);

async fn with_timeout<F: Future<Output = anyhow::Result<()>>>(fut: F) -> anyhow::Result<()> {
match tokio::time::timeout(COMPILE_BENCHMARK_TIMEOUT, fut).await {
Ok(res) => res,
Err(_) => Err(anyhow::anyhow!(
"Benchmark timeouted in {} seconds",
COMPILE_BENCHMARK_TIMEOUT.as_secs()
)),
}
}

/// Perform compile benchmarks.
fn bench_compile(
rt: &mut Runtime,
Expand Down Expand Up @@ -1121,7 +1143,6 @@ fn bench_compile(
print_intro();

let mut processor = BenchProcessor::new(
rt,
tx.conn(),
benchmark_name,
&shared.artifact_id,
Expand Down Expand Up @@ -1157,13 +1178,14 @@ fn bench_compile(
)
},
&|processor| {
benchmark.measure(
rt.block_on(with_timeout(benchmark.measure(
processor,
&config.profiles,
&config.scenarios,
&shared.toolchain,
config.iterations,
)
)))
.with_context(|| anyhow::anyhow!("Cannot compile {}", benchmark.name))
},
)
}
Expand All @@ -1175,8 +1197,7 @@ fn bench_compile(
Category::Primary,
&|| eprintln!("Special benchmark commencing (due to `--bench-rustc`)"),
&|processor| {
processor
.measure_rustc(&shared.toolchain)
rt.block_on(with_timeout(processor.measure_rustc(&shared.toolchain)))
.context("measure rustc")
},
);
Expand Down
23 changes: 15 additions & 8 deletions collector/src/compile/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::compile::benchmark::profile::Profile;
use crate::compile::benchmark::scenario::Scenario;
use crate::compile::execute::{CargoProcess, Processor};
use crate::toolchain::Toolchain;
use crate::utils::wait_for_future;
use anyhow::{bail, Context};
use log::debug;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -189,7 +190,7 @@ impl Benchmark {
}

/// Run a specific benchmark under a processor + profiler combination.
pub fn measure(
pub async fn measure(
&self,
processor: &mut dyn Processor,
profiles: &[Profile],
Expand Down Expand Up @@ -261,9 +262,11 @@ impl Benchmark {
for (profile, prep_dir) in &profile_dirs {
let server = server.clone();
let thread = s.spawn::<_, anyhow::Result<()>>(move || {
self.mk_cargo_process(toolchain, prep_dir.path(), *profile)
.jobserver(server)
.run_rustc(false)?;
wait_for_future(
self.mk_cargo_process(toolchain, prep_dir.path(), *profile)
.jobserver(server)
.run_rustc(false),
)?;
Ok(())
});
threads.push(thread);
Expand Down Expand Up @@ -310,7 +313,8 @@ impl Benchmark {
if scenarios.contains(&Scenario::Full) {
self.mk_cargo_process(toolchain, cwd, profile)
.processor(processor, Scenario::Full, "Full", None)
.run_rustc(true)?;
.run_rustc(true)
.await?;
}

// Rustdoc does not support incremental compilation
Expand All @@ -321,15 +325,17 @@ impl Benchmark {
self.mk_cargo_process(toolchain, cwd, profile)
.incremental(true)
.processor(processor, Scenario::IncrFull, "IncrFull", None)
.run_rustc(true)?;
.run_rustc(true)
.await?;
}

// An incremental build with no changes (fastest incremental case).
if scenarios.contains(&Scenario::IncrUnchanged) {
self.mk_cargo_process(toolchain, cwd, profile)
.incremental(true)
.processor(processor, Scenario::IncrUnchanged, "IncrUnchanged", None)
.run_rustc(true)?;
.run_rustc(true)
.await?;
}

if scenarios.contains(&Scenario::IncrPatched) {
Expand All @@ -348,7 +354,8 @@ impl Benchmark {
&scenario_str,
Some(patch),
)
.run_rustc(true)?;
.run_rustc(true)
.await?;
}
}
}
Expand Down
Loading