kanidm/server/lib/benches/scaling_10k.rs

130 lines
5.5 KiB
Rust
Raw Normal View History

2022-10-01 08:08:51 +02:00
use std::time::{Duration, Instant};
use criterion::{
criterion_group, criterion_main, BenchmarkId, Criterion, SamplingMode, Throughput,
};
2023-01-28 04:52:44 +01:00
use kanidmd_lib::entry::{Entry, EntryInit, EntryNew};
use kanidmd_lib::entry_init;
use kanidmd_lib::prelude::{Attribute, EntryClass};
use kanidmd_lib::utils::duration_from_epoch_now;
use kanidmd_lib::value::Value;
pub fn scaling_user_create_single(c: &mut Criterion) {
let mut group = c.benchmark_group("user_create_single");
group.sample_size(10);
group.sampling_mode(SamplingMode::Flat);
group.warm_up_time(Duration::from_secs(5));
group.measurement_time(Duration::from_secs(120));
for size in &[100, 250, 500, 1000, 1500, 2000, 5000, 10000] {
group.throughput(Throughput::Elements(*size));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
b.iter_custom(|iters| {
let mut elapsed = Duration::from_secs(0);
println!("iters, size -> {iters:?}, {size:?}");
for _i in 0..iters {
2022-11-02 10:46:09 +01:00
let mut rt = tokio::runtime::Builder::new_current_thread();
elapsed = rt
.enable_all()
.build()
.expect("Failed building the Runtime")
.block_on(async {
let (idms, _idms_delayed, _idms_audit) =
2022-11-02 10:46:09 +01:00
kanidmd_lib::testkit::setup_idm_test().await;
2022-11-02 10:46:09 +01:00
let ct = duration_from_epoch_now();
let start = Instant::now();
for counter in 0..size {
2022-11-02 10:46:09 +01:00
let mut idms_prox_write = idms.proxy_write(ct).await;
let name = format!("testperson_{counter}");
let e1 = entry_init!(
(Attribute::Class, EntryClass::Object.to_value()),
(Attribute::Class, EntryClass::Person.to_value()),
(Attribute::Class, EntryClass::Account.to_value()),
(Attribute::Name, Value::new_iname(&name)),
(Attribute::Description, Value::new_utf8s("criterion")),
(Attribute::DisplayName, Value::new_utf8s(&name))
);
let cr = idms_prox_write.qs_write.internal_create(vec![e1]);
assert!(cr.is_ok());
idms_prox_write.commit().expect("Must not fail");
}
2022-11-02 10:46:09 +01:00
elapsed.checked_add(start.elapsed()).unwrap()
});
}
elapsed
});
});
}
group.finish();
}
pub fn scaling_user_create_batched(c: &mut Criterion) {
let mut group = c.benchmark_group("user_create_batched");
group.sample_size(10);
group.sampling_mode(SamplingMode::Flat);
group.warm_up_time(Duration::from_secs(5));
group.measurement_time(Duration::from_secs(120));
for size in &[100, 250, 500, 1000, 1500, 2000, 5000, 10000] {
group.throughput(Throughput::Elements(*size));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
b.iter_custom(|iters| {
let mut elapsed = Duration::from_secs(0);
println!("iters, size -> {iters:?}, {size:?}");
let data: Vec<_> = (0..size)
.map(|i| {
let name = format!("testperson_{i}");
entry_init!(
(Attribute::Class, EntryClass::Object.to_value()),
(Attribute::Class, EntryClass::Person.to_value()),
(Attribute::Class, EntryClass::Account.to_value()),
(Attribute::Name, Value::new_iname(&name)),
(Attribute::Description, Value::new_utf8s("criterion")),
(Attribute::DisplayName, Value::new_utf8s(&name))
)
})
.collect();
for _i in 0..iters {
2022-11-02 10:46:09 +01:00
let mut rt = tokio::runtime::Builder::new_current_thread();
elapsed = rt
.enable_all()
.build()
.expect("Failed building the Runtime")
.block_on(async {
let (idms, _idms_delayed, _idms_audit) =
2022-11-02 10:46:09 +01:00
kanidmd_lib::testkit::setup_idm_test().await;
2022-11-02 10:46:09 +01:00
let ct = duration_from_epoch_now();
let start = Instant::now();
2022-11-02 10:46:09 +01:00
let mut idms_prox_write = idms.proxy_write(ct).await;
let cr = idms_prox_write.qs_write.internal_create(data.clone());
assert!(cr.is_ok());
idms_prox_write.commit().expect("Must not fail");
2022-11-02 10:46:09 +01:00
elapsed.checked_add(start.elapsed()).unwrap()
});
}
elapsed
});
});
}
group.finish();
}
criterion_group!(
name = scaling_basic;
config = Criterion::default()
.measurement_time(Duration::from_secs(15))
.with_plots();
targets = scaling_user_create_single, scaling_user_create_batched
);
criterion_main!(scaling_basic);