Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/Parallel/CpuCoreCountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
namespace Rector\Parallel;

use Fidry\CpuCoreCounter\CpuCoreCounter;
use Fidry\CpuCoreCounter\NumberOfCpuCoreNotFound;

final class CpuCoreCountProvider
{
private const int DEFAULT_CORE_COUNT = 2;

public function provide(): int
{
try {
return new CpuCoreCounter()
->getCount();
} catch (NumberOfCpuCoreNotFound) {
return self::DEFAULT_CORE_COUNT;
}
// getAvailableForParallelisation() respects cgroup/CFS quota (docker --cpus, KUBERNETES_CPU_LIMIT),
// unlike getCount() which reports host cores and overcommits workers in containers
return new CpuCoreCounter()
->getAvailableForParallelisation()
->availableCpus;
}
}
Loading