parent
e1c8da49a2
commit
728a5dadf4
@ -1,82 +1,119 @@ |
|||||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; |
use criterion::{criterion_group, criterion_main, Criterion, Throughput}; |
||||||
use oxigraph::model::{Dataset, Graph, GraphName, NamedNode, Quad, Triple}; |
use oxhttp::model::{Method, Request, Status}; |
||||||
|
use oxigraph::io::GraphFormat; |
||||||
|
use oxigraph::model::GraphNameRef; |
||||||
|
use oxigraph::sparql::{Query, QueryResults, Update}; |
||||||
use oxigraph::store::Store; |
use oxigraph::store::Store; |
||||||
use rand::random; |
use std::fs::File; |
||||||
|
use std::io::{BufRead, BufReader, Cursor, Read}; |
||||||
|
use std::path::Path; |
||||||
|
|
||||||
criterion_group!( |
fn store_load(c: &mut Criterion) { |
||||||
store_load, |
let mut data = Vec::new(); |
||||||
graph_load_bench, |
read_data("explore-1000.nt.zst") |
||||||
dataset_load_bench, |
.read_to_end(&mut data) |
||||||
sled_load_bench |
.unwrap(); |
||||||
); |
|
||||||
|
|
||||||
criterion_main!(store_load); |
let mut group = c.benchmark_group("store load"); |
||||||
|
group.throughput(Throughput::Bytes(data.len() as u64)); |
||||||
fn graph_load_bench(c: &mut Criterion) { |
|
||||||
let mut group = c.benchmark_group("graph"); |
|
||||||
group.nresamples(10); |
|
||||||
group.sample_size(10); |
group.sample_size(10); |
||||||
for size in [100, 1_000, 10_000] { |
group.bench_function("load BSBM explore 1000", |b| { |
||||||
group.throughput(Throughput::Elements(size as u64)); |
b.iter(|| { |
||||||
let triples: Vec<_> = create_quads(size).into_iter().map(Triple::from).collect(); |
let store = Store::new().unwrap(); |
||||||
group.bench_function(BenchmarkId::from_parameter(size), |b| { |
store |
||||||
b.iter(|| triples.iter().collect::<Graph>()); |
.load_graph( |
||||||
}); |
Cursor::new(&data), |
||||||
} |
GraphFormat::NTriples, |
||||||
group.finish(); |
GraphNameRef::DefaultGraph, |
||||||
|
None, |
||||||
|
) |
||||||
|
.unwrap(); |
||||||
|
}) |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
fn dataset_load_bench(c: &mut Criterion) { |
fn store_query_and_update(c: &mut Criterion) { |
||||||
let mut group = c.benchmark_group("dataset"); |
let mut data = Vec::new(); |
||||||
group.nresamples(10); |
read_data("explore-1000.nt.zst") |
||||||
group.sample_size(10); |
.read_to_end(&mut data) |
||||||
for size in [100, 1_000, 10_000] { |
.unwrap(); |
||||||
group.throughput(Throughput::Elements(size as u64)); |
let store = Store::new().unwrap(); |
||||||
let quads = create_quads(size); |
store |
||||||
group.bench_function(BenchmarkId::from_parameter(size), |b| { |
.load_graph( |
||||||
b.iter(|| quads.iter().collect::<Dataset>()); |
Cursor::new(&data), |
||||||
}); |
GraphFormat::NTriples, |
||||||
} |
GraphNameRef::DefaultGraph, |
||||||
group.finish(); |
None, |
||||||
} |
) |
||||||
|
.unwrap(); |
||||||
|
let operations = read_data("mix-exploreAndUpdate-1000.tsv.zst") |
||||||
|
.lines() |
||||||
|
.map(|l| { |
||||||
|
let l = l.unwrap(); |
||||||
|
let mut parts = l.trim().split('\t'); |
||||||
|
let kind = parts.next().unwrap(); |
||||||
|
let operation = parts.next().unwrap(); |
||||||
|
match kind { |
||||||
|
"query" => Operation::Query(Query::parse(operation, None).unwrap()), |
||||||
|
"update" => Operation::Update(Update::parse(operation, None).unwrap()), |
||||||
|
_ => panic!("Unexpected operation kind {}", kind), |
||||||
|
} |
||||||
|
}) |
||||||
|
.collect::<Vec<_>>(); |
||||||
|
|
||||||
fn sled_load_bench(c: &mut Criterion) { |
let mut group = c.benchmark_group("store operations"); |
||||||
let mut group = c.benchmark_group("sled"); |
group.throughput(Throughput::Elements(operations.len() as u64)); |
||||||
group.nresamples(10); |
|
||||||
group.sample_size(10); |
group.sample_size(10); |
||||||
for size in [100, 1_000, 10_000] { |
group.bench_function("BSBM explore 1000 queryAndUpdate", |b| { |
||||||
group.throughput(Throughput::Elements(size as u64)); |
b.iter(|| { |
||||||
let quads = create_quads(size); |
for operation in &operations { |
||||||
group.bench_function(BenchmarkId::from_parameter(size), |b| { |
match operation { |
||||||
b.iter(|| { |
Operation::Query(q) => match store.query(q.clone()).unwrap() { |
||||||
let store = Store::new().unwrap(); |
QueryResults::Boolean(_) => (), |
||||||
for quad in &quads { |
QueryResults::Solutions(s) => { |
||||||
store.insert(quad).unwrap(); |
for s in s { |
||||||
|
s.unwrap(); |
||||||
|
} |
||||||
|
} |
||||||
|
QueryResults::Graph(g) => { |
||||||
|
for t in g { |
||||||
|
t.unwrap(); |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
Operation::Update(u) => store.update(u.clone()).unwrap(), |
||||||
} |
} |
||||||
}); |
} |
||||||
}); |
}) |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
criterion_group!(store, store_query_and_update, store_load); |
||||||
|
|
||||||
|
criterion_main!(store); |
||||||
|
|
||||||
|
fn read_data(file: &str) -> impl BufRead { |
||||||
|
if !Path::new(file).exists() { |
||||||
|
let mut client = oxhttp::Client::new(); |
||||||
|
client.set_redirection_limit(5); |
||||||
|
let url = format!( |
||||||
|
"https://github.com/Tpt/bsbm-tools/releases/download/v0.2/{}", |
||||||
|
file |
||||||
|
); |
||||||
|
let request = Request::builder(Method::GET, url.parse().unwrap()).build(); |
||||||
|
let response = client.request(request).unwrap(); |
||||||
|
assert_eq!( |
||||||
|
response.status(), |
||||||
|
Status::OK, |
||||||
|
"{}", |
||||||
|
response.into_body().to_string().unwrap() |
||||||
|
); |
||||||
|
std::io::copy(&mut response.into_body(), &mut File::create(file).unwrap()).unwrap(); |
||||||
} |
} |
||||||
group.finish(); |
BufReader::new(zstd::Decoder::new(File::open(file).unwrap()).unwrap()) |
||||||
} |
} |
||||||
|
|
||||||
fn create_quads(size: u64) -> Vec<Quad> { |
enum Operation { |
||||||
(0..size) |
Query(Query), |
||||||
.map(|_| { |
Update(Update), |
||||||
Quad::new( |
|
||||||
NamedNode::new_unchecked(format!( |
|
||||||
"http://example.com/id/{}", |
|
||||||
random::<u64>() % size |
|
||||||
)), |
|
||||||
NamedNode::new_unchecked(format!( |
|
||||||
"http://example.com/id/{}", |
|
||||||
random::<u64>() % size |
|
||||||
)), |
|
||||||
NamedNode::new_unchecked(format!( |
|
||||||
"http://example.com/id/{}", |
|
||||||
random::<u64>() % size |
|
||||||
)), |
|
||||||
GraphName::DefaultGraph, |
|
||||||
) |
|
||||||
}) |
|
||||||
.collect() |
|
||||||
} |
} |
||||||
|
@ -1 +1 @@ |
|||||||
Subproject commit 561ce517d21f9f17f324ac58ac50be9231804255 |
Subproject commit 30ac58a9a2717451242e06ec0ea241b72490183b |
Loading…
Reference in new issue