thread_pool: measure cooldown from completion in _maybe_grow_on_pressure

The monitor stores _last_scale_time_usecs after _add_thread_scaling_locked
returns (i.e. after pthread_create), but _maybe_grow_on_pressure stored
a timestamp captured before the add.  Under resource pressure
pthread_create can take non-trivial time, making the effective cooldown
shorter than configured on the fast-path grow.

Move the store after _add_thread_scaling_locked and use a fresh
_now_usecs() call, matching the monitor's behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-10 17:34:22 -04:00
parent 159a5c7b71
commit 375f1f9303

View file

@ -806,9 +806,8 @@ ThreadPool::_maybe_grow_on_pressure()
if(count >= _scaling_config.max_threads)
return;
_last_scale_time_usecs.store(now,std::memory_order_relaxed);
_add_thread_scaling_locked({});
_last_scale_time_usecs.store(_now_usecs(),std::memory_order_relaxed);
syslog(LOG_DEBUG,
"threadpool (%s): fast-path grow to %zu threads (queue full)",
_name.c_str(),