Skip to content

Commit

Permalink
feat(subscriber): add TOKIO_CONSOLE_BUFFER_CAPACITY env variable (#568
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
iFrostizz authored Jul 5, 2024
1 parent 6ad0def commit a6cf14b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions console-subscriber/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ impl Builder {
self.recording_path = Some(path.into());
}

if let Some(capacity) = usize_from_env("TOKIO_CONSOLE_BUFFER_CAPACITY") {
self.event_buffer_capacity = capacity;
}

self
}

Expand Down Expand Up @@ -765,3 +769,14 @@ fn duration_from_env(var_name: &str) -> Option<Duration> {
),
}
}

fn usize_from_env(var_name: &str) -> Option<usize> {
let var = std::env::var(var_name).ok()?;
match var.parse::<usize>() {
Ok(num) => Some(num),
Err(e) => panic!(
"failed to parse a usize from `{}={:?}`: {}",
var_name, var, e
),
}
}

0 comments on commit a6cf14b

Please sign in to comment.