Enforce cooldown_usecs in monitor hill-climb loop

cooldown_usecs was only checked in _maybe_grow_on_pressure (the
fast-path enqueue grow). The monitor thread scaled every
sample_interval_usecs unconditionally, so a recent fast-path grow
could be immediately followed by a monitor grow, defeating the
cooldown.

Check _last_scale_time_usecs against cooldown_usecs before applying
any monitor scaling decision, making the cooldown global across both
scaling paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-09 21:22:47 -04:00
parent 2aa2311a55
commit 13fc1b27df

View file

@ -536,6 +536,15 @@ ThreadPool::monitor_routine(void *arg_)
}
}
// Respect the global cooldown so the monitor and fast-path
// pressure grow don't step on each other.
{
std::uint64_t now = _now_usecs();
std::uint64_t last = btp->_last_scale_time_usecs.load(std::memory_order_relaxed);
if((now - last) < (std::uint64_t)btp->_scaling_config.cooldown_usecs)
continue;
}
if(direction > 0 && count < btp->_scaling_config.max_threads)
{
btp->add_thread();