Reset hill-climb direction after idle period

When throughput dropped below 0.5 (idle), decline_streak was reset but
direction was preserved. When work resumed, the monitor continued in
whatever direction it held before the idle period — often a shrink
direction that was correct for the previous workload but wrong for the
new burst. This could cause the pool to shrink immediately when it
should be growing.

Reset direction to +1 (grow) when entering the idle branch so the pool
starts the next active period biased toward growth, which is the safer
default under new load.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-09 23:32:47 -04:00
parent b150f2c685
commit 2333f6078a

View file

@ -527,10 +527,14 @@ ThreadPool::monitor_routine(void *arg_)
double prev_ema = ema_throughput;
ema_throughput = ema_alpha * (double)raw_throughput + (1.0 - ema_alpha) * ema_throughput;
// Only adjust if there's meaningful work happening
// Only adjust if there's meaningful work happening.
// Reset direction to +1 (bias toward growth) so a stale
// shrink direction from before the idle period doesn't
// penalize the pool when work resumes.
if(ema_throughput < 0.5 && prev_ema < 0.5)
{
decline_streak = 0;
direction = 1;
continue;
}