2023-10-11 07:44:29 +02:00
|
|
|
use std::time::{Duration, Instant, SystemTime};
|
2022-10-01 08:08:51 +02:00
|
|
|
|
2021-02-23 09:10:59 +01:00
|
|
|
use criterion::{
|
|
|
|
criterion_group, criterion_main, BenchmarkId, Criterion, SamplingMode, Throughput,
|
|
|
|
};
|
2023-01-28 04:52:44 +01:00
|
|
|
|
2022-10-07 07:42:13 +02:00
|
|
|
use kanidmd_lib::entry::{Entry, EntryInit, EntryNew};
|
|
|
|
use kanidmd_lib::entry_init;
|
2023-08-21 09:16:43 +02:00
|
|
|
use kanidmd_lib::prelude::{Attribute, EntryClass};
|
2024-03-06 02:33:14 +01:00
|
|
|
use kanidmd_lib::testkit::{setup_idm_test, TestConfiguration};
|
2022-10-07 07:42:13 +02:00
|
|
|
use kanidmd_lib::value::Value;
|
2021-02-23 09:10:59 +01:00
|
|
|
|
2023-10-11 07:44:29 +02:00
|
|
|
pub fn duration_from_epoch_now() -> Duration {
|
|
|
|
#[allow(clippy::expect_used)]
|
|
|
|
SystemTime::now()
|
|
|
|
.duration_since(SystemTime::UNIX_EPOCH)
|
|
|
|
.expect("invalid duration from epoch now")
|
|
|
|
}
|
|
|
|
|
2021-02-23 09:10:59 +01:00
|
|
|
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);
|
2023-02-15 01:25:51 +01:00
|
|
|
println!("iters, size -> {iters:?}, {size:?}");
|
2021-02-23 09:10:59 +01:00
|
|
|
|
|
|
|
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 {
|
2023-06-21 05:53:22 +02:00
|
|
|
let (idms, _idms_delayed, _idms_audit) =
|
2024-03-06 02:33:14 +01:00
|
|
|
setup_idm_test(TestConfiguration::default()).await;
|
2021-02-23 09:10:59 +01:00
|
|
|
|
2022-11-02 10:46:09 +01:00
|
|
|
let ct = duration_from_epoch_now();
|
2021-02-23 09:10:59 +01:00
|
|
|
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;
|
2023-02-15 01:25:51 +01:00
|
|
|
let name = format!("testperson_{counter}");
|
2021-02-23 09:10:59 +01:00
|
|
|
let e1 = entry_init!(
|
2023-09-12 03:47:24 +02:00
|
|
|
(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))
|
2021-02-23 09:10:59 +01:00
|
|
|
);
|
|
|
|
|
2022-04-27 02:56:18 +02:00
|
|
|
let cr = idms_prox_write.qs_write.internal_create(vec![e1]);
|
2021-02-23 09:10:59 +01:00
|
|
|
assert!(cr.is_ok());
|
|
|
|
|
2022-04-27 02:56:18 +02:00
|
|
|
idms_prox_write.commit().expect("Must not fail");
|
2021-02-23 09:10:59 +01:00
|
|
|
}
|
2022-11-02 10:46:09 +01:00
|
|
|
elapsed.checked_add(start.elapsed()).unwrap()
|
|
|
|
});
|
2021-02-23 09:10:59 +01:00
|
|
|
}
|
|
|
|
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);
|
2023-02-15 01:25:51 +01:00
|
|
|
println!("iters, size -> {iters:?}, {size:?}");
|
2021-02-23 09:10:59 +01:00
|
|
|
|
|
|
|
let data: Vec<_> = (0..size)
|
|
|
|
.map(|i| {
|
2023-02-15 01:25:51 +01:00
|
|
|
let name = format!("testperson_{i}");
|
2021-02-23 09:10:59 +01:00
|
|
|
entry_init!(
|
2023-09-12 03:47:24 +02:00
|
|
|
(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))
|
2021-02-23 09:10:59 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.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 {
|
2023-06-21 05:53:22 +02:00
|
|
|
let (idms, _idms_delayed, _idms_audit) =
|
2024-03-06 02:33:14 +01:00
|
|
|
setup_idm_test(TestConfiguration::default()).await;
|
2021-02-23 09:10:59 +01:00
|
|
|
|
2022-11-02 10:46:09 +01:00
|
|
|
let ct = duration_from_epoch_now();
|
2021-02-23 09:10:59 +01:00
|
|
|
let start = Instant::now();
|
|
|
|
|
2022-11-02 10:46:09 +01:00
|
|
|
let mut idms_prox_write = idms.proxy_write(ct).await;
|
2022-04-27 02:56:18 +02:00
|
|
|
let cr = idms_prox_write.qs_write.internal_create(data.clone());
|
2021-02-23 09:10:59 +01:00
|
|
|
assert!(cr.is_ok());
|
|
|
|
|
2022-04-27 02:56:18 +02:00
|
|
|
idms_prox_write.commit().expect("Must not fail");
|
2022-11-02 10:46:09 +01:00
|
|
|
elapsed.checked_add(start.elapsed()).unwrap()
|
|
|
|
});
|
2021-02-23 09:10:59 +01:00
|
|
|
}
|
|
|
|
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);
|