2021-03-01 09:19:11 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2021-02-27 17:34:46 +00:00
|
|
|
mod perf;
|
|
|
|
|
2021-04-16 10:45:21 +00:00
|
|
|
use std::sync::Arc;
|
2021-01-24 13:29:59 +00:00
|
|
|
|
2021-03-09 13:24:16 +00:00
|
|
|
use criterion::*;
|
2021-01-24 13:29:59 +00:00
|
|
|
|
|
|
|
use matrix_sdk_common::{
|
2021-03-02 10:17:38 +00:00
|
|
|
api::r0::{
|
|
|
|
keys::{claim_keys, get_keys},
|
|
|
|
to_device::send_event_to_device::Response as ToDeviceResponse,
|
|
|
|
},
|
|
|
|
identifiers::{room_id, user_id, DeviceIdBox, UserId},
|
2021-01-24 13:29:59 +00:00
|
|
|
uuid::Uuid,
|
2021-04-16 10:45:21 +00:00
|
|
|
IncomingResponse,
|
2021-01-24 13:29:59 +00:00
|
|
|
};
|
2021-03-02 10:17:38 +00:00
|
|
|
use matrix_sdk_crypto::{EncryptionSettings, OlmMachine};
|
2021-01-24 13:29:59 +00:00
|
|
|
use matrix_sdk_test::response_from_file;
|
|
|
|
use serde_json::Value;
|
2021-03-09 13:24:16 +00:00
|
|
|
use tokio::runtime::Builder;
|
2021-01-24 13:29:59 +00:00
|
|
|
|
|
|
|
fn alice_id() -> UserId {
|
|
|
|
user_id!("@alice:example.org")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn alice_device_id() -> DeviceIdBox {
|
|
|
|
"JLAFKJWSCS".into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn keys_query_response() -> get_keys::Response {
|
|
|
|
let data = include_bytes!("./keys_query.json");
|
|
|
|
let data: Value = serde_json::from_slice(data).unwrap();
|
|
|
|
let data = response_from_file(&data);
|
2021-04-16 10:45:21 +00:00
|
|
|
get_keys::Response::try_from_http_response(data).expect("Can't parse the keys upload response")
|
2021-01-24 13:29:59 +00:00
|
|
|
}
|
|
|
|
|
2021-02-27 15:54:06 +00:00
|
|
|
fn keys_claim_response() -> claim_keys::Response {
|
|
|
|
let data = include_bytes!("./keys_claim.json");
|
|
|
|
let data: Value = serde_json::from_slice(data).unwrap();
|
|
|
|
let data = response_from_file(&data);
|
2021-04-16 10:45:21 +00:00
|
|
|
claim_keys::Response::try_from_http_response(data)
|
|
|
|
.expect("Can't parse the keys upload response")
|
2021-02-27 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 12:30:19 +00:00
|
|
|
fn huge_keys_query_resopnse() -> get_keys::Response {
|
|
|
|
let data = include_bytes!("./keys_query_2000_members.json");
|
|
|
|
let data: Value = serde_json::from_slice(data).unwrap();
|
|
|
|
let data = response_from_file(&data);
|
2021-04-16 10:45:21 +00:00
|
|
|
get_keys::Response::try_from_http_response(data).expect("Can't parse the keys query response")
|
2021-03-11 12:30:19 +00:00
|
|
|
}
|
|
|
|
|
2021-02-27 15:54:06 +00:00
|
|
|
pub fn keys_query(c: &mut Criterion) {
|
2021-03-09 13:24:16 +00:00
|
|
|
let runtime = Builder::new_multi_thread()
|
|
|
|
.build()
|
|
|
|
.expect("Can't create runtime");
|
2021-01-24 13:29:59 +00:00
|
|
|
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
|
|
|
let response = keys_query_response();
|
|
|
|
let uuid = Uuid::new_v4();
|
|
|
|
|
|
|
|
let count = response
|
|
|
|
.device_keys
|
|
|
|
.values()
|
|
|
|
.fold(0, |acc, d| acc + d.len())
|
|
|
|
+ response.master_keys.len()
|
|
|
|
+ response.self_signing_keys.len()
|
|
|
|
+ response.user_signing_keys.len();
|
|
|
|
|
2021-02-27 15:54:06 +00:00
|
|
|
let mut group = c.benchmark_group("Keys querying");
|
2021-01-24 13:29:59 +00:00
|
|
|
group.throughput(Throughput::Elements(count as u64));
|
|
|
|
|
2021-03-02 10:18:10 +00:00
|
|
|
let name = format!("{} device and cross signing keys", count);
|
|
|
|
|
2021-01-24 13:29:59 +00:00
|
|
|
group.bench_with_input(
|
2021-03-02 10:18:10 +00:00
|
|
|
BenchmarkId::new("memory store", &name),
|
2021-01-24 13:29:59 +00:00
|
|
|
&response,
|
2021-01-25 14:47:51 +00:00
|
|
|
|b, response| {
|
2021-03-09 13:24:16 +00:00
|
|
|
b.to_async(&runtime)
|
2021-01-25 14:47:51 +00:00
|
|
|
.iter(|| async { machine.mark_request_as_sent(&uuid, response).await.unwrap() })
|
|
|
|
},
|
2021-01-24 13:29:59 +00:00
|
|
|
);
|
2021-03-02 10:18:10 +00:00
|
|
|
|
|
|
|
let dir = tempfile::tempdir().unwrap();
|
2021-03-10 11:05:21 +00:00
|
|
|
let machine = runtime
|
|
|
|
.block_on(OlmMachine::new_with_default_store(
|
|
|
|
&alice_id(),
|
|
|
|
&alice_device_id(),
|
|
|
|
dir.path(),
|
|
|
|
None,
|
|
|
|
))
|
|
|
|
.unwrap();
|
2021-03-02 10:18:10 +00:00
|
|
|
|
|
|
|
group.bench_with_input(
|
|
|
|
BenchmarkId::new("sled store", &name),
|
|
|
|
&response,
|
|
|
|
|b, response| {
|
2021-03-09 13:24:16 +00:00
|
|
|
b.to_async(&runtime)
|
2021-03-02 10:18:10 +00:00
|
|
|
.iter(|| async { machine.mark_request_as_sent(&uuid, response).await.unwrap() })
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-01-24 13:29:59 +00:00
|
|
|
group.finish()
|
|
|
|
}
|
|
|
|
|
2021-02-27 15:54:06 +00:00
|
|
|
pub fn keys_claiming(c: &mut Criterion) {
|
2021-03-11 12:28:22 +00:00
|
|
|
let runtime = Arc::new(
|
|
|
|
Builder::new_multi_thread()
|
|
|
|
.build()
|
|
|
|
.expect("Can't create runtime"),
|
|
|
|
);
|
|
|
|
|
2021-02-27 15:54:06 +00:00
|
|
|
let keys_query_response = keys_query_response();
|
|
|
|
let uuid = Uuid::new_v4();
|
|
|
|
|
|
|
|
let response = keys_claim_response();
|
|
|
|
|
|
|
|
let count = response
|
|
|
|
.one_time_keys
|
|
|
|
.values()
|
|
|
|
.fold(0, |acc, d| acc + d.len());
|
|
|
|
|
2021-03-02 10:18:10 +00:00
|
|
|
let mut group = c.benchmark_group("Olm session creation");
|
2021-02-27 15:54:06 +00:00
|
|
|
group.throughput(Throughput::Elements(count as u64));
|
|
|
|
|
2021-03-02 10:18:10 +00:00
|
|
|
let name = format!("{} one-time keys", count);
|
2021-02-27 15:54:06 +00:00
|
|
|
|
|
|
|
group.bench_with_input(
|
2021-03-02 10:18:10 +00:00
|
|
|
BenchmarkId::new("memory store", &name),
|
2021-02-27 15:54:06 +00:00
|
|
|
&response,
|
|
|
|
|b, response| {
|
|
|
|
b.iter_batched(
|
|
|
|
|| {
|
|
|
|
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
2021-03-11 12:28:22 +00:00
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
|
|
|
|
.unwrap();
|
|
|
|
(machine, runtime.clone())
|
|
|
|
},
|
|
|
|
move |(machine, runtime)| {
|
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, response))
|
|
|
|
.unwrap()
|
2021-02-27 15:54:06 +00:00
|
|
|
},
|
|
|
|
BatchSize::SmallInput,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
);
|
2021-03-02 10:18:10 +00:00
|
|
|
|
|
|
|
group.bench_with_input(
|
|
|
|
BenchmarkId::new("sled store", &name),
|
|
|
|
&response,
|
|
|
|
|b, response| {
|
|
|
|
b.iter_batched(
|
|
|
|
|| {
|
|
|
|
let dir = tempfile::tempdir().unwrap();
|
2021-03-11 12:28:22 +00:00
|
|
|
let machine = runtime
|
|
|
|
.block_on(OlmMachine::new_with_default_store(
|
|
|
|
&alice_id(),
|
|
|
|
&alice_device_id(),
|
|
|
|
dir.path(),
|
|
|
|
None,
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
|
|
|
|
.unwrap();
|
|
|
|
(machine, runtime.clone())
|
|
|
|
},
|
|
|
|
move |(machine, runtime)| {
|
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, response))
|
|
|
|
.unwrap()
|
2021-03-02 10:18:10 +00:00
|
|
|
},
|
|
|
|
BatchSize::SmallInput,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-02-27 15:54:06 +00:00
|
|
|
group.finish()
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:17:38 +00:00
|
|
|
pub fn room_key_sharing(c: &mut Criterion) {
|
2021-03-09 13:24:16 +00:00
|
|
|
let runtime = Builder::new_multi_thread()
|
|
|
|
.build()
|
|
|
|
.expect("Can't create runtime");
|
|
|
|
|
2021-03-02 10:17:38 +00:00
|
|
|
let keys_query_response = keys_query_response();
|
|
|
|
let uuid = Uuid::new_v4();
|
|
|
|
let response = keys_claim_response();
|
|
|
|
let room_id = room_id!("!test:localhost");
|
|
|
|
|
|
|
|
let to_device_response = ToDeviceResponse::new();
|
|
|
|
let users: Vec<UserId> = keys_query_response.device_keys.keys().cloned().collect();
|
|
|
|
|
|
|
|
let count = response
|
|
|
|
.one_time_keys
|
|
|
|
.values()
|
|
|
|
.fold(0, |acc, d| acc + d.len());
|
|
|
|
|
|
|
|
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
2021-03-10 11:05:21 +00:00
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
|
|
|
|
.unwrap();
|
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &response))
|
|
|
|
.unwrap();
|
2021-03-02 10:17:38 +00:00
|
|
|
|
|
|
|
let mut group = c.benchmark_group("Room key sharing");
|
|
|
|
group.throughput(Throughput::Elements(count as u64));
|
|
|
|
let name = format!("{} devices", count);
|
|
|
|
|
|
|
|
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
|
2021-03-09 13:24:16 +00:00
|
|
|
b.to_async(&runtime).iter(|| async {
|
2021-03-02 10:17:38 +00:00
|
|
|
let requests = machine
|
|
|
|
.share_group_session(&room_id, users.iter(), EncryptionSettings::default())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(requests.len() >= 8);
|
|
|
|
|
|
|
|
for request in requests {
|
|
|
|
machine
|
|
|
|
.mark_request_as_sent(&request.txn_id, &to_device_response)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2021-04-12 13:19:30 +00:00
|
|
|
machine.invalidate_group_session(&room_id).await.unwrap();
|
2021-03-02 10:17:38 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
let dir = tempfile::tempdir().unwrap();
|
2021-03-11 12:28:22 +00:00
|
|
|
let machine = runtime
|
|
|
|
.block_on(OlmMachine::new_with_default_store(
|
|
|
|
&alice_id(),
|
|
|
|
&alice_device_id(),
|
|
|
|
dir.path(),
|
|
|
|
None,
|
|
|
|
))
|
|
|
|
.unwrap();
|
2021-03-10 11:05:21 +00:00
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
|
|
|
|
.unwrap();
|
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &response))
|
|
|
|
.unwrap();
|
2021-03-02 10:17:38 +00:00
|
|
|
|
|
|
|
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
|
2021-03-09 13:24:16 +00:00
|
|
|
b.to_async(&runtime).iter(|| async {
|
2021-03-02 10:17:38 +00:00
|
|
|
let requests = machine
|
|
|
|
.share_group_session(&room_id, users.iter(), EncryptionSettings::default())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(requests.len() >= 8);
|
|
|
|
|
|
|
|
for request in requests {
|
|
|
|
machine
|
|
|
|
.mark_request_as_sent(&request.txn_id, &to_device_response)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2021-04-12 13:19:30 +00:00
|
|
|
machine.invalidate_group_session(&room_id).await.unwrap();
|
2021-03-02 10:17:38 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
group.finish()
|
|
|
|
}
|
|
|
|
|
2021-03-11 12:30:19 +00:00
|
|
|
pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
|
|
|
|
let runtime = Builder::new_multi_thread()
|
|
|
|
.build()
|
|
|
|
.expect("Can't create runtime");
|
|
|
|
|
|
|
|
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
|
|
|
let response = huge_keys_query_resopnse();
|
|
|
|
let uuid = Uuid::new_v4();
|
|
|
|
let users: Vec<UserId> = response.device_keys.keys().cloned().collect();
|
|
|
|
|
|
|
|
let count = response
|
|
|
|
.device_keys
|
|
|
|
.values()
|
|
|
|
.fold(0, |acc, d| acc + d.len());
|
|
|
|
|
|
|
|
let mut group = c.benchmark_group("Devices missing sessions collecting");
|
|
|
|
group.throughput(Throughput::Elements(count as u64));
|
|
|
|
|
|
|
|
let name = format!("{} devices", count);
|
|
|
|
|
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &response))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
|
|
|
|
b.to_async(&runtime).iter_with_large_drop(|| async {
|
|
|
|
machine.get_missing_sessions(users.iter()).await.unwrap()
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
let dir = tempfile::tempdir().unwrap();
|
|
|
|
let machine = runtime
|
|
|
|
.block_on(OlmMachine::new_with_default_store(
|
|
|
|
&alice_id(),
|
|
|
|
&alice_device_id(),
|
|
|
|
dir.path(),
|
|
|
|
None,
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
runtime
|
|
|
|
.block_on(machine.mark_request_as_sent(&uuid, &response))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
|
|
|
|
b.to_async(&runtime)
|
|
|
|
.iter(|| async { machine.get_missing_sessions(users.iter()).await.unwrap() })
|
|
|
|
});
|
|
|
|
|
|
|
|
group.finish()
|
|
|
|
}
|
|
|
|
|
2021-02-27 17:34:46 +00:00
|
|
|
fn criterion() -> Criterion {
|
2021-03-01 09:19:11 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
let criterion = Criterion::default().with_profiler(perf::FlamegraphProfiler::new(100));
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
let criterion = Criterion::default();
|
|
|
|
|
|
|
|
criterion
|
2021-02-27 17:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group! {
|
|
|
|
name = benches;
|
|
|
|
config = criterion();
|
2021-03-11 12:30:19 +00:00
|
|
|
targets = keys_query, keys_claiming, room_key_sharing, devices_missing_sessions_collecting,
|
2021-02-27 17:34:46 +00:00
|
|
|
}
|
2021-01-24 13:29:59 +00:00
|
|
|
criterion_main!(benches);
|