Skip to content

Commit

Permalink
Delete suggest bench tmp dirs
Browse files Browse the repository at this point in the history
#6479 reduced the overhead for running benchmarks, but a side effect was
that it left directories filled with sqlite DBs in `/tmp`.  This makes
sure we delete those directories.
  • Loading branch information
bendk committed Jan 7, 2025
1 parent 920491f commit 7d70184
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
15 changes: 10 additions & 5 deletions components/suggest/benches/benchmark_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use criterion::{
criterion_group, criterion_main, measurement::Measurement, BatchSize, BenchmarkGroup, Criterion,
};
use criterion::{criterion_group, measurement::Measurement, BatchSize, BenchmarkGroup, Criterion};
use std::sync::Once;
use suggest::benchmarks::{geoname, ingest, query, BenchmarkWithInput};
use suggest::benchmarks::{cleanup, geoname, ingest, query, BenchmarkWithInput};

pub fn geoname(c: &mut Criterion) {
setup_viaduct();
Expand Down Expand Up @@ -55,4 +53,11 @@ fn setup_viaduct() {
}

criterion_group!(benches, geoname, ingest, query);
criterion_main!(benches);

fn main() {
benches();
criterion::Criterion::default()
.configure_from_args()
.final_summary();
cleanup();
}
19 changes: 13 additions & 6 deletions components/suggest/src/benchmarks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
path::PathBuf,
sync::{
atomic::{AtomicU32, Ordering},
OnceLock,
Mutex,
},
};
use tempfile::TempDir;
Expand Down Expand Up @@ -64,14 +64,16 @@ fn unique_db_filename() -> String {
format!("db{}.sqlite", COUNTER.fetch_add(1, Ordering::Relaxed))
}

// Create a "starter" store that will do an initial ingest, and then
// initialize every returned store with a copy of its DB so that each one
// doesn't need to reingest.
static STARTER: Mutex<Option<(TempDir, PathBuf)>> = Mutex::new(None);

/// Creates a new store that will contain all provider data currently in remote
/// settings.
fn new_store() -> SuggestStore {
// Create a "starter" store that will do an initial ingest, and then
// initialize every returned store with a copy of its DB so that each one
// doesn't need to reingest.
static STARTER: OnceLock<(TempDir, PathBuf)> = OnceLock::new();
let (starter_dir, starter_db_path) = STARTER.get_or_init(|| {
let mut starter = STARTER.lock().unwrap();
let (starter_dir, starter_db_path) = starter.get_or_insert_with(|| {
let temp_dir = tempfile::tempdir().unwrap();
let db_path = temp_dir.path().join(unique_db_filename());
let store =
Expand All @@ -87,3 +89,8 @@ fn new_store() -> SuggestStore {
std::fs::copy(starter_db_path, &db_path).expect("Error copying starter DB file");
SuggestStore::new(&db_path.to_string_lossy(), None).expect("Error building store")
}

/// Cleanup the temp directory created for SuggestStore instances used in the benchmarks.
pub fn cleanup() {
*STARTER.lock().unwrap() = None;
}

0 comments on commit 7d70184

Please sign in to comment.