diff --git a/Cargo.lock b/Cargo.lock index 55c4b264..0cb35a45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,6 +182,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485" +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + [[package]] name = "jemalloc-sys" version = "0.3.2" @@ -430,6 +436,12 @@ version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + [[package]] name = "scopeguard" version = "1.1.0" @@ -456,6 +468,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "signal-hook-registry" version = "1.2.0" @@ -537,6 +560,8 @@ dependencies = [ "devtimer", "libtdb", "rand", + "serde", + "serde_json", ] [[package]] diff --git a/tdb-bench/Cargo.toml b/tdb-bench/Cargo.toml index 522d336e..309ce1a5 100644 --- a/tdb-bench/Cargo.toml +++ b/tdb-bench/Cargo.toml @@ -11,3 +11,5 @@ rand = "0.7.3" devtimer = "4.0.0" libtdb = {path="../libtdb"} clap = {version = "2.33.3", features=["yaml"]} +serde = {version="1.0.117", features=["derive"]} +serde_json = "1.0.59" diff --git a/tdb-bench/src/cli.yml b/tdb-bench/src/cli.yml index deba6e28..fe1a6779 100644 --- a/tdb-bench/src/cli.yml +++ b/tdb-bench/src/cli.yml @@ -23,27 +23,32 @@ name: TerrabaseDB Benchmark Tool version: 0.4.5 author: Sayan N. about: | - The TerrabaseDB benchmark tool can be used to benchmark TerrabaseDB installations. - If you find any issues, then report one here: https://github.com/terrabasedb/terrabasedb + The TerrabaseDB benchmark tool can be used to benchmark TerrabaseDB installations. + If you find any issues, then report one here: https://github.com/terrabasedb/terrabasedb args: - - connections: - short: c - required: true - long: connections - value_name: count - help: Sets the number of simultaneous clients - takes_value: true - - queries: - short: q - required: true - long: queries - value_name: number - help: Sets the number of queries to run - takes_value: true - - size: - short: s - required: true - long: kvsize - value_name: bytes - help: Sets the size of the key/value pairs - takes_value: true + - connections: + short: c + required: true + long: connections + value_name: count + help: Sets the number of simultaneous clients + takes_value: true + - queries: + short: q + required: true + long: queries + value_name: number + help: Sets the number of queries to run + takes_value: true + - size: + short: s + required: true + long: kvsize + value_name: bytes + help: Sets the size of the key/value pairs + takes_value: true + - json: + required: false + long: json + help: Sets output type to JSON + takes_value: false diff --git a/tdb-bench/src/main.rs b/tdb-bench/src/main.rs index 9f733550..bedba847 100644 --- a/tdb-bench/src/main.rs +++ b/tdb-bench/src/main.rs @@ -29,6 +29,7 @@ mod benchtool { use libtdb::terrapipe; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; + use serde::Serialize; use std::io::prelude::*; use std::net::{self, TcpStream}; use std::sync::mpsc; @@ -117,10 +118,26 @@ mod benchtool { } } + #[derive(Serialize)] + pub struct JSONReportBlock { + report: String, + stat: f64, + } + + impl JSONReportBlock { + pub fn new(report: &'static str, stat: f64) -> Self { + JSONReportBlock { + report: report.to_owned(), + stat, + } + } + } + /// Run the benchmark tool pub fn runner() { let cfg_layout = load_yaml!("./cli.yml"); let matches = App::from_yaml(cfg_layout).get_matches(); + let json_out = matches.is_present("json"); let (max_connections, max_queries, packet_size) = match ( matches.value_of("connections").unwrap().parse::(), matches.value_of("queries").unwrap().parse::(), @@ -201,16 +218,21 @@ mod benchtool { delpool.execute(packet); } drop(delpool); - println!("==========RESULTS=========="); - println!( - "{} GETs/sec", - calc(max_queries, dt.time_in_nanos("GET").unwrap()) - ); - println!( - "{} SETs/sec", - calc(max_queries, dt.time_in_nanos("SET").unwrap()) - ); - println!("==========================="); + let gets_per_sec = calc(max_queries, dt.time_in_nanos("GET").unwrap()); + let sets_per_sec = calc(max_queries, dt.time_in_nanos("SET").unwrap()); + if json_out { + let dat = vec![ + JSONReportBlock::new("GET", gets_per_sec), + JSONReportBlock::new("SET", sets_per_sec), + ]; + let serialized = serde_json::to_string(&dat).unwrap(); + println!("{}", serialized); + } else { + println!("==========RESULTS=========="); + println!("{} GETs/sec", gets_per_sec); + println!("{} SETs/sec", sets_per_sec); + println!("==========================="); + } } /// Returns the number of queries/sec