From 6bf5892125ddc19cfa123767813fd0b73a42f6dc Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Fri, 27 Oct 2017 21:10:32 +0200 Subject: [PATCH] Only tweak-workers if there's something to tweak - tweak-workers should now only be called if there's something in the queue - by moving the test outside, we don't need to call tweak-workers - makes test-t 20 race about 3% faster --- src/core/ThreadPoolScheduler.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/ThreadPoolScheduler.pm b/src/core/ThreadPoolScheduler.pm index ee9861febd3..5b53d5f2ca7 100644 --- a/src/core/ThreadPoolScheduler.pm +++ b/src/core/ThreadPoolScheduler.pm @@ -505,11 +505,11 @@ my class ThreadPoolScheduler does Scheduler { my $smooth-per-core-util = @last-utils.sum; scheduler-debug-status "Per-core utilization (approx): $smooth-per-core-util%"; - if $!general-queue.DEFINITE { + if $!general-queue.DEFINITE && $!general-queue.elems { self!tweak-workers: $!general-queue, $!general-workers, &add-general-worker, $cpu-cores, $smooth-per-core-util; } - if $!timer-queue.DEFINITE { + if $!timer-queue.DEFINITE && $!timer-queue.elems { self!tweak-workers: $!timer-queue, $!timer-workers, &add-timer-worker, $cpu-cores, $smooth-per-core-util; } @@ -552,12 +552,11 @@ my class ThreadPoolScheduler does Scheduler { nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_MSEC) } + # Tweak workers for non-empty queues method !tweak-workers(\queue, \worker-list, &add-worker, $cores, $per-core-util) { - # If there's nothing in the queue, nothing could need an extra worker. - return if queue.elems == 0; # Go through the worker list. If something is not working, then there - # is at lesat one worker free to process things in the queue, so we + # is at least one worker free to process things in the queue, so we # don't need to add one. my int $total-completed; my int $total-times-nothing-completed;