Skip to content

Commit

Permalink
Improve the CPU core count detection
Browse files Browse the repository at this point in the history
See theofidry/cpu-core-counter#11 for the motivations.

The code should be sensibly the same, the notable differences are:

- fixed the deprecated usage of `hw.ncpu`
- /proc/cpuinfo is check _last_
- nproc is checked first (before was not checked at all, it's considered to be more accurate and less convoluted than cpuinfo though)
- not sure about the `return 2`, but this was not too clear [here](phpstan#514 (review)) neither. I could otherwise change the fallback value to return `1` if `proc_open` doesn't exist and 2 otherwise
- add more ways to find the CPU cores count
  • Loading branch information
theofidry committed Dec 8, 2022
1 parent 7f5522e commit eadd1a5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"clue/ndjson-react": "^1.0",
"composer/ca-bundle": "^1.2",
"composer/xdebug-handler": "^3.0.3",
"fidry/cpu-core-counter": "^0.3.0",
"fidry/cpu-core-counter": "^0.3.1",
"hoa/compiler": "3.17.08.08",
"hoa/exception": "^1.0",
"hoa/regex": "1.17.01.13",
Expand Down
63 changes: 62 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/Process/CpuCoreCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public function getNumberOfCpuCores(): int
}

try {
return (new FidryCpuCoreCounter())->getCount();
$this->count = (new FidryCpuCoreCounter())->getCount();
} catch (NumberOfCpuCoreNotFound) {
return 1;
$this->count = 1;
}

return $this->count;
}

}

0 comments on commit eadd1a5

Please sign in to comment.