Skip to content

Commit

Permalink
finish properly
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Mar 4, 2020
1 parent 91e1b2d commit 7f65a0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions kvdb-rocksdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ rand = "0.7.2"
tempdir = "0.3.7"
keccak-hash = { path = "../keccak-hash" }
sysinfo = "0.9"
ctrlc = "3.1.4"
time = "0.1"
21 changes: 18 additions & 3 deletions kvdb-rocksdb/examples/memtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use kvdb_rocksdb::{DatabaseConfig, Database};
use ethereum_types::H256;
use keccak_hash::keccak;
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
use std::sync::{Arc, atomic::AtomicBool, atomic::Ordering as AtomicOrdering};

const COLUMN_COUNT: u32 = 100;

Expand Down Expand Up @@ -67,6 +68,14 @@ fn main() {
.map(|arg| arg.parse().expect("Megabytes per col - should be integer or missing"))
.unwrap_or(1);

let exit = Arc::new(AtomicBool::new(false));
let ctrlc_exit = exit.clone();

ctrlc::set_handler(move || {
println!("\nRemoving temp database...\n");
ctrlc_exit.store(true, AtomicOrdering::Relaxed);
})
.expect("Error setting Ctrl-C handler");

let mut config = DatabaseConfig::with_columns(COLUMN_COUNT);

Expand All @@ -80,7 +89,7 @@ fn main() {

let mut step = 0;
let mut keyvalues = KeyValueSeed::new();
loop {
while !exit.load(AtomicOrdering::Relaxed) {
let col = step % 100;

let key_values: Vec<(H256, H256)> = keyvalues.clone().take(128).collect();
Expand Down Expand Up @@ -110,8 +119,14 @@ fn main() {
keyvalues = KeyValueSeed::with_seed(seed);

if step % 10000 == 9999 {
println!("sys memory footprint: {} Mb", proc_memory_usage() / 1024);
println!("lib memory report: {} Mb", parity_util_mem::malloc_size(&db) / 1024 / 1024);
let timestamp =
time::strftime("%Y-%m-%d %H:%M:%S", &time::now())
.expect("Error formatting log timestamp");

println!("{}", timestamp);
println!("\tData written: {} keys - {} Mb", step+1, ((step+1)*64*128) / 1024 / 1024);
println!("\tProcess memory used as seen by the OS: {} Mb", proc_memory_usage() / 1024);
println!("\tMemory used as reported by rocksdb: {} Mb\n", parity_util_mem::malloc_size(&db) / 1024 / 1024);
}

step += 1;
Expand Down

0 comments on commit 7f65a0b

Please sign in to comment.