Add basic stress-test crate

next
Sayan Nandan 3 years ago
parent 6b4d27cf43
commit 15d2b1922c

11
Cargo.lock generated

@ -413,6 +413,9 @@ dependencies = [
[[package]]
name = "libstress"
version = "0.1.0"
dependencies = [
"num_cpus",
]
[[package]]
name = "lock_api"
@ -933,6 +936,14 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a"
[[package]]
name = "stress-test"
version = "0.1.0"
dependencies = [
"libstress",
"skytable",
]
[[package]]
name = "strsim"
version = "0.8.0"

@ -5,7 +5,8 @@ members = [
"libsky",
"sky-bench",
"sky-macros",
"libstress"
"libstress",
"stress-test"
]
[profile.release]

@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
num_cpus = "1.13.0"

@ -51,21 +51,21 @@ impl Worker {
fn new<Inp: 'static, UIn>(
job_receiver: Arc<Mutex<mpsc::Receiver<JobType<UIn>>>>,
init_pre_loop_var: impl Fn() -> Inp + 'static + Send,
on_exit: impl Fn(&Inp) + Send + 'static,
on_loop: impl Fn(&Inp, UIn) + Send + Sync + 'static,
on_exit: impl Fn(&mut Inp) + Send + 'static,
on_loop: impl Fn(&mut Inp, UIn) + Send + Sync + 'static,
) -> Self
where
UIn: Send + Sync + 'static,
{
let thread = thread::spawn(move || {
let on_loop = on_loop;
let pre_loop_var = init_pre_loop_var();
let mut pre_loop_var = init_pre_loop_var();
loop {
let action = job_receiver.lock().unwrap().recv().unwrap();
match action {
JobType::Task(tsk) => on_loop(&pre_loop_var, tsk),
JobType::Task(tsk) => on_loop(&mut pre_loop_var, tsk),
JobType::Nothing => {
on_exit(&pre_loop_var);
on_exit(&mut pre_loop_var);
break;
}
}
@ -80,9 +80,9 @@ impl Worker {
impl<Inp: 'static, UIn, Lp, Lv, Ex> Clone for Workpool<Inp, UIn, Lv, Lp, Ex>
where
UIn: Send + Sync + 'static,
Ex: Fn(&Inp) + Send + Sync + 'static + Clone,
Ex: Fn(&mut Inp) + Send + Sync + 'static + Clone,
Lv: Fn() -> Inp + Send + Sync + 'static + Clone,
Lp: Fn(&Inp, UIn) + Clone + Send + Sync + 'static,
Lp: Fn(&mut Inp, UIn) + Clone + Send + Sync + 'static,
{
fn clone(&self) -> Self {
Workpool::new(
@ -124,9 +124,9 @@ pub struct Workpool<Inp, UIn, Lv, Lp, Ex> {
impl<Inp: 'static, UIn, Lv, Ex, Lp> Workpool<Inp, UIn, Lv, Lp, Ex>
where
UIn: Send + Sync + 'static,
Ex: Fn(&Inp) + Send + Sync + 'static + Clone,
Ex: Fn(&mut Inp) + Send + Sync + 'static + Clone,
Lv: Fn() -> Inp + Send + Sync + 'static + Clone,
Lp: Fn(&Inp, UIn) + Send + Sync + 'static + Clone,
Lp: Fn(&mut Inp, UIn) + Send + Sync + 'static + Clone,
{
/// Create a new workpool
pub fn new(count: usize, init_pre_loop_var: Lv, on_loop: Lp, on_exit: Ex) -> Self {
@ -157,6 +157,12 @@ where
pub fn execute(&mut self, inp: UIn) {
self.job_distributor.send(JobType::Task(inp)).unwrap();
}
pub fn new_default_threads(init_pre_loop_var: Lv, on_loop: Lp, on_exit: Ex) -> Self {
// we'll naively use the number of CPUs present on the system times 2 to determine
// the number of workers (sure the scheduler does tricks all the time)
let worker_count = num_cpus::get() * 2;
Self::new(worker_count, init_pre_loop_var, on_loop, on_exit)
}
}
impl<Inp, UIn, Lv, Lp, Ex> Drop for Workpool<Inp, UIn, Lp, Lv, Ex> {

@ -101,7 +101,7 @@ mod benchtool {
let mut np = Workpool::new(
10,
move || TcpStream::connect(host.clone()).unwrap(),
|mut sock, packet: Vec<u8>| {
|sock, packet: Vec<u8>| {
sock.write_all(&packet).unwrap();
let _ = sock.read(&mut vec![0; 1024]).unwrap();
},
@ -164,7 +164,7 @@ mod benchtool {
let mut setpool = Workpool::new(
10,
move || TcpStream::connect(host.clone()).unwrap(),
|mut sock, packet: Vec<u8>| {
|sock, packet: Vec<u8>| {
sock.write_all(&packet).unwrap();
// we don't care much about what's returned
let _ = sock.read(&mut vec![0; 1024]).unwrap();

@ -0,0 +1,11 @@
[package]
name = "stress-test"
version = "0.1.0"
authors = ["Sayan Nandan <nandansayan@outlook.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libstress = {path = "../libstress"}
skytable = {git = "https://github.com/skytable/client-rust.git", branch = "next"}

@ -0,0 +1,44 @@
/*
* Created on Wed Jun 16 2021
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2021, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use libstress::Workpool;
use skytable::Connection;
use skytable::Query;
use skytable::{Element, Response};
fn main() {
let mut pool = Workpool::new(
10,
|| Connection::new("127.0.0.1", 2003).unwrap(),
|con, query: Query| {
let ret = con.run_simple_query(&query).unwrap();
assert_eq!(ret, Response::Item(Element::String("HEY!".to_owned())));
},
|_| {},
);
loop {
pool.execute(Query::from("HEYA"));
}
}
Loading…
Cancel
Save