1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 05:42:40 +01:00

Improve taskmaster behavior on empty queues

Summary:
Right now, taskmasters on empty queues sleep for 30 seconds. With a default setup (4 taskmasters), this averages out to 7.5 seconds between the time you do anything that queues something and the time that the taskmasters start work on it.

On instances, which currently launch a smaller number of taskmasters, this wait is even longer.

Instead, sleep for the number of seconds that there are taskmasters, with a random offset. This makes the average wait to start a task from an empty queue 1 second, and the average maximum load of an empty queue also one query per second.

On loaded instances this doesn't matter, but this should dramatically improve behavior for less-loaded instances without any real tradeoffs.

Test Plan: Started several taskmasters, saw them jitter out of sync and then use short sleeps to give an empty queue about a 1s delay.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D11772
This commit is contained in:
epriestley 2015-02-16 11:30:49 -08:00
parent 3a8cd60bab
commit 2cd77b5b58

View file

@ -3,7 +3,9 @@
final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
protected function run() {
$sleep = 0;
$taskmaster_count = PhabricatorEnv::getEnvConfig('phd.start-taskmasters');
$offset = mt_rand(0, $taskmaster_count - 1);
do {
$tasks = id(new PhabricatorWorkerLeaseQuery())
->setLimit(1)
@ -40,7 +42,21 @@ final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
$sleep = 0;
} else {
$sleep = min($sleep + 1, 30);
// When there's no work, sleep for as many seconds as there are
// active taskmasters.
// On average, this starts tasks added to an empty queue after one
// second. This keeps responsiveness high even on small instances
// without much work to do.
// It also means an empty queue has an average load of one query
// per second even if there are a very large number of taskmasters
// launched.
// The first time we sleep, we add a random offset to try to spread
// the sleep times out somewhat evenly.
$sleep = $taskmaster_count + $offset;
$offset = 0;
}
$this->sleep($sleep);