Skip to content

Commit a6cf14b

Browse files
authored
feat(subscriber): add TOKIO_CONSOLE_BUFFER_CAPACITY env variable (#568)
When the recorded process spawns a lot of tasks and execute a lot of operations, a red message can be seen on the top of the console saying `dropped: 14319181 async_ops, 1601630 tasks, 634586 resources`. That means that the buffer is not sufficiently big to record these and someone in the tokio Discord advised to use the `TOKIO_CONSOLE_BUFFER_CAPACITY` variable to tune that buffer. Turns out it was not a thing, so this pr adds it.
1 parent 6ad0def commit a6cf14b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

console-subscriber/src/builder.rs

+15
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ impl Builder {
333333
self.recording_path = Some(path.into());
334334
}
335335

336+
if let Some(capacity) = usize_from_env("TOKIO_CONSOLE_BUFFER_CAPACITY") {
337+
self.event_buffer_capacity = capacity;
338+
}
339+
336340
self
337341
}
338342

@@ -765,3 +769,14 @@ fn duration_from_env(var_name: &str) -> Option<Duration> {
765769
),
766770
}
767771
}
772+
773+
fn usize_from_env(var_name: &str) -> Option<usize> {
774+
let var = std::env::var(var_name).ok()?;
775+
match var.parse::<usize>() {
776+
Ok(num) => Some(num),
777+
Err(e) => panic!(
778+
"failed to parse a usize from `{}={:?}`: {}",
779+
var_name, var, e
780+
),
781+
}
782+
}

0 commit comments

Comments
 (0)