Skip to content

Commit 89f1382

Browse files
committed
Different method to compute CPU cores to use
1 parent 23928d9 commit 89f1382

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

conf/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ parameters:
9595
maximumNumberOfProcesses: 8
9696
minimumNumberOfJobsPerProcess: 2
9797
buffer: 134217728 # 128 MB
98+
loadLimit: 1.0
9899
phpVersion: null
99100
polluteScopeWithLoopInitialAssignments: true
100101
polluteScopeWithAlwaysIterableForeach: true

conf/parametersSchema.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ parametersSchema:
9999
processTimeout: float(),
100100
maximumNumberOfProcesses: int(),
101101
minimumNumberOfJobsPerProcess: int(),
102-
buffer: int()
102+
buffer: int(),
103+
loadLimit: schema(float(), nullable())
103104
])
104105
phpVersion: schema(anyOf(
105106
schema(int(), min(70100), max(80599)),

src/Process/CpuCoreCounter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Fidry\CpuCoreCounter\CpuCoreCounter as FidryCpuCoreCounter;
66
use Fidry\CpuCoreCounter\NumberOfCpuCoreNotFound;
7+
use PHPStan\DependencyInjection\AutowiredParameter;
78
use PHPStan\DependencyInjection\AutowiredService;
89

910
#[AutowiredService]
@@ -12,14 +13,21 @@ final class CpuCoreCounter
1213

1314
private ?int $count = null;
1415

16+
public function __construct(
17+
#[AutowiredParameter(ref: '%parallel.loadLimit%')]
18+
private ?float $loadLimit,
19+
)
20+
{
21+
}
22+
1523
public function getNumberOfCpuCores(): int
1624
{
1725
if ($this->count !== null) {
1826
return $this->count;
1927
}
2028

2129
try {
22-
$this->count = (new FidryCpuCoreCounter())->getCount();
30+
$this->count = (new FidryCpuCoreCounter())->getAvailableForParallelisation(0, null, $this->loadLimit)->availableCpus;
2331
} catch (NumberOfCpuCoreNotFound) {
2432
$this->count = 1;
2533
}

0 commit comments

Comments
 (0)