@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+28
+2
resources/sql/autopatches/20181024.drydock.01.commandprops.sql
··· 1 + ALTER TABLE {$NAMESPACE}_drydock.drydock_command 2 + ADD properties LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT};
+2
resources/sql/autopatches/20181024.drydock.02.commanddefaults.sql
··· 1 + UPDATE {$NAMESPACE}_drydock.drydock_command 2 + SET properties = '{}' WHERE properties = '';
+12
src/applications/drydock/storage/DrydockCommand.php
··· 11 11 protected $targetPHID; 12 12 protected $command; 13 13 protected $isConsumed; 14 + protected $properties = array(); 14 15 15 16 private $commandTarget = self::ATTACHABLE; 16 17 ··· 22 23 23 24 protected function getConfiguration() { 24 25 return array( 26 + self::CONFIG_SERIALIZATION => array( 27 + 'properties' => self::SERIALIZATION_JSON, 28 + ), 25 29 self::CONFIG_COLUMN_SCHEMA => array( 26 30 'command' => 'text32', 27 31 'isConsumed' => 'bool', ··· 43 47 return $this->assertAttached($this->commandTarget); 44 48 } 45 49 50 + public function setProperty($key, $value) { 51 + $this->properties[$key] = $value; 52 + return $this; 53 + } 54 + 55 + public function getProperty($key, $default = null) { 56 + return idx($this->properties, $key, $default); 57 + } 46 58 47 59 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 48 60
+7
src/applications/drydock/worker/DrydockResourceUpdateWorker.php
··· 150 150 $this->releaseResource($resource, $reclaimer_phid); 151 151 break; 152 152 } 153 + 154 + // If the command specifies that other worker tasks should be awakened 155 + // after it executes, awaken them now. 156 + $awaken_ids = $command->getProperty('awakenTaskIDs'); 157 + if (is_array($awaken_ids) && $awaken_ids) { 158 + PhabricatorWorker::awakenTaskIDs($awaken_ids); 159 + } 153 160 } 154 161 155 162
+5
src/applications/drydock/worker/DrydockWorker.php
··· 241 241 DrydockLease $lease) { 242 242 $viewer = $this->getViewer(); 243 243 244 + // When the resource releases, we we want to reawaken this task since it 245 + // should be able to start building a new resource right away. 246 + $worker_task_id = $this->getCurrentWorkerTaskID(); 247 + 244 248 $command = DrydockCommand::initializeNewCommand($viewer) 245 249 ->setTargetPHID($resource->getPHID()) 246 250 ->setAuthorPHID($lease->getPHID()) 247 251 ->setCommand(DrydockCommand::COMMAND_RECLAIM) 252 + ->setProperty('awakenTaskIDs', array($worker_task_id)) 248 253 ->save(); 249 254 250 255 $resource->scheduleUpdate();