Page MenuHomePhabricator

D16110.diff
No OneTemporary

D16110.diff

diff --git a/src/daemon/PhutilDaemonOverseer.php b/src/daemon/PhutilDaemonOverseer.php
--- a/src/daemon/PhutilDaemonOverseer.php
+++ b/src/daemon/PhutilDaemonOverseer.php
@@ -25,6 +25,7 @@
private $lastPidfile;
private $startEpoch;
private $autoscale = array();
+ private $autoscaleConfig = array();
public function __construct(array $argv) {
PhutilServiceProfiler::getInstance()->enableDiscardMode();
@@ -183,6 +184,18 @@
$daemon->setTraceMemory($this->traceMemory);
$this->addDaemon($daemon, $config);
+
+ $group = idx($config['autoscale'], 'group');
+ if (strlen($group)) {
+ if (isset($this->autoscaleConfig[$group])) {
+ throw new Exception(
+ pht(
+ 'Two daemons are part of the same autoscale group ("%s"). '.
+ 'Each daemon autoscale group must be unique.',
+ $group));
+ }
+ $this->autoscaleConfig[$group] = $config;
+ }
}
$should_reload = false;
@@ -271,17 +284,14 @@
}
private function getAutoscaleGroup(PhutilDaemonHandle $daemon) {
- return $this->getAutoscaleProperty($daemon, 'group');
- }
-
- private function getAutoscaleProperty(
- PhutilDaemonHandle $daemon,
- $key,
- $default = null) {
-
$id = $daemon->getDaemonID();
$autoscale = $this->daemons[$id]['config']['autoscale'];
- return idx($autoscale, $key, $default);
+ return idx($autoscale, 'group');
+ }
+
+ private function getAutoscaleProperty($group_key, $key, $default = null) {
+ $config = $this->autoscaleConfig[$group_key]['autoscale'];
+ return idx($config, $key, $default);
}
public function didBeginWork(PhutilDaemonHandle $daemon) {
@@ -298,11 +308,14 @@
}
public function updateAutoscale() {
+ if ($this->inGracefulShutdown) {
+ return;
+ }
+
foreach ($this->autoscale as $group => $daemons) {
- $daemon = $this->daemons[head_key($daemons)]['handle'];
- $scaleup_duration = $this->getAutoscaleProperty($daemon, 'up', 2);
- $max_pool_size = $this->getAutoscaleProperty($daemon, 'pool', 8);
- $reserve = $this->getAutoscaleProperty($daemon, 'reserve', 0);
+ $scaleup_duration = $this->getAutoscaleProperty($group, 'up', 2);
+ $max_pool_size = $this->getAutoscaleProperty($group, 'pool', 8);
+ $reserve = $this->getAutoscaleProperty($group, 'reserve', 0);
// Don't scale a group if it is already at the maximum pool size.
if (count($daemons) >= $max_pool_size) {
@@ -344,7 +357,7 @@
}
if ($should_scale) {
- $config = $this->daemons[$daemon_id]['config'];
+ $config = $this->autoscaleConfig[$group];
$config['autoscale']['clone'] = true;
@@ -359,6 +372,13 @@
'autoscale' => $config['autoscale'],
));
+ $this->logMessage(
+ 'AUTO',
+ pht(
+ 'Scaling pool "%s" up to %s daemon(s).',
+ $group,
+ new PhutilNumber(count($daemons) + 1)));
+
$this->addDaemon($clone, $config);
// Don't scale more than one pool up per iteration. Otherwise, we could

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 4:04 PM (8 h, 14 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6918901
Default Alt Text
D16110.diff (3 KB)

Event Timeline