Skip to content

Commit

Permalink
benchmarks: make evaluation benchmark configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Wünsche committed Jan 24, 2024
1 parent 8f18993 commit ed6779c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 34 deletions.
8 changes: 4 additions & 4 deletions betree/haura-benchmarks/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ function tiered() {
}

function scientific_evaluation() {
export BETREE__ALLOC_STRATEGY='[[0],[1],[],[]]'
run "$RUN_IDENT" scientific_evaluation_id_alloc evaluation-read 30
# Invocation: <Evaluation Length s> <Object Size in bytes> <Samples> <Min. Sample Size> <Max. Sample Size>
run "$RUN_IDENT" random_evaluation_read evaluation-read 30 $((25 * 1024 * 1024 * 1024)) $((8192)) $((1 * 1024)) $((12 * 1024 * 1024))
}

function evaluation_rw() {
export BETREE__ALLOC_STRATEGY='[[0],[1],[],[]]'
run "$RUN_IDENT" file_system_three evaluation-rw
# Invocation: <Evaluation Length s> <Object Size in bytes> <Samples> <Min. Sample Size> <Max. Sample Size>
run "$RUN_IDENT" random_evaluation_rw evaluation-rw 30 $((25 * 1024 * 1024 * 1024)) $((8192)) $((1 * 1024)) $((12 * 1024 * 1024))
}

