Add generic benchmarking module

next
Sayan Nandan 4 years ago
parent 14e6f43893
commit 12597ce250
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

72
Cargo.lock generated

@ -56,6 +56,12 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "devtimer"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6035b7b9244bf9637cd7ef80b5e1c54404bef92cccd34738c85c45f04ae8b244"
[[package]]
name = "fnv"
version = "1.0.7"
@ -84,6 +90,17 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399"
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hermit-abi"
version = "0.1.15"
@ -271,6 +288,12 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282adbf10f2698a7a77f8e983a74b2d18176c19a7fd32a45446139ae7b02b715"
[[package]]
name = "ppv-lite86"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
[[package]]
name = "proc-macro2"
version = "1.0.18"
@ -289,6 +312,47 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
@ -403,6 +467,8 @@ name = "tsh"
version = "0.3.1"
dependencies = [
"corelib",
"devtimer",
"rand",
"tokio",
]
@ -412,6 +478,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "winapi"
version = "0.2.8"

@ -1,5 +1,5 @@
# This is a simple script which creates a release build and
# moves the release builds into my $HOME/bin folder
cargo build --release
cp target/release/tdb target/release/tsh $HOME/bin
cp -f target/release/tdb target/release/tsh $HOME/bin
echo 'Done!'

@ -8,4 +8,8 @@ edition = "2018"
[dependencies]
corelib = {path = "../corelib"}
tokio = {version = "0.2.22", features = ["full"]}
tokio = {version = "0.2.22", features = ["full"]}
[dev-dependencies]
rand = "0.7.3"
devtimer = "4.0.0"

@ -0,0 +1,91 @@
//! A generic module for benchmarking SET/GET operations
//! **NOTE:** This is experimental and only uses a single connection. So any
//! benchmark comparisons you might do - aren't fair since it is likely
//! that most of them were done using parallel connections
#[cfg(test)]
#[test]
#[ignore]
fn benchmark_server() {
const MAX_TESTS: usize = 1000000;
use corelib::terrapipe::QueryBuilder;
use devtimer::DevTime;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use std::io::{Read, Write};
use std::net::TcpStream;
let rand = thread_rng();
let mut dt = DevTime::new_complex();
let keys: Vec<String> = (0..MAX_TESTS)
.into_iter()
.map(|_| {
let rand_string: String = rand.sample_iter(&Alphanumeric).take(32).collect();
rand_string
})
.collect();
let values: Vec<String> = (0..MAX_TESTS)
.into_iter()
.map(|_| {
let rand_string: String = rand.sample_iter(&Alphanumeric).take(32).collect();
rand_string
})
.collect();
let set_packs: Vec<Vec<u8>> = (0..MAX_TESTS)
.map(|idx| {
let mut q = QueryBuilder::new_simple();
q.add("SET");
q.add(&keys[idx]);
q.add(&values[idx]);
q.prepare_response().1
})
.collect();
let get_packs: Vec<Vec<u8>> = (0..MAX_TESTS)
.map(|idx| {
let mut q = QueryBuilder::new_simple();
q.add("GET");
q.add(&keys[idx]);
q.prepare_response().1
})
.collect();
let del_packs: Vec<Vec<u8>> = (0..MAX_TESTS)
.map(|idx| {
let mut q = QueryBuilder::new_simple();
q.add("DEL");
q.add(&keys[idx]);
q.prepare_response().1
})
.collect();
let mut con = TcpStream::connect("127.0.0.1:2003").unwrap();
dt.create_timer("SET").unwrap();
dt.start_timer("SET").unwrap();
for packet in set_packs {
con.write_all(&packet).unwrap();
// We don't care about the return
let _ = con.read(&mut vec![0; 1024]).unwrap();
}
dt.stop_timer("SET").unwrap();
dt.create_timer("GET").unwrap();
dt.start_timer("GET").unwrap();
for packet in get_packs {
con.write_all(&packet).unwrap();
// We don't need the return
let _ = con.read(&mut vec![0; 1024]).unwrap();
}
dt.stop_timer("GET").unwrap();
// Delete all the created keys
for packet in del_packs {
con.write_all(&packet).unwrap();
// We don't need the return
let _ = con.read(&mut vec![0; 1024]).unwrap();
}
println!(
"Time for {} SETs: {} ns",
MAX_TESTS,
dt.time_in_nanos("SET").unwrap()
);
println!(
"Time for {} GETs: {} ns",
MAX_TESTS,
dt.time_in_nanos("GET").unwrap()
);
}

@ -24,6 +24,9 @@ mod client;
use tokio;
const MSG_WELCOME: &'static str = "TerrabaseDB v0.1.0";
#[cfg(test)]
mod benchmark;
#[tokio::main]
async fn main() {
println!("{}", MSG_WELCOME);

@ -63,20 +63,22 @@ impl<'a> Navigator<'a> {
let ref mut cursor = self.cursor;
let start = cursor.position() as usize;
let end = match beforehint {
// The end will be the current position + the moved position
// The end will be the current position + the moved position - 1
Some(hint) => (start + hint),
None => cursor.get_ref().len() - 1,
};
for i in start..end {
// If the current character is a `\n` byte, then return this slice
if cursor.get_ref()[i] == b'\n' {
if let Some(slice) = cursor.get_ref().get(start..i) {
// Only move the cursor ahead if the bytes could be fetched
// otherwise the next time we try to get anything, the
// cursor would crash. If we don't change the cursor position
// we will keep moving over stale data
cursor.set_position((i + 1) as u64);
return Some(slice);
if let Some(rf) = cursor.get_ref().get(i) {
if *rf == b'\n' {
if let Some(slice) = cursor.get_ref().get(start..i) {
// Only move the cursor ahead if the bytes could be fetched
// otherwise the next time we try to get anything, the
// cursor would crash. If we don't change the cursor position
// we will keep moving over stale data
cursor.set_position((i + 1) as u64);
return Some(slice);
}
}
}
}

Loading…
Cancel
Save