Upgrade sky-bench to use new protocol

next
Sayan Nandan 2 years ago
parent 879e20f6ca
commit 339e3a4a55
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -24,19 +24,17 @@
*
*/
use crate::report::AggregatedReport;
use crate::util;
use crate::{report::AggregatedReport, util};
use devtimer::DevTime;
use libstress::utils::generate_random_byte_vector;
use libstress::PoolConfig;
use libstress::{utils::generate_random_byte_vector, PoolConfig};
use rand::thread_rng;
use skytable::types::RawString;
use skytable::Query;
use std::io::{Read, Write};
use std::net::TcpStream;
mod validation;
use self::validation::SIMPLE_QUERY_SIZE;
use skytable::{types::RawString, Query};
use std::{
io::{Read, Write},
net::TcpStream,
};
pub mod validation;
use self::validation::SQ_RESPCODE_SIZE;
const NOTICE_INIT_BENCH: &str = "Finished sanity test. Initializing benchmark ...";
const NOTICE_INIT_COMPLETE: &str = "Initialization complete! Benchmark started";
@ -79,23 +77,19 @@ pub fn runner(
.arg(format!("default:{}", &temp_table))
.into_raw_query();
// an okay response code size: `*1\n!1\n0\n`:
let response_okay_size =
validation::calculate_monoelement_dataframe_size(1) + SIMPLE_QUERY_SIZE;
let pool_config = PoolConfig::new(
max_connections,
move || {
let mut stream = TcpStream::connect(&host).unwrap();
stream.write_all(&switch_table.clone()).unwrap();
let mut v = vec![0; response_okay_size];
let mut v = vec![0; SQ_RESPCODE_SIZE];
let _ = stream.read_exact(&mut v).unwrap();
stream
},
move |sock, packet: Vec<u8>| {
sock.write_all(&packet).unwrap();
// all `okay`s are returned (for both update and set)
let mut v = vec![0; response_okay_size];
let mut v = vec![0; SQ_RESPCODE_SIZE];
let _ = sock.read_exact(&mut v).unwrap();
},
|socket| {
@ -166,7 +160,8 @@ pub fn runner(
dt.stop_timer("SET").unwrap();
let get_response_packet_size =
validation::calculate_monoelement_dataframe_size(per_kv_size) + SIMPLE_QUERY_SIZE;
validation::calculate_monoelement_dataframe_size(per_kv_size)
+ validation::calculate_metaframe_size(1);
let getpool =
pool_config.with_loop_closure(move |sock: &mut TcpStream, packet: Vec<u8>| {
sock.write_all(&packet).unwrap();
@ -215,7 +210,7 @@ fn init_temp_table(rand: &mut impl rand::Rng, host: &str) -> String {
let mut create_table_connection = TcpStream::connect(host).unwrap();
// create table
create_table_connection.write_all(&create_table).unwrap();
let mut v = [0u8; 8];
let mut v = [0u8; SQ_RESPCODE_SIZE];
let _ = create_table_connection.read_exact(&mut v).unwrap();
temp_table
}

@ -24,8 +24,7 @@
*
*/
/// Just a sweet `*1\n`
pub(super) const SIMPLE_QUERY_SIZE: usize = 3;
pub const SQ_RESPCODE_SIZE: usize = b"*!1\n".len();
/// For a dataframe, this returns the dataframe size for array responses.
///
@ -77,7 +76,7 @@ pub fn calculate_typed_array_dataframe_size(
/// For a monoelement dataframe, this returns the size:
/// ```text
/// <tsymbol><size>\n
/// <element>\n
/// <element>
/// ```
///
/// For an `okay` respcode, it will look like this:
@ -91,7 +90,6 @@ pub fn calculate_monoelement_dataframe_size(per_element_size: usize) -> usize {
s += per_element_size.to_string().len(); // the bytes in size string
s += 1; // the LF
s += per_element_size; // the element itself
s += 1; // the final LF
s
}
@ -102,10 +100,11 @@ pub fn calculate_monoelement_dataframe_size(per_element_size: usize) -> usize {
#[allow(dead_code)] // TODO(@ohsayan): Remove this lint
pub fn calculate_metaframe_size(queries: usize) -> usize {
if queries == 1 {
SIMPLE_QUERY_SIZE
// just `*`
1
} else {
let mut s = 0;
s += 1; // `*`
s += 1; // `$`
s += queries.to_string().len(); // the bytes in size string
s += 1; // `\n`
s
@ -118,11 +117,11 @@ mod tests {
#[test]
fn test_monoelement_calculation() {
assert_eq!(calculate_monoelement_dataframe_size(1), 5);
assert_eq!(calculate_monoelement_dataframe_size(1), 4);
}
#[test]
fn test_simple_query_metaframe_size() {
assert_eq!(calculate_metaframe_size(1), SIMPLE_QUERY_SIZE);
assert_eq!(calculate_metaframe_size(1), 1);
}
#[test]
fn test_typed_array_dataframe_size() {

@ -24,8 +24,7 @@
*
*/
use crate::hoststr;
use crate::sanity_test;
use crate::{benchtool::validation::SQ_RESPCODE_SIZE, hoststr, sanity_test};
use libstress::Workpool;
use rand::thread_rng;
use skytable::Query;
@ -44,7 +43,7 @@ pub fn create_testkeys(host: &str, port: u16, num: usize, connections: usize, si
move || TcpStream::connect(host.clone()).unwrap(),
|sock, packet: Vec<u8>| {
sock.write_all(&packet).unwrap();
let mut buf = [0u8; 8];
let mut buf = [0u8; SQ_RESPCODE_SIZE];
let _ = sock.read_exact(&mut buf).unwrap();
},
|socket| {

Loading…
Cancel
Save