function filesystem_zip() {
Expand Down
44 changes: 39 additions & 5 deletions betree/haura-benchmarks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ enum Mode {
Checkpoints,
Filesystem,
FilesystemZip {
path: PathBuf
path: PathBuf,
},
EvaluationRead {
#[structopt(default_value = "120")]
runtime: u64,
size: u64,
samples: u64,
min_size: u64,
max_size: u64,
},
EvaluationRW {
#[structopt(default_value = "120")]
runtime: u64,
size: u64,
samples: u64,
min_size: u64,
max_size: u64,
},
Zip {
n_clients: u32,
Expand Down Expand Up @@ -83,14 +91,40 @@ fn run_all(mode: Mode) -> Result<(), Box<dyn Error>> {
filesystem_zip::run(client, path)?;
control.database.write().sync()?;
}
Mode::EvaluationRead { runtime } => {
Mode::EvaluationRead {
runtime,
size,
samples,
min_size,
max_size,
} => {
let client = control.client(0, b"scientific_evaluation");
scientific_evaluation::run_read(client, runtime)?;
let config = scientific_evaluation::EvaluationConfig {
runtime,
size,
samples,
min_size,
max_size,
};
scientific_evaluation::run_read(client, config)?;
control.database.write().sync()?;
}
Mode::EvaluationRW { runtime } => {
Mode::EvaluationRW {
runtime,
size,
samples,
min_size,
max_size,
} => {
let client = control.client(0, b"scientific_evaluation");
scientific_evaluation::run_read_write(client, runtime)?;
let config = scientific_evaluation::EvaluationConfig {
runtime,
size,
samples,
min_size,
max_size,
};
scientific_evaluation::run_read_write(client, config)?;
control.database.write().sync()?;
}
Mode::Zip {
Expand Down
55 changes: 30 additions & 25 deletions betree/haura-benchmarks/src/scientific_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,85 @@
use betree_perf::*;
use betree_storage_stack::StoragePreference;
use rand::Rng;
use std::{error::Error, io::{Write, Seek}};
use std::{
error::Error,
io::{Seek, Write},
};

const OBJECT_SIZE: u64 = 25 * 1024 * 1024 * 1024;
const MIN_FETCH_SIZE: u64 = 1 * 1024;
const MAX_FETCH_SIZE: u64 = 12 * 1024 * 1024;
const N_POSITIONS: u64 = 1024; // E(sum N_POSITIONS_size) = 3GiB
const OBJ_NAME: &[u8] = b"important_research";

fn gen_positions(client: &mut Client) -> Vec<(u64, u64)> {
pub struct EvaluationConfig {
pub runtime: u64,
pub size: u64,
pub samples: u64,
pub min_size: u64,
pub max_size: u64,
}

fn gen_positions(client: &mut Client, config: &EvaluationConfig) -> Vec<(u64, u64)> {
let mut positions = vec![];
for _ in 0..N_POSITIONS {
let start = client.rng.gen_range(0..OBJECT_SIZE);
let length = client.rng.gen_range(MIN_FETCH_SIZE..MAX_FETCH_SIZE);
positions.push((
start,
length.clamp(0, OBJECT_SIZE.saturating_sub(start)),
));
for _ in 0..config.samples {
let start = client.rng.gen_range(0..config.size);
let length = client.rng.gen_range(config.min_size..config.max_size);
positions.push((start, length.clamp(0, config.size.saturating_sub(start))));
}
positions
}

fn prepare_store(client: &mut Client) -> Result<(), Box<dyn Error>> {
fn prepare_store(client: &mut Client, config: &EvaluationConfig) -> Result<(), Box<dyn Error>> {
let start = std::time::Instant::now();
let (obj, _info) = client
.object_store
.open_or_create_object_with_pref(b"important_research", StoragePreference::SLOW)?;
let mut cursor = obj.cursor_with_pref(StoragePreference::SLOW);

with_random_bytes(&mut client.rng, OBJECT_SIZE, 8 * 1024 * 1024, |b| {
with_random_bytes(&mut client.rng, config.size, 8 * 1024 * 1024, |b| {
cursor.write_all(b)
})?;
println!("Initial write took {}s", start.elapsed().as_secs());
client.sync().expect("Failed to sync database");
Ok(())
}

pub fn run_read(mut client: Client, runtime: u64) -> Result<(), Box<dyn Error>> {
pub fn run_read(mut client: Client, config: EvaluationConfig) -> Result<(), Box<dyn Error>> {
println!("running scientific_evaluation");
// Generate positions to read
let positions = gen_positions(&mut client);
prepare_store(&mut client)?;
let positions = gen_positions(&mut client, &config);
prepare_store(&mut client, &config)?;

let (obj, _info) = client
.object_store
.open_object_with_info(OBJ_NAME)?
.expect("Object was just created, but can't be opened!");

let start = std::time::Instant::now();
let mut buf = vec![0; MAX_FETCH_SIZE as usize];
let mut buf = vec![0; config.max_size as usize];
let f = std::fs::OpenOptions::new()
.write(true)
.create(true)
.open("evaluation_read.csv")?;
let mut w = std::io::BufWriter::new(f);
w.write_all(b"offset,size,latency_ns\n")?;

for (pos, len) in positions.iter().cycle() {
// Read data as may be done in some evaluation where only parts of a
// database file are read in.
let t = std::time::Instant::now();
obj.read_at(&mut buf[..*len as usize], *pos).unwrap();
w.write_fmt(format_args!("{pos},{len},{}", t.elapsed().as_nanos()))?;
if start.elapsed().as_secs() >= runtime {
if start.elapsed().as_secs() >= config.runtime {
break;
}
}
w.flush()?;
Ok(())
}

pub fn run_read_write(mut client: Client, runtime: u64) -> Result<(), Box<dyn Error>> {
pub fn run_read_write(mut client: Client, config: EvaluationConfig) -> Result<(), Box<dyn Error>> {
println!("running scientific_evaluation");
// Generate positions to read
let positions = gen_positions(&mut client);
prepare_store(&mut client)?;
let positions = gen_positions(&mut client, &config);
prepare_store(&mut client, &config)?;

let (obj, _info) = client
.object_store
Expand All @@ -85,7 +90,7 @@ pub fn run_read_write(mut client: Client, runtime: u64) -> Result<(), Box<dyn Er
let mut cursor = obj.cursor();

let start = std::time::Instant::now();
let mut buf = vec![0; MAX_FETCH_SIZE as usize];
let mut buf = vec![0; config.max_size as usize];
let f = std::fs::OpenOptions::new()
.write(true)
.create(true)
Expand All @@ -107,7 +112,7 @@ pub fn run_read_write(mut client: Client, runtime: u64) -> Result<(), Box<dyn Er
})?;
w.write_fmt(format_args!("{pos},{len},{},w", t.elapsed().as_nanos()))?;
}
if start.elapsed().as_secs() >= runtime {
if start.elapsed().as_secs() >= config.runtime {
break;
}
}
Expand Down

0 comments on commit ed6779c

Please sign in to comment.