Track memory usage in simulation
This commit is contained in:
parent
461d7d4ce5
commit
3469fa67a4
|
@ -25,6 +25,7 @@ julianday = "1.2.0"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
lox_cli = { path = "../lox_cli", version = "0.1", optional = true }
|
lox_cli = { path = "../lox_cli", version = "0.1", optional = true }
|
||||||
lox-library = { git = "https://gitlab.torproject.org/vecna/lox.git", version = "0.1.0" }
|
lox-library = { git = "https://gitlab.torproject.org/vecna/lox.git", version = "0.1.0" }
|
||||||
|
memory-stats = { version = "1.0.0", optional = true }
|
||||||
nalgebra = "0.29"
|
nalgebra = "0.29"
|
||||||
rand = { version = "0.8" }
|
rand = { version = "0.8" }
|
||||||
#select = "0.6.0"
|
#select = "0.6.0"
|
||||||
|
@ -45,7 +46,7 @@ base64 = "0.21.7"
|
||||||
faketime = "0.2"
|
faketime = "0.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
simulation = ["faketime", "lox_cli"]
|
simulation = ["faketime", "lox_cli", "memory-stats"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "simulation"
|
name = "simulation"
|
||||||
|
|
|
@ -18,6 +18,7 @@ use troll_patrol::{
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use lox_cli::{networking::*, *};
|
use lox_cli::{networking::*, *};
|
||||||
use lox_library::proto::{level_up::LEVEL_INTERVAL, trust_promotion::UNTRUSTED_INTERVAL};
|
use lox_library::proto::{level_up::LEVEL_INTERVAL, trust_promotion::UNTRUSTED_INTERVAL};
|
||||||
|
use memory_stats::memory_stats;
|
||||||
use rand::{prelude::SliceRandom, Rng};
|
use rand::{prelude::SliceRandom, Rng};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -223,9 +224,33 @@ pub async fn main() {
|
||||||
let mut true_neg = 0;
|
let mut true_neg = 0;
|
||||||
let mut true_pos = 0;
|
let mut true_pos = 0;
|
||||||
|
|
||||||
|
// Track memory use during simulation
|
||||||
|
let mut max_physical_mem = 0;
|
||||||
|
let mut max_virtual_mem = 0;
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
for day in 1..=config.num_days {
|
for day in 1..=config.num_days {
|
||||||
println!("Starting day {} of the simulation", day);
|
println!("Starting day {} of the simulation", day);
|
||||||
|
println!(
|
||||||
|
"We have {} users and {} bridges",
|
||||||
|
users.len(),
|
||||||
|
bridges.len()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"The censor has learned {} bridges",
|
||||||
|
censor.known_bridges.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some(usage) = memory_stats() {
|
||||||
|
if usage.physical_mem > max_physical_mem {
|
||||||
|
max_physical_mem = usage.physical_mem;
|
||||||
|
}
|
||||||
|
if usage.virtual_mem > max_virtual_mem {
|
||||||
|
max_virtual_mem = usage.virtual_mem;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Failed to get the current memory usage");
|
||||||
|
}
|
||||||
|
|
||||||
// USER TASKS
|
// USER TASKS
|
||||||
|
|
||||||
|
@ -305,7 +330,6 @@ pub async fn main() {
|
||||||
let new_blockages: HashMap<String, HashSet<String>> =
|
let new_blockages: HashMap<String, HashSet<String>> =
|
||||||
serde_json::from_slice(&new_blockages_resp).unwrap();
|
serde_json::from_slice(&new_blockages_resp).unwrap();
|
||||||
|
|
||||||
// TODO: Track more stats about new blockages
|
|
||||||
// Since we have only one censor, just convert to a set of bridges
|
// Since we have only one censor, just convert to a set of bridges
|
||||||
let mut blocked_bridges = HashSet::<[u8; 20]>::new();
|
let mut blocked_bridges = HashSet::<[u8; 20]>::new();
|
||||||
for (bridge, ccs) in new_blockages {
|
for (bridge, ccs) in new_blockages {
|
||||||
|
@ -356,11 +380,30 @@ pub async fn main() {
|
||||||
increment_simulated_date();
|
increment_simulated_date();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print various information about the simulation run
|
||||||
|
println!(
|
||||||
|
"\nSimulation ended with {} users and {} bridges",
|
||||||
|
users.len(),
|
||||||
|
bridges.len()
|
||||||
|
);
|
||||||
|
println!("The censor learned {} bridges", censor.known_bridges.len());
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"\nMaximum physical memory usage during simulation: {}",
|
||||||
|
max_physical_mem
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"Maximum virtual memory usage during simulation: {}\n",
|
||||||
|
max_virtual_mem
|
||||||
|
);
|
||||||
|
|
||||||
println!("True Positives: {}", true_pos);
|
println!("True Positives: {}", true_pos);
|
||||||
println!("True Negatives: {}", true_neg);
|
println!("True Negatives: {}", true_neg);
|
||||||
println!("False Positives: {}", false_pos);
|
println!("False Positives: {}", false_pos);
|
||||||
println!("False Negatives: {}", false_neg);
|
println!("False Negatives: {}", false_neg);
|
||||||
|
|
||||||
|
println!("\nFull stats per bridge:");
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Fingerprint,first_distributed,first_blocked,first_detected_blocked,first_positive_report"
|
"Fingerprint,first_distributed,first_blocked,first_detected_blocked,first_positive_report"
|
||||||
);
|
);
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -27,6 +27,9 @@ use tokio::{
|
||||||
#[cfg(not(feature = "simulation"))]
|
#[cfg(not(feature = "simulation"))]
|
||||||
use tokio_cron::{Job, Scheduler};
|
use tokio_cron::{Job, Scheduler};
|
||||||
|
|
||||||
|
#[cfg(feature = "simulation")]
|
||||||
|
use memory_stats::memory_stats;
|
||||||
|
|
||||||
async fn shutdown_signal() {
|
async fn shutdown_signal() {
|
||||||
tokio::signal::ctrl_c()
|
tokio::signal::ctrl_c()
|
||||||
.await
|
.await
|
||||||
|
@ -151,12 +154,27 @@ async fn context_manager(
|
||||||
max_historical_days: u32,
|
max_historical_days: u32,
|
||||||
mut context_rx: mpsc::Receiver<Command>,
|
mut context_rx: mpsc::Receiver<Command>,
|
||||||
) {
|
) {
|
||||||
|
#[cfg(feature = "simulation")]
|
||||||
|
let (mut max_physical_mem, mut max_virtual_mem) = (0, 0);
|
||||||
|
|
||||||
let db: Db = sled::open(&db_config.db_path).unwrap();
|
let db: Db = sled::open(&db_config.db_path).unwrap();
|
||||||
|
|
||||||
// Create negative report key for today if we don't have one
|
// Create negative report key for today if we don't have one
|
||||||
new_negative_report_key(&db, get_date());
|
new_negative_report_key(&db, get_date());
|
||||||
|
|
||||||
while let Some(cmd) = context_rx.recv().await {
|
while let Some(cmd) = context_rx.recv().await {
|
||||||
|
#[cfg(feature = "simulation")]
|
||||||
|
if let Some(usage) = memory_stats() {
|
||||||
|
if usage.physical_mem > max_physical_mem {
|
||||||
|
max_physical_mem = usage.physical_mem;
|
||||||
|
}
|
||||||
|
if usage.virtual_mem > max_virtual_mem {
|
||||||
|
max_virtual_mem = usage.virtual_mem;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Failed to get the current memory usage");
|
||||||
|
}
|
||||||
|
|
||||||
use Command::*;
|
use Command::*;
|
||||||
match cmd {
|
match cmd {
|
||||||
Request { req, sender } => {
|
Request { req, sender } => {
|
||||||
|
@ -170,6 +188,11 @@ async fn context_manager(
|
||||||
println!("Sending Shutdown Signal, all threads should shutdown.");
|
println!("Sending Shutdown Signal, all threads should shutdown.");
|
||||||
drop(shutdown_sig);
|
drop(shutdown_sig);
|
||||||
println!("Shutdown Sent.");
|
println!("Shutdown Sent.");
|
||||||
|
#[cfg(feature = "simulation")]
|
||||||
|
println!(
|
||||||
|
"\nMaximum physical memory usage: {}\nMaximum virtual memory usage: {}\n",
|
||||||
|
max_physical_mem, max_virtual_mem
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Update { _req, sender } => {
|
Update { _req, sender } => {
|
||||||
let blockages = update_daily_info(
|
let blockages = update_daily_info(
|
||||||
|
|
Loading…
Reference in New Issue