Enable JSON output for `tdb-bench`

This commit enables JSON output for the benchmark tool.
This is an effort to support automated benchmarking, once we do have
such a facility in the future. This closes #37

Signed-off-by: Sayan Nandan <nandansayan@outlook.com>
next
Sayan Nandan 4 years ago
parent 824944e30e
commit cbebda85b0
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

25
Cargo.lock generated

@ -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]]

@ -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"

@ -23,27 +23,32 @@ name: TerrabaseDB Benchmark Tool
version: 0.4.5
author: Sayan N. <ohsayan@outlook.com>
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

@ -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::<usize>(),
matches.value_of("queries").unwrap().parse::<usize>(),
@ -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

Loading…
Cancel
Save