Skip to content

Commit

Permalink
Allow customizing number of buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Aug 28, 2024
1 parent 18e8f5b commit 486aacf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/buffet/src/bufpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ pub fn initialize_allocator() -> Result<()> {
#[cfg(feature = "miri")]
let default_num_bufs = 1024;

initialize_allocator_with_num_bufs(default_num_bufs)
let mut num_bufs = default_num_bufs;

if let Ok(env_num_bufs) = std::env::var("BUFFET_NUM_BUFS") {
if let Ok(parsed_num_bufs) = env_num_bufs.parse::<usize>() {
num_bufs = parsed_num_bufs;
}
}

let mem_usage_in_mb: f64 = num_bufs as f64 * (BUF_SIZE as usize) as f64 / 1024.0 / 1024.0;
eprintln!(
"===== Initializing buffer pool with {} buffers, will use {:.2} MiB (override with $BUFFET_NUM_BUFS)",
num_bufs, mem_usage_in_mb
);
initialize_allocator_with_num_bufs(default_num_bufs as _)
}

impl BufMut {
Expand Down

0 comments on commit 486aacf

Please sign in to comment.