Skip to content

Commit

Permalink
Properly handle num_consumers for memory headroom calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
hextraza committed Dec 16, 2023
1 parent cf9ad7e commit 5c53f23
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/process/bam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,15 @@ fn block_on_memory_headroom(num_consumers: usize) -> bool {
let start_time = Instant::now();
let total_memory = ALLOCATOR.limit();

let num_cores_for_avg = if num_consumers > 1 {
num_consumers - 1
} else {
num_consumers
};

while start_time.elapsed() < WAIT_TIMEOUT {
let current_memory = ALLOCATOR.allocated();
let average_memory_per_thread = current_memory / (num_consumers - 1);
let average_memory_per_thread = current_memory / num_cores_for_avg;
let remaining_headroom = total_memory - current_memory;
let predicted_memory_use = (average_memory_per_thread as f64) * SAFETY_BUFFER;

Expand Down

0 comments on commit 5c53f23

Please sign in to comment.