Skip to content

Commit 2582b33

Browse files
committed
perf(runner): adaptive backoff in wait_for_job_slot poll loop
Replace fixed 50ms poll with stepped backoff (50ms -> 100ms after 4 iterations -> 200ms after 20) in src/runner.sh:15. Long-running parallel tests no longer spawn `jobs -r | wc -l` 20 times per second per wait; short tests keep the original responsiveness. Bash 3.0+ compatible.
1 parent bcf5952 commit 2582b33

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/runner.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@ function bashunit::runner::wait_for_job_slot() {
1818
return 0
1919
fi
2020

21+
# Adaptive backoff: start at 50ms, grow to 200ms to reduce `jobs -r` overhead
22+
# on long-running tests while keeping short tests responsive.
23+
local delay="0.05"
24+
local iterations=0
2125
while true; do
2226
local running_jobs
2327
running_jobs=$(jobs -r | wc -l)
2428
if [ "$running_jobs" -lt "$max_jobs" ]; then
2529
break
2630
fi
27-
sleep 0.05
31+
sleep "$delay"
32+
iterations=$((iterations + 1))
33+
if [ "$iterations" -eq 4 ]; then
34+
delay="0.1"
35+
elif [ "$iterations" -eq 20 ]; then
36+
delay="0.2"
37+
fi
2838
done
2939
}
3040

0 commit comments

Comments
 (0)