private function determineWorkerCount(Console $console)
{
if (!$this->canReusePort()) {
$this->logger->warning("Environment does not support binding on the same port in multiple processes; " . "only one worker will be used.");
return 1;
}
$cpuCores = $this->countCpuCores();
if (!$console->isArgDefined("workers")) {
return $cpuCores;
}
$workers = $console->getArg("workers");
if ($workers <= 0) {
$this->logger->warning("Invalid worker count specified; integer >= 0 expected. Using CPU core count ...");
return $cpuCores;
}
if ($workers > $cpuCores) {
$s = $cpuCores === 1 ? "" : "s";
$this->logger->warning("Running aerys with more worker processes than available CPU cores is not " . "recommended. Aerys counted {$cpuCores} core{$s}, but you specified {$workers} " . "workers. If you know what you're doing you may safely ignore this message, " . "but it's usually best to let the server determine the worker count.");
}
return $workers;
}