Benchmark restart time for dev server (vercel/turbo#244)
This implements a benchmark of restarting the devserver after successfully starting it and shutting it down. ## Question/TODO: Since our goal is metrics that don't scale with project size, should we assert that the small/medium benchmark results don't differ? Test Plan: `cargo bench -p next-dev`
This commit is contained in:
parent
80d0a86655
commit
7d79ce5029
1 changed files with 45 additions and 1 deletions
|
@ -120,6 +120,44 @@ fn bench_simple_file_change(c: &mut Criterion) {
|
|||
}
|
||||
}
|
||||
|
||||
fn bench_restart(c: &mut Criterion) {
|
||||
let mut g = c.benchmark_group("bench_restart");
|
||||
g.sample_size(10);
|
||||
g.measurement_time(Duration::from_secs(30));
|
||||
|
||||
let runtime = Runtime::new().unwrap();
|
||||
let browser = &runtime.block_on(create_browser());
|
||||
|
||||
for size in [100, 1_000] {
|
||||
g.bench_with_input(BenchmarkId::new("modules", size), &size, |b, &s| {
|
||||
let template_dir = build_test(s);
|
||||
b.to_async(Runtime::new().unwrap()).iter_batched_async(
|
||||
|| async {
|
||||
// Run a complete build, shut down, and test running it again
|
||||
let mut app = PreparedApp::new(template_dir.clone()).await;
|
||||
app.start_server();
|
||||
|
||||
let page = app.new_page(browser).await;
|
||||
page.close().await.unwrap();
|
||||
|
||||
let mut proc = app.stop_server();
|
||||
proc.wait().unwrap();
|
||||
app
|
||||
},
|
||||
|mut app| async {
|
||||
app.start_server();
|
||||
let page = app.new_page(browser).await;
|
||||
page.wait_for_navigation().await.unwrap();
|
||||
app.schedule_page_disposal(page);
|
||||
app
|
||||
},
|
||||
|app| app.dispose(),
|
||||
);
|
||||
remove_dir_all(&template_dir).unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
struct PreparedApp {
|
||||
test_dir: tempfile::TempDir,
|
||||
server: Option<(Child, String)>,
|
||||
|
@ -185,6 +223,12 @@ impl PreparedApp {
|
|||
page.close().await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn stop_server(&mut self) -> Child {
|
||||
let mut proc = self.server.take().expect("Server never started").0;
|
||||
proc.kill().unwrap();
|
||||
proc
|
||||
}
|
||||
}
|
||||
|
||||
fn command(bin: &str) -> Command {
|
||||
|
@ -337,6 +381,6 @@ impl<'a, 'b, A: AsyncExecutor> AsyncBencherExtension for AsyncBencher<'a, 'b, A,
|
|||
criterion_group!(
|
||||
name = benches;
|
||||
config = Criterion::default();
|
||||
targets = bench_startup, bench_simple_file_change
|
||||
targets = bench_startup, bench_simple_file_change, bench_restart
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in a new issue