Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sled Experiment for watching the consumed disk_space
use sled;
fn main() {
let db = sled::open("/path/to/sled").unwrap();
//let db = sled::Config::default().temporary(true).open().unwrap();
let tree = db.open_tree("events").unwrap();
let mut cnt = 0_u64;
let mut size = 0_u64;
let mut last_id: Option<u64> = None;
while cnt < 1_000_000_000 {
let id = db.generate_id().unwrap();
let write: [u8; 8] = unsafe { std::mem::transmute(id.to_be()) };
let payload = vec![100; 10000];
tree.insert(write, payload).unwrap();
if let Some(last) = last_id {
let last_key: [u8; 8] = unsafe { std::mem::transmute(last.to_be()) };
tree.remove(last_key).unwrap();
}
last_id = Some(id);
if cnt % 1_000 == 0 {
let cur_size = db.size_on_disk().unwrap();
if cnt % 1_000_000 == 0 {
println!("{}", cur_size);
}
if cur_size < size {
println!("db shrunk! From {} to {} bytes", size, cur_size);
}
size = cur_size;
}
cnt += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment