mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-28 19:26:49 +00:00
Improve comments in the blocking threadpool
This commit is contained in:
parent
4cb1faf299
commit
ab613a53e5
1 changed files with 8 additions and 4 deletions
|
@ -50,11 +50,14 @@ lazy_static! {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create up to 10,000 dynamic blocking task worker threads.
|
// Create up to MAX_THREADS dynamic blocking task worker threads.
|
||||||
// Dynamic threads will terminate themselves if they don't
|
// Dynamic threads will terminate themselves if they don't
|
||||||
// receive any work after a timeout that scales down as the
|
// receive any work after a timeout that scales down as the
|
||||||
// total number of threads scales up.
|
// total number of threads scales up.
|
||||||
fn maybe_create_another_blocking_thread() {
|
fn maybe_create_another_blocking_thread() {
|
||||||
|
// We use a `Relaxed` atomic operation because
|
||||||
|
// it's just a heuristic, and would not lose correctness
|
||||||
|
// even if it's random.
|
||||||
let workers = DYNAMIC_THREAD_COUNT.load(Ordering::Relaxed);
|
let workers = DYNAMIC_THREAD_COUNT.load(Ordering::Relaxed);
|
||||||
if workers >= MAX_THREADS {
|
if workers >= MAX_THREADS {
|
||||||
return;
|
return;
|
||||||
|
@ -62,9 +65,7 @@ fn maybe_create_another_blocking_thread() {
|
||||||
|
|
||||||
// We want to give up earlier when we have more threads
|
// We want to give up earlier when we have more threads
|
||||||
// to exert backpressure on the system submitting work
|
// to exert backpressure on the system submitting work
|
||||||
// to do. We use a `Relaxed` atomic operation because
|
// to do.
|
||||||
// it's just a heuristic, and would not lose correctness
|
|
||||||
// even if it's random.
|
|
||||||
let utilization_percent = (workers * 100) / MAX_THREADS;
|
let utilization_percent = (workers * 100) / MAX_THREADS;
|
||||||
let relative_wait_limit = (WAIT_SPREAD * utilization_percent) / 100;
|
let relative_wait_limit = (WAIT_SPREAD * utilization_percent) / 100;
|
||||||
|
|
||||||
|
@ -93,6 +94,9 @@ fn maybe_create_another_blocking_thread() {
|
||||||
// timeout is dynamic, and when we have more threads we block
|
// timeout is dynamic, and when we have more threads we block
|
||||||
// for longer before spinning up another thread for backpressure.
|
// for longer before spinning up another thread for backpressure.
|
||||||
fn schedule(t: async_task::Task<()>) {
|
fn schedule(t: async_task::Task<()>) {
|
||||||
|
// We use a `Relaxed` atomic operation because
|
||||||
|
// it's just a heuristic, and would not lose correctness
|
||||||
|
// even if it's random.
|
||||||
let workers = DYNAMIC_THREAD_COUNT.load(Ordering::Relaxed);
|
let workers = DYNAMIC_THREAD_COUNT.load(Ordering::Relaxed);
|
||||||
|
|
||||||
// We want to block for longer when we have more threads to
|
// We want to block for longer when we have more threads to
|
||||||
|
|
Loading…
Reference in a new issue