Exemplo n.º 1
0
 function __construct($config = array())
 {
     $this->config = Scalr_Util_Arrays::mergeReplaceRecursive(self::getConfig(), $config);
     foreach ($config as $k => $v) {
         if (property_exists($this, $k)) {
             $this->{$k} = $v;
         }
     }
 }
Exemplo n.º 2
0
 static function getConfig()
 {
     return Scalr_Util_Arrays::mergeReplaceRecursive(parent::getConfig(), array("processPool" => array("size" => 3), "memoryLimitTick" => 10000));
 }
Exemplo n.º 3
0
 static function getConfig()
 {
     return Scalr_Util_Arrays::mergeReplaceRecursive(parent::getConfig(), array("description" => "MultiProcess cronjob. Do Network, I/O and CPU jobs in a 5 workers pool", "processPool" => array("size" => 5, "daemonize" => true, "preventParalleling" => true, "workerMemoryLimit" => 32000, "workerMemoryLimitTick" => 1000, "termTimeout" => 2000), "fileName" => __FILE__));
 }
Exemplo n.º 4
0
 private function computeConfig($jobClassName)
 {
     $jobConfig = call_user_func(array($jobClassName, "getConfig"));
     if (is_subclass_of($jobClassName, "Scalr_System_Cronjob_MultiProcess_Worker")) {
         if ($jobConfig["distributed"]) {
             $inheritConfig = Scalr_System_Cronjob_Distributed::getConfig();
         } else {
             $inheritConfig = Scalr_System_Cronjob_MultiProcess::getConfig();
         }
     } else {
         $inheritConfig = Scalr_System_Cronjob::getConfig();
     }
     return Scalr_Util_Arrays::mergeReplaceRecursive($inheritConfig, $jobConfig);
 }
Exemplo n.º 5
0
 protected function init($options = null)
 {
     $this->logger = Logger::getLogger(__CLASS__);
     // Merge configurations. this config, ini config
     // Get configuration filename from ENV, CLI options, own static config, default: "dcron.ini"
     $configFileName = $_ENV[self::ENV_CONFIG_FILE_PROPERTY];
     if (!$configFileName) {
         if ($options && $options["getopt"]) {
             $configFileName = $options["getopt"]->getOption(self::GETOPT_CONFIG_FILE);
         }
     }
     if (!$configFileName) {
         if ($this->config["iniFile"]) {
             $configFileName = $this->config["iniFile"];
         }
     }
     if (!$configFileName) {
         $configFileName = "dcron.ini";
     }
     // Load configuration
     $configString = @file_get_contents($configFileName);
     if (!$configString) {
         throw new Scalr_System_Cronjob_Exception(sprintf("Cannot load configuration file '%s'", $configFileName));
     }
     $iniConfig = Scalr_Util_Compat::parseIniString($configString, true);
     if (!$iniConfig) {
         throw new Scalr_System_Cronjob_Exception(sprintf("Cannot parse configuration file '%s'", $configFileName));
     }
     // XXX Temporary hack
     if ($iniConfig["remoteConfigUrl"]) {
         $this->logger->debug(sprintf("Fetch configuration from '%s'", $iniConfig["remoteConfigUrl"]));
         $configString = @file_get_contents($iniConfig["remoteConfigUrl"]);
         if (!$configString) {
             throw new Scalr_System_Cronjob_Exception(sprintf("Cannot load configuration file '%s'", $iniConfig["remoteConfigUrl"]));
         }
         $iniConfig = Scalr_Util_Compat::parseIniString($configString, true);
         if (!$iniConfig) {
             throw new Scalr_System_Cronjob_Exception(sprintf("Cannot parse configuration file '%s'", $iniConfig["remoteConfigUrl"]));
         }
     }
     // Apply configuration. Worker configuration is already applied
     $this->config = Scalr_Util_Arrays::mergeReplaceRecursive($iniConfig, $this->config);
     foreach ($this->config as $k => $v) {
         if (property_exists($this, $k)) {
             $this->{$k} = $v;
         }
     }
     // Get nodeName from ENV, CLI options, UNIX hostname command output
     $nodeName = $_ENV[self::ENV_NONE_NAME_PROPERTY];
     if (!$nodeName) {
         if ($options && $options["getopt"]) {
             $nodeName = $options["getopt"]->getOption(self::GETOPT_NONE_NAME);
         }
     }
     if (!$nodeName) {
         $nodeName = php_uname("n");
     }
     if (!$nodeName) {
         throw new Scalr_System_Cronjob_Exception('Cannot detect current nodeName. ' . 'Use $_ENV or CLI options to setup nodeName');
     }
     $this->nodeName = $nodeName;
     $this->logger->info(sprintf("Initialize distributed cronjob (nodeName: %s, quorum: %d, distributedConfig: %s)", $this->nodeName, $this->config["quorum"], $configFileName));
     // Create elector
     $electorCls = $this->config["electorCls"];
     if (!$electorCls) {
         $electorCls = "Scalr_System_Cronjob_Distributed_DefaultElector";
     }
     $this->logger->info("Set elector: {$electorCls}");
     $this->elector = new $electorCls($this->nodeName, $this->config);
     // ZOO
     $this->jobZPath = "{$this->config["jobsZPath"]}/{$this->jobName}";
     $this->zookeeper = new Scalr_Service_Zookeeper($this->config["zookeeper"]);
     $this->nodeRegistry = new Scalr_System_Cronjob_Distributed_NodeRegistry(array("zookeeper" => $this->zookeeper, "path" => "{$this->jobZPath}/nodes", "node" => $this->nodeName));
     $this->leaderElection = new Scalr_Service_Zookeeper_Election(array("zookeeper" => $this->zookeeper, "path" => "{$this->jobZPath}/election", "timeout" => $this->electionTimeout, "quorum" => $this->quorum));
     $this->returnedNodesQueue = new Scalr_Service_Zookeeper_Queue(array("zookeeper" => $this->zookeeper, "path" => "{$this->jobZPath}/returned-queue"));
     // Work queue
     $this->globalWorkQueue = new Scalr_Service_Zookeeper_Queue(array("zookeeper" => $this->zookeeper, "path" => $this->jobZPath . "/work-queue"));
     // Local queue
     $this->config["processPool"]["workQueue"] = new Scalr_System_Ipc_ShmQueue(array("name" => "scalr.system.cronjob.multiprocess.workQueue-" . posix_getpid(), "blocking" => true, "autoInit" => true));
     // Call parent initialization
     parent::init($options);
 }
Exemplo n.º 6
0
    if (!array_key_exists($quarter, $data)) {
        $data[$quarter] = ["quarter" => $row["quarter"] - 1, "year" => $row["year"], "days" => [], "dataByPlatform" => []];
    }
    if (!array_key_exists($row["platform"], $data[$quarter]["dataByPlatform"])) {
        $data[$quarter]["dataByPlatform"][$row["platform"]] = [];
    }
    $data[$quarter]["dataByPlatform"][$row["platform"]][] = $row["value"];
    $data[$quarter]["days"][substr($row["time"], 0, 10)] = true;
}
if ($format == 'csv') {
    $csvRowTemplate = ['year' => '', 'quarter' => '', 'partial' => ''];
}
foreach ($data as $quarter => &$set) {
    ksort($set["dataByPlatform"]);
    foreach ($set["dataByPlatform"] as $platform => &$report) {
        $report = \Scalr_Util_Arrays::percentile($report, 90, true);
        if ($format == 'csv' && !array_key_exists($platform, $csvRowTemplate)) {
            $csvRowTemplate[$platform] = 0;
        }
    }
}
foreach ($data as $quarter => &$set) {
    $uniqueDates = count($set["days"]);
    $partial = $quarterDays[$set["quarter"]] + ($set["quarter"] === 0 && ($set["year"] % 4 === 0 && $set["year"] % 100 !== 0 || $set["year"] % 400 === 0) ? 1 : 0) === $uniqueDates ? false : $uniqueDates;
    if ($format == 'csv') {
        $csvData[] = array_merge($csvRowTemplate, ['year' => $set["year"], 'quarter' => $set["quarter"] + 1, 'partial' => empty($partial) ? '' : $partial], $set["dataByPlatform"]);
    } else {
        foreach ($set["dataByPlatform"] as $platform => &$report) {
            $platformName = array_key_exists($platform, $allPlatforms) ? $allPlatforms[$platform] : $platform;
            if (empty($report)) {
                $report = str_pad($platformName . ":", 32) . "0";