Fix logging output even when --json flag is passed

Also, the construction of `Workpool`s was simplified.
next
Sayan Nandan 3 years ago
parent bb14b62805
commit 3619d114b8

@ -111,6 +111,7 @@ All changes in this project will be noted in this file.
- Panic on incorrect data type in `skyd` - Panic on incorrect data type in `skyd`
- `sky-bench` no longer affects your personal data because it creates a random temporary table - `sky-bench` no longer affects your personal data because it creates a random temporary table
under the `default` keyspace under the `default` keyspace
- Fix log output in `sky-bench` even if the `--json` flag was passed
## Version 0.6.3 [2021-06-27] ## Version 0.6.3 [2021-06-27]

@ -168,8 +168,12 @@ where
} }
/// Get a new [`Workpool`] from the current config /// Get a new [`Workpool`] from the current config
pub fn get_pool(&self) -> Workpool<Inp, UIn, Lv, Lp, Ex> { pub fn get_pool(&self) -> Workpool<Inp, UIn, Lv, Lp, Ex> {
self.get_pool_with_workers(self.count)
}
/// Get a [`Workpool`] with the base config but with a different number of workers
pub fn get_pool_with_workers(&self, count: usize) -> Workpool<Inp, UIn, Lv, Lp, Ex> {
Workpool::new( Workpool::new(
self.count, count,
self.init_pre_loop_var.clone(), self.init_pre_loop_var.clone(),
self.on_loop.clone(), self.on_loop.clone(),
self.on_exit.clone(), self.on_exit.clone(),

@ -31,7 +31,6 @@ use crate::util::JSONReportBlock;
use devtimer::DevTime; use devtimer::DevTime;
use libstress::utils::generate_random_string_vector; use libstress::utils::generate_random_string_vector;
use libstress::PoolConfig; use libstress::PoolConfig;
use libstress::Workpool;
use rand::thread_rng; use rand::thread_rng;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::net::TcpStream; use std::net::TcpStream;
@ -42,37 +41,24 @@ pub fn runner(
port: u16, port: u16,
max_connections: usize, max_connections: usize,
max_queries: usize, max_queries: usize,
packet_size: usize, per_kv_size: usize,
json_out: bool, json_out: bool,
) { ) {
sanity_test!(host, port); if let Err(e) = sanity_test!(host, port) {
err!(format!("Sanity test failed with error: {}", e));
}
if !json_out { if !json_out {
println!( println!(
"Initializing benchmark\nConnections: {}\nQueries: {}\nData size (key+value): {} bytes", "Initializing benchmark\nConnections: {}\nQueries: {}\nData size (key+value): {} bytes",
max_connections, max_connections,
max_queries, max_queries,
(packet_size * 2), // key size + value size (per_kv_size * 2), // key size + value size
); );
} }
let host = hoststr!(host, port); let host = hoststr!(host, port);
let host_clone = host.clone();
let mut rand = thread_rng(); let mut rand = thread_rng();
let mut dt = DevTime::new_complex(); let mut dt = DevTime::new_complex();
// create the temporary table to work on
let util_pool = Workpool::new(
1,
move || TcpStream::connect(&host_clone).unwrap(),
|sock, packet: Vec<u8>| {
sock.write_all(&packet).unwrap();
// we don't care much about what's returned
let _ = sock.read(&mut [0; 1024]).unwrap();
},
|socket| {
socket.shutdown(std::net::Shutdown::Both).unwrap();
},
true,
);
let temp_table = libstress::utils::rand_alphastring(10, &mut rand); let temp_table = libstress::utils::rand_alphastring(10, &mut rand);
let create_table = libsky::into_raw_query(&format!( let create_table = libsky::into_raw_query(&format!(
"create table {} keymap(binstr,binstr)", "create table {} keymap(binstr,binstr)",
@ -82,17 +68,12 @@ pub fn runner(
"use default:{} keymap(binstr,binstr)", "use default:{} keymap(binstr,binstr)",
&temp_table &temp_table
)); ));
let drop_table = libsky::into_raw_query(&format!("drop table {}", &temp_table));
util_pool.execute(create_table);
util_pool.execute(switch_table.clone());
let drop_pool = util_pool.clone();
drop(util_pool);
// Create separate connection pools for get and set operations
let pool_config = PoolConfig::new( let pool_config = PoolConfig::new(
max_connections, max_connections,
move || { move || {
let mut stream = TcpStream::connect(&host).unwrap(); let mut stream = TcpStream::connect(&host).unwrap();
stream.write_all(&switch_table).unwrap(); stream.write_all(&switch_table.clone()).unwrap();
let _ = stream.read(&mut [0; 1024]).unwrap(); let _ = stream.read(&mut [0; 1024]).unwrap();
stream stream
}, },
@ -106,9 +87,16 @@ pub fn runner(
}, },
true, true,
); );
let drop_table = libsky::into_raw_query(&format!("drop table {}", &temp_table));
let util_pool = pool_config.get_pool_with_workers(1);
util_pool.execute(create_table);
drop(util_pool);
// Create separate connection pools for get and set operations
let keys: Vec<String> = let keys: Vec<String> =
generate_random_string_vector(max_queries, packet_size, &mut rand, true); generate_random_string_vector(max_queries, per_kv_size, &mut rand, true);
let values = generate_random_string_vector(max_queries, packet_size, &mut rand, false); let values = generate_random_string_vector(max_queries, per_kv_size, &mut rand, false);
/* /*
We create three vectors of vectors: `set_packs`, `get_packs` and `del_packs` We create three vectors of vectors: `set_packs`, `get_packs` and `del_packs`
The bytes in each of `set_packs` has a query packet for setting data; The bytes in each of `set_packs` has a query packet for setting data;
@ -130,6 +118,7 @@ pub fn runner(
if !json_out { if !json_out {
println!("Per-packet size (GET): {} bytes", get_packs[0].len()); println!("Per-packet size (GET): {} bytes", get_packs[0].len());
println!("Per-packet size (SET): {} bytes", set_packs[0].len()); println!("Per-packet size (SET): {} bytes", set_packs[0].len());
println!("Per-packet size (UPDATE): {} bytes", update_packs[0].len());
println!("Initialization complete! Benchmark started"); println!("Initialization complete! Benchmark started");
} }
@ -159,6 +148,7 @@ pub fn runner(
} }
// drop table // drop table
let drop_pool = pool_config.get_pool_with_workers(1);
drop_pool.execute(drop_table); drop_pool.execute(drop_table);
drop(drop_pool); drop(drop_pool);

@ -31,9 +31,10 @@
//! **NOTE:** This is experimental and may show incorrect results - that is, //! **NOTE:** This is experimental and may show incorrect results - that is,
//! the response times may be shown to be slower than they actually are //! the response times may be shown to be slower than they actually are
#[macro_use]
mod util;
mod benchtool; mod benchtool;
mod testkey; mod testkey;
mod util;
use crate::util::DEFAULT_PACKET_SIZE; use crate::util::DEFAULT_PACKET_SIZE;
use crate::util::DEFAULT_QUERY_COUNT; use crate::util::DEFAULT_QUERY_COUNT;
use crate::util::DEFAULT_WORKER_COUNT; use crate::util::DEFAULT_WORKER_COUNT;

@ -33,7 +33,10 @@ use std::io::{Read, Write};
use std::net::{self, TcpStream}; use std::net::{self, TcpStream};
pub fn create_testkeys(host: &str, port: u16, num: usize, connections: usize, size: usize) { pub fn create_testkeys(host: &str, port: u16, num: usize, connections: usize, size: usize) {
sanity_test!(host, port); if let Err(e) = sanity_test!(host, port) {
err!(format!("Sanity test failed with error: {}", e));
}
let host = hoststr!(host, port); let host = hoststr!(host, port);
let mut rand = thread_rng(); let mut rand = thread_rng();
let np = Workpool::new( let np = Workpool::new(

@ -45,15 +45,14 @@ macro_rules! hoststr {
#[macro_export] #[macro_export]
macro_rules! sanity_test { macro_rules! sanity_test {
($host:expr, $port:expr) => { ($host:expr, $port:expr) => {{
println!("Running a sanity test...");
// Run a sanity test // Run a sanity test
if let Err(e) = crate::util::run_sanity_test(&$host, $port) { if let Err(e) = crate::util::run_sanity_test(&$host, $port) {
eprintln!("ERROR: Sanity test failed: {}", e); Err(e)
return; } else {
Ok(())
} }
println!("Sanity test succeeded"); }};
};
} }
#[macro_export] #[macro_export]

Loading…
Cancel
Save