Added statistics for open invite 1000 users

This commit is contained in:
onyinyang 2021-06-15 02:01:24 -04:00
parent 727a6e11a3
commit 6217252813
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 153 additions and 17 deletions

View File

@ -14,6 +14,7 @@ rand = "0.7"
serde = "1"
serde_with = "1.9.1"
sha2 = "0.9"
statistical = "1.0.0"
lazy_static = "1"
hex_fmt = "0.3"
aes-gcm = "0.8"

View File

@ -4,6 +4,7 @@ BridgeLine::random() or private fields */
use super::bridge_table::BridgeLine;
use super::proto::*;
use super::*;
use statistical::{mean, standard_deviation};
use std::time::{Duration, Instant};
struct PerfStat {
@ -22,13 +23,17 @@ struct TestHarness {
impl TestHarness {
fn new() -> Self {
TestHarness::new_buckets(5, 5)
}
fn new_buckets(num_buckets: u8, hot_spare: u8) -> Self {
// Create a BridegDb
let mut bdb = BridgeDb::new();
// Create a BridgeAuth
let mut ba = BridgeAuth::new(bdb.pubkey);
// Make 15 open invitation bridges, in 5 sets of 3
for _ in 0..5 {
for _ in 0..num_buckets {
let bucket = [
BridgeLine::random(),
BridgeLine::random(),
@ -37,7 +42,7 @@ impl TestHarness {
ba.add_openinv_bridges(bucket, &mut bdb);
}
// Add 5 more hot spare buckets
for _ in 0..5 {
for _ in 0..hot_spare {
let bucket = [
BridgeLine::random(),
BridgeLine::random(),
@ -622,21 +627,21 @@ fn test_issue_invite() {
th.advance_days(47);
// Go up to level 1
let (perf_stat, migcred) = th.trust_promotion(&cred);
let (mperf_stat, cred1) = th.level0_migration(&cred, &migcred);
let (_perf_stat, migcred) = th.trust_promotion(&cred);
let (_mperf_stat, cred1) = th.level0_migration(&cred, &migcred);
assert!(scalar_u32(&cred1.trust_level).unwrap() == 1);
// Time passes
th.advance_days(20);
// Go up to level 2
let (two_perf_stat, cred2) = th.level_up(&cred1);
let (_two_perf_stat, cred2) = th.level_up(&cred1);
assert!(scalar_u32(&cred2.trust_level).unwrap() == 2);
println!("cred2 = {:?}", cred2);
assert!(th.ba.verify_lox(&cred2));
// Issue an invitation
let (invite_perf_stat, (cred2a, invite)) = th.issue_invite(&cred2);
let (_invite_perf_stat, (cred2a, invite)) = th.issue_invite(&cred2);
assert!(th.ba.verify_lox(&cred2a));
assert!(th.ba.verify_invitation(&invite));
println!("cred2a = {:?}", cred2a);
@ -654,21 +659,21 @@ fn test_redeem_invite() {
th.advance_days(47);
// Go up to level 1
let (perf_stat, migcred) = th.trust_promotion(&cred);
let (one_perf_stat, cred1) = th.level0_migration(&cred, &migcred);
let (_perf_stat, migcred) = th.trust_promotion(&cred);
let (_one_perf_stat, cred1) = th.level0_migration(&cred, &migcred);
assert!(scalar_u32(&cred1.trust_level).unwrap() == 1);
// Time passes
th.advance_days(20);
// Go up to level 2
let (two_perf_stat, cred2) = th.level_up(&cred1);
let (_two_perf_stat, cred2) = th.level_up(&cred1);
assert!(scalar_u32(&cred2.trust_level).unwrap() == 2);
println!("cred2 = {:?}", cred2);
assert!(th.ba.verify_lox(&cred2));
// Issue an invitation to Bob
let (invite_perf_stat, (cred2a, bob_invite)) = th.issue_invite(&cred2);
let (_invite_perf_stat, (cred2a, bob_invite)) = th.issue_invite(&cred2);
assert!(th.ba.verify_lox(&cred2a));
assert!(th.ba.verify_invitation(&bob_invite));
println!("cred2a = {:?}", cred2a);
@ -678,7 +683,7 @@ fn test_redeem_invite() {
th.advance_days(12);
// Bob joins the system
let (bob_perf_stat, bob_cred) = th.redeem_invite(&bob_invite);
let (_bob_perf_stat, bob_cred) = th.redeem_invite(&bob_invite);
assert!(th.ba.verify_lox(&bob_cred));
println!("bob_cred = {:?}", bob_cred);
}
@ -744,15 +749,15 @@ fn test_blockage_migration() {
th.advance_days(47);
// Go up to level 1
let (mperf_stat, migcred) = th.trust_promotion(&cred);
let (perf_stat, cred1) = th.level0_migration(&cred, &migcred);
let (_mperf_stat, migcred) = th.trust_promotion(&cred);
let (_perf_stat, cred1) = th.level0_migration(&cred, &migcred);
assert!(scalar_u32(&cred1.trust_level).unwrap() == 1);
// Time passes
th.advance_days(20);
// Go up to level 2
let (two_perf_stat, cred2) = th.level_up(&cred1);
let (_two_perf_stat, cred2) = th.level_up(&cred1);
assert!(scalar_u32(&cred2.trust_level).unwrap() == 2);
println!("cred2 = {:?}", cred2);
assert!(th.ba.verify_lox(&cred2));
@ -761,7 +766,7 @@ fn test_blockage_migration() {
th.advance_days(29);
// Go up to level 3
let (three_perf_stat, cred3) = th.level_up(&cred2);
let (_three_perf_stat, cred3) = th.level_up(&cred2);
assert!(scalar_u32(&cred3.trust_level).unwrap() == 3);
println!("cred3 = {:?}", cred3);
assert!(th.ba.verify_lox(&cred3));
@ -793,13 +798,143 @@ fn test_blockage_migration() {
assert!(bucket2.1.is_none());
// See about getting a Migration credential for the blockage
let (block_perf_stat, migration) = th.check_blockage(&cred3);
let (_block_perf_stat, migration) = th.check_blockage(&cred3);
println!("migration = {:?}", migration);
// Migrate
let (four_perf_stat, cred4) = th.blockage_migration(&cred3, &migration);
let (_four_perf_stat, cred4) = th.blockage_migration(&cred3, &migration);
println!("cred4 = {:?}", cred4);
assert!(th.ba.verify_lox(&cred4));
}
#[test]
fn protocol_tests() {
let mut th = TestHarness::new_buckets(10, 10);
let mut req_size: Vec<f64> = Vec::new();
let mut resp_size: Vec<f64> = Vec::new();
let mut req_t_size: Vec<f64> = Vec::new();
let mut resp_t_size: Vec<f64> = Vec::new();
let mut resp_handle_t_size: Vec<f64> = Vec::new();
for _i in 0..1000 {
let (perf_stat, (_cred, _bridgeline)) = th.open_invite();
req_size.push(perf_stat.req_len as f64);
req_t_size.push(perf_stat.req_t.as_secs_f64());
resp_size.push(perf_stat.resp_len as f64);
resp_t_size.push(perf_stat.resp_t.as_secs_f64());
resp_handle_t_size.push(perf_stat.resp_handle_t.as_secs_f64());
}
let mean_req_size = mean(&req_size);
let req_std_dev = standard_deviation(&req_size, Some(mean_req_size));
let mean_req_t_size = mean(&req_t_size);
let req_t_std_dev = standard_deviation(&req_t_size, Some(mean_req_t_size));
let mean_resp_size = mean(&resp_size);
let resp_std_dev = standard_deviation(&resp_size, Some(mean_resp_size));
let mean_resp_t_size = mean(&resp_t_size);
let resp_t_std_dev = standard_deviation(&resp_t_size, Some(mean_resp_t_size));
let mean_resp_handle_t_size = mean(&resp_t_size);
let resp_handle_t_std_dev =
standard_deviation(&resp_handle_t_size, Some(mean_resp_handle_t_size));
println!("Average Request Size = {:?}", mean_req_size);
println!("Request Standard Deviation = {:?}", req_std_dev);
println!(
"Average Request Time = {:?}",
Duration::from_secs_f64(mean_req_t_size)
);
println!(
"Request time Standard Deviation = {:?}",
Duration::from_secs_f64(req_t_std_dev)
);
println!("Average Response Size = {:?}", mean_resp_size);
println!("Response Standard Deviation = {:?}", resp_std_dev);
println!(
"Average Response Time = {:?}",
Duration::from_secs_f64(mean_resp_t_size)
);
println!(
"Response Time Standard Deviation = {:?}",
Duration::from_secs_f64(resp_t_std_dev)
);
println!(
"Average Response Handling Time = {:?}",
Duration::from_secs_f64(mean_resp_handle_t_size)
);
println!(
"Response Handling Time Standard Deviation = {:?}",
Duration::from_secs_f64(resp_handle_t_std_dev)
);
println!("\n---------------Block Bridges-------------------\n");
// Mark 5 bridges in untrusted buckets as unreachable
let b0 = th.ba.bridge_table.buckets[0][0];
th.ba.bridge_unreachable(&b0, &mut th.bdb);
let b3 = th.ba.bridge_table.buckets[3][0];
th.ba.bridge_unreachable(&b3, &mut th.bdb);
let b6 = th.ba.bridge_table.buckets[6][0];
th.ba.bridge_unreachable(&b6, &mut th.bdb);
let b9 = th.ba.bridge_table.buckets[9][0];
th.ba.bridge_unreachable(&b9, &mut th.bdb);
let b12 = th.ba.bridge_table.buckets[12][0];
th.ba.bridge_unreachable(&b12, &mut th.bdb);
let mut req_size2: Vec<f64> = Vec::new();
let mut resp_size2: Vec<f64> = Vec::new();
let mut req_t_size2: Vec<f64> = Vec::new();
let mut resp_t_size2: Vec<f64> = Vec::new();
let mut resp_handle_t_size2: Vec<f64> = Vec::new();
for _i in 0..1000 {
let (perf_stat2, (_cred2, _bridgeline2)) = th.open_invite();
req_size2.push(perf_stat2.req_len as f64);
req_t_size2.push(perf_stat2.req_t.as_secs_f64());
resp_size2.push(perf_stat2.resp_len as f64);
resp_t_size2.push(perf_stat2.resp_t.as_secs_f64());
resp_handle_t_size2.push(perf_stat2.resp_handle_t.as_secs_f64());
}
let mean_req_size2 = mean(&req_size2);
let req_std_dev2 = standard_deviation(&req_size2, Some(mean_req_size2));
let mean_req_t_size2 = mean(&req_t_size2);
let req_t_std_dev2 = standard_deviation(&req_t_size2, Some(mean_req_t_size2));
let mean_resp_size2 = mean(&resp_size2);
let resp_std_dev2 = standard_deviation(&resp_size2, Some(mean_resp_size2));
let mean_resp_t_size2 = mean(&resp_t_size2);
let resp_t_std_dev2 = standard_deviation(&resp_t_size2, Some(mean_resp_t_size2));
let mean_resp_handle_t_size2 = mean(&resp_t_size2);
let resp_handle_t_std_dev2 =
standard_deviation(&resp_handle_t_size2, Some(mean_resp_handle_t_size2));
println!("Average Request size = {:?}", mean_req_size2);
println!("Request Standard Deviation = {:?}", req_std_dev2);
println!(
"Average Request Time = {:?}",
Duration::from_secs_f64(mean_req_t_size)
);
println!(
"Request time Standard Deviation = {:?}",
Duration::from_secs_f64(req_t_std_dev2)
);
println!("Average Response size = {:?}", mean_resp_size2);
println!("Response Standard Deviation = {:?}", resp_std_dev2);
println!(
"Average Response Time = {:?}",
Duration::from_secs_f64(mean_resp_t_size2)
);
println!(
"Response Time Standard Deviation = {:?}",
Duration::from_secs_f64(resp_t_std_dev2)
);
println!(
"Average Response Handling Time = {:?}",
Duration::from_secs_f64(mean_resp_handle_t_size2)
);
println!(
"Response Handling Time Standard Deviation = {:?}",
Duration::from_secs_f64(resp_handle_t_std_dev2)
);
}