Skip to content

Commit

Permalink
IBX-9316: Fixed CPU count for Ibexa Cloud (#461)
Browse files Browse the repository at this point in the history
For more details see https://issues.ibexa.co/browse/IBX-9316 and #461

Key changes:

* Fixed CPU count for Ibexa Cloud
  • Loading branch information
reithor authored Dec 20, 2024
1 parent 806270b commit 90f0c81
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 === '\\') {
Expand Down

0 comments on commit 90f0c81

Please sign in to comment.