From 90f0c81e83acd62f214adac4fdebb37a64c4edfd Mon Sep 17 00:00:00 2001 From: Thorsten Reiter <34274688+reithor@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:36:02 +0100 Subject: [PATCH] IBX-9316: Fixed CPU count for Ibexa Cloud (#461) For more details see https://issues.ibexa.co/browse/IBX-9316 and https://github.com/ibexa/core/pull/461 Key changes: * Fixed CPU count for Ibexa Cloud --- src/bundle/Core/Command/ReindexCommand.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bundle/Core/Command/ReindexCommand.php b/src/bundle/Core/Command/ReindexCommand.php index bd8d6cc246..8af26d403b 100644 --- a/src/bundle/Core/Command/ReindexCommand.php +++ b/src/bundle/Core/Command/ReindexCommand.php @@ -28,6 +28,9 @@ class ReindexCommand extends Command implements BackwardCompatibleCommand { + private const IBEXA_CLOUD_CONFIG_FILE = '/run/config.json'; + private const LINUX_CPUINFO_FILE = '/proc/cpuinfo'; + /** @var \Ibexa\Core\Search\Common\Indexer|\Ibexa\Core\Search\Common\IncrementalIndexer */ private $searchIndexer; @@ -450,9 +453,17 @@ private function getPhpPath() private function getNumberOfCPUCores() { $cores = 1; - if (is_file('/proc/cpuinfo')) { + if (isset($_SERVER['PLATFORM_BRANCH']) && is_readable(self::IBEXA_CLOUD_CONFIG_FILE) && is_file(self::IBEXA_CLOUD_CONFIG_FILE)) { + // Ibexa Cloud: read #cpus from config + $configJsonEncoded = file_get_contents(self::IBEXA_CLOUD_CONFIG_FILE); + if ($configJsonEncoded === false) { + return 1; + } + $configJson = json_decode($configJsonEncoded); + $cores = isset($configJson->info->limits->cpu) ? max(1, (int) ($configJson->info->limits->cpu)) : 1; + } elseif (is_readable(self::LINUX_CPUINFO_FILE) && is_file(self::LINUX_CPUINFO_FILE)) { // Linux (and potentially Windows with linux sub systems) - $cpuinfo = file_get_contents('/proc/cpuinfo'); + $cpuinfo = file_get_contents(self::LINUX_CPUINFO_FILE); preg_match_all('/^processor/m', $cpuinfo, $matches); $cores = count($matches[0]); } elseif (DIRECTORY_SEPARATOR === '\\') {