diff --git a/services/commtest/Cargo.lock b/services/commtest/Cargo.lock --- a/services/commtest/Cargo.lock +++ b/services/commtest/Cargo.lock @@ -94,6 +94,7 @@ "derive_more", "futures", "lazy_static", + "num_cpus", "prost", "tokio", "tonic", @@ -398,9 +399,9 @@ [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ "hermit-abi", "libc", diff --git a/services/commtest/Cargo.toml b/services/commtest/Cargo.toml --- a/services/commtest/Cargo.toml +++ b/services/commtest/Cargo.toml @@ -13,6 +13,7 @@ derive_more = "0.99.16" bytesize = "1.1.0" lazy_static = "1.4.0" +num_cpus = "1.13.1" [build-dependencies] tonic-build = "0.6" diff --git a/services/commtest/tests/blob_performance_test.rs b/services/commtest/tests/blob_performance_test.rs --- a/services/commtest/tests/blob_performance_test.rs +++ b/services/commtest/tests/blob_performance_test.rs @@ -1,7 +1,58 @@ +#[path = "./blob/blob_utils.rs"] +mod blob_utils; #[path = "./lib/tools.rs"] mod tools; +use bytesize::ByteSize; + +use tokio::runtime::Runtime; +use tools::{obtain_number_of_threads, Error}; + +use blob_utils::BlobData; + #[tokio::test] -async fn blob_performance_test() { - assert!(false, "not implemented"); +async fn blob_performance_test() -> Result<(), Error> { + let number_of_threads = obtain_number_of_threads(); + + println!( + "Running performance tests for blob, number of threads: {}", + number_of_threads + ); + + let mut blob_data = vec![]; + + for i in 0..number_of_threads { + let index: u64 = (i as u64) % 10; + blob_data.push(BlobData { + holder: format!("test_holder_{}", i), + hash: format!("test_hash_{}", i), + chunks_sizes: vec![ + ByteSize::kib(200 + (300 - index * 20)).as_u64() as usize, + ByteSize::kib(500 + (400 - index * 20)).as_u64() as usize, + ByteSize::kib(700 + (500 - index * 25)).as_u64() as usize, + ], + }) + } + + let rt = Runtime::new().unwrap(); + tokio::task::spawn_blocking(move || { + // PUT + rt.block_on(async { + println!("performing PUT operations"); + }); + + // GET + rt.block_on(async { + println!("performing GET operations"); + }); + + // REMOVE + rt.block_on(async { + println!("performing REMOVE operations"); + }); + }) + .await + .expect("Task panicked"); + + Ok(()) } diff --git a/services/commtest/tests/lib/tools.rs b/services/commtest/tests/lib/tools.rs --- a/services/commtest/tests/lib/tools.rs +++ b/services/commtest/tests/lib/tools.rs @@ -1,5 +1,7 @@ use bytesize::ByteSize; use lazy_static::lazy_static; +use num_cpus; +use std::env; #[allow(dead_code)] pub fn generate_nbytes( @@ -33,3 +35,13 @@ #[allow(dead_code)] pub const ATTACHMENT_DELIMITER: &str = ";"; + +#[allow(dead_code)] +pub fn obtain_number_of_threads() -> usize { + let number_of_threads_str: String = + env::var("COMM_NUMBER_OF_THREADS").unwrap(); + if number_of_threads_str.is_empty() { + return num_cpus::get(); + } + return number_of_threads_str.parse::().unwrap(); +} diff --git a/services/scripts/run_performance_tests.sh b/services/scripts/run_performance_tests.sh --- a/services/scripts/run_performance_tests.sh +++ b/services/scripts/run_performance_tests.sh @@ -10,18 +10,25 @@ cargo test "$1"_performance_test --test '*' --manifest-path=commtest/Cargo.toml #-- --nocapture } -list_expected () { - echo "Expected one of these:"; +help () { + echo "Usage:"; + echo "There are two arguments you can specify"; + echo "First is a target service:"; echo "$SERVICES"; echo "all"; + echo "Second is a number of threads that you'd like to spawn."; + echo "It is optional, if not specified, it will fall back to a default value"; + echo "The default value is the number of CPUs"; } if [[ -z "$1" ]]; then echo "No service specified" >&2 - list_expected; + help; exit 1 fi +export COMM_NUMBER_OF_THREADS="$2" + if [[ "$1" == "all" ]]; then for SERVICE in "$SERVICES"; do run_performance_test "$SERVICE" @@ -33,7 +40,7 @@ if [[ "$SERVICE" != "$1" ]]; then echo "No such service: $1"; - list_expected; + help; exit 1; fi;