mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 07:20:57 +01:00
When a Drydock lease schedules a resource to be reclaimed, awaken the lease update task when the reclaim completes
Summary: Depends on D19751. Ref T13210. When Drydock needs to reclaim an existing unused resource in order to build a new resource to satisfy a lease, the lease which triggered the reclaim currently gets thrown back into the pool with a 15-second yield. If the queue is pretty empty and the reclaim is quick, this can mean that we spend up to 15 extra seconds just waiting for the lease update task to get another shot at building a resource (the resource reclaim may complete in a second or two, but nothing else happens until the yield ends). Instead, when a lease triggers a reclaim, have the reclaim reawaken the lease task when it completes. In the best case, this saves us 15 seconds of waiting. In other cases (the task already completed some other way, the resource gets claimed before the lease gets to it), it's harmless. Test Plan: - Allocated A, A, A working copies with limit 3. Leased a B working copy. - Before patch: allocation took ~32 seconds. - After patch: allocation takes ~17 seconds (i.e., about 15 seconds less). Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13210 Differential Revision: https://secure.phabricator.com/D19752
This commit is contained in:
parent
1f6869a765
commit
e9309fdd6a
5 changed files with 28 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_drydock.drydock_command
|
||||
ADD properties LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT};
|
|
@ -0,0 +1,2 @@
|
|||
UPDATE {$NAMESPACE}_drydock.drydock_command
|
||||
SET properties = '{}' WHERE properties = '';
|
|
@ -11,6 +11,7 @@ final class DrydockCommand
|
|||
protected $targetPHID;
|
||||
protected $command;
|
||||
protected $isConsumed;
|
||||
protected $properties = array();
|
||||
|
||||
private $commandTarget = self::ATTACHABLE;
|
||||
|
||||
|
@ -22,6 +23,9 @@ final class DrydockCommand
|
|||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_SERIALIZATION => array(
|
||||
'properties' => self::SERIALIZATION_JSON,
|
||||
),
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'command' => 'text32',
|
||||
'isConsumed' => 'bool',
|
||||
|
@ -43,6 +47,14 @@ final class DrydockCommand
|
|||
return $this->assertAttached($this->commandTarget);
|
||||
}
|
||||
|
||||
public function setProperty($key, $value) {
|
||||
$this->properties[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProperty($key, $default = null) {
|
||||
return idx($this->properties, $key, $default);
|
||||
}
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -150,6 +150,13 @@ final class DrydockResourceUpdateWorker extends DrydockWorker {
|
|||
$this->releaseResource($resource, $reclaimer_phid);
|
||||
break;
|
||||
}
|
||||
|
||||
// If the command specifies that other worker tasks should be awakened
|
||||
// after it executes, awaken them now.
|
||||
$awaken_ids = $command->getProperty('awakenTaskIDs');
|
||||
if (is_array($awaken_ids) && $awaken_ids) {
|
||||
PhabricatorWorker::awakenTaskIDs($awaken_ids);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -241,10 +241,15 @@ abstract class DrydockWorker extends PhabricatorWorker {
|
|||
DrydockLease $lease) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
// When the resource releases, we we want to reawaken this task since it
|
||||
// should be able to start building a new resource right away.
|
||||
$worker_task_id = $this->getCurrentWorkerTaskID();
|
||||
|
||||
$command = DrydockCommand::initializeNewCommand($viewer)
|
||||
->setTargetPHID($resource->getPHID())
|
||||
->setAuthorPHID($lease->getPHID())
|
||||
->setCommand(DrydockCommand::COMMAND_RECLAIM)
|
||||
->setProperty('awakenTaskIDs', array($worker_task_id))
|
||||
->save();
|
||||
|
||||
$resource->scheduleUpdate();
|
||||
|
|
Loading…
Reference in a new issue