Skip to content

Commit

Permalink
Updates API to use bytes instead of String and bincode as storage and…
Browse files Browse the repository at this point in the history
… serialization
  • Loading branch information
RPallas92 committed Nov 6, 2024
1 parent cae9aae commit d99bbf2
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 212 deletions.
146 changes: 63 additions & 83 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "graus-db"
version = "0.1.0"
version = "0.2.0"
authors = ["Ricardo Pallas Roman <[email protected]>"]
description = "A high-performance, thread-safe key-value embedded data store."
edition = "2018"
Expand All @@ -13,10 +13,12 @@ documentation = "https://github.com/rpallas92/GrausDB"
readme = "README.md"

[dependencies]
bincode = "1.3.3"
bytes = "1.8.0"
crossbeam-skiplist = "0.1"
log = "0.4.6"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_bytes = "0.11.15"
thiserror = "1.0"

[dev-dependencies]
Expand All @@ -27,4 +29,4 @@ walkdir = "2.2.7"

[[bench]]
name = "graus_db_single_thread"
harness = false
harness = false
21 changes: 11 additions & 10 deletions benches/graus_db_single_thread.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use graus_db::GrausDb;
use rand::prelude::*;
use std::convert::TryInto;
use tempfile::TempDir;

fn set_bench(c: &mut Criterion) {
Expand All @@ -13,7 +14,7 @@ fn set_bench(c: &mut Criterion) {
},
|(store, _temp_dir)| {
for i in 1..(1 << 12) {
store.set(format!("key{}", i), "value".to_string()).unwrap();
store.set(format!("key{}", i), b"value").unwrap();
}
},
BatchSize::SmallInput,
Expand All @@ -30,16 +31,18 @@ fn update_if_bench(c: &mut Criterion) {
let temp_dir = TempDir::new().unwrap();
let store = GrausDb::open(temp_dir.path()).unwrap();
let key = "key1";
store.set(key.to_owned(), "3500".to_string()).unwrap();
let value: u64 = 3500;
store.set(key.to_owned(), &value.to_le_bytes()).unwrap();
(store, temp_dir, key)
},
|(store, _temp_dir, key)| {
let update_fn = |value: String| {
let num = value.parse::<i32>().unwrap();
(num - 1).to_string()
let update_fn = |value: &mut [u8]| {
let num = u64::from_le_bytes(value.try_into().expect("incorrect length"));
let incremented_num = num - 1;
value.copy_from_slice(&incremented_num.to_le_bytes());
};
let predicate = |value: String| {
let num = value.parse::<i32>().unwrap();
let predicate = |value: &[u8]| {
let num = u64::from_le_bytes(value.try_into().expect("incorrect length"));
num > 0
};

Expand All @@ -65,9 +68,7 @@ fn get_bench(c: &mut Criterion) {
let temp_dir = TempDir::new().unwrap();
let store = GrausDb::open(temp_dir.path()).unwrap();
for key_i in 1..(1 << i) {
store
.set(format!("key{}", key_i), "value".to_string())
.unwrap();
store.set(format!("key{}", key_i), b"value").unwrap();
}
let mut rng = SmallRng::from_seed([0; 16]);
b.iter(|| {
Expand Down
Loading

0 comments on commit d99bbf2

Please sign in to comment.