Created
September 13, 2024 14:41
-
-
Save flaneur2020/bd03c6d9032828c379a86c7ddeb8db32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use object_store::local::LocalFileSystem; | |
use object_store::aws::{DynamoCommit, S3ConditionalPut}; | |
use object_store::{path::Path, ObjectStore}; | |
use rand::{Rng, RngCore}; | |
use slatedb::config::ReadLevel::Uncommitted; | |
use slatedb::config::{DbOptions, ObjectStoreCacheOptions, ReadOptions, WriteOptions}; | |
use slatedb::db::Db; | |
use slatedb::inmemory_cache::InMemoryCacheOptions; | |
use std::path::PathBuf; | |
use std::sync::Arc; | |
use std::time::{Duration, Instant}; | |
#[tokio::main] | |
async fn main() { | |
let mut options = DbOptions::default(); | |
options.wal_enabled = false; | |
let mut block_cache_options = InMemoryCacheOptions::default(); | |
block_cache_options.max_capacity = 128 * 1024 * 1024; | |
block_cache_options.cached_block_size = 1024; | |
options.block_cache_options = Some(block_cache_options); | |
let mut object_cache_options = ObjectStoreCacheOptions::default(); | |
object_cache_options.root_folder = Some(PathBuf::from("/tmp/mycache")); | |
// object_cache_options.root_folder = None; | |
object_cache_options.part_size_bytes = 4 * 1024 * 1024; | |
options.object_store_cache_options = object_cache_options; | |
let object_store = Arc::new(LocalFileSystem::new_with_prefix("/tmp/debug").unwrap()); | |
let db = Db::open_with_opts(Path::from("store2375"), options, object_store) | |
.await | |
.unwrap(); | |
let mut random = rand::thread_rng(); | |
let mut value = vec![0; 8 * 1024]; | |
rand::thread_rng().fill_bytes(value.as_mut_slice()); | |
let duration = Duration::from_secs(10 * 60); | |
let mut puts = 0; | |
let mut gets = 0; | |
let start = Instant::now(); | |
let mut last_update = start; | |
while start.elapsed() < duration { | |
let elapsed_from_update = last_update.elapsed(); | |
if elapsed_from_update >= Duration::from_secs(1) { | |
last_update = Instant::now(); | |
println!( | |
"{:.3} put/s + {:.3} get/s = {:.3} op/s, {:.3} s elapsed", | |
puts as f64 / elapsed_from_update.as_secs_f64(), | |
gets as f64 / elapsed_from_update.as_secs_f64(), | |
(puts + gets) as f64 / elapsed_from_update.as_secs_f64(), | |
elapsed_from_update.as_secs_f64() | |
); | |
puts = 0; | |
gets = 0; | |
} | |
let key: u32 = random.gen_range(0..100_000); | |
if random.gen_range(0..100) < 25 { | |
puts += 1; | |
db.put_with_options( | |
&key.to_be_bytes(), | |
value.as_slice(), | |
&WriteOptions { | |
await_durable: false, | |
}, | |
) | |
.await; | |
} else { | |
gets += 1; | |
db.get_with_options( | |
&key.to_be_bytes(), | |
&ReadOptions { | |
read_level: Uncommitted, | |
}, | |
) | |
.await | |
.unwrap(); | |
} | |
} | |
db.close().await.unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment