flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
14
BACK_BACK/node_modules/physical-cpu-count/.gitlab-ci.yml
generated
vendored
Executable file
14
BACK_BACK/node_modules/physical-cpu-count/.gitlab-ci.yml
generated
vendored
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
cache:
|
||||
paths:
|
||||
- node_modules
|
||||
|
||||
argon:
|
||||
image: node:argon
|
||||
script:
|
||||
- npm i
|
||||
- npm t
|
||||
|
||||
boron:
|
||||
image: node:boron
|
||||
script:
|
||||
- npm it
|
||||
1
BACK_BACK/node_modules/physical-cpu-count/.npmignore
generated
vendored
Executable file
1
BACK_BACK/node_modules/physical-cpu-count/.npmignore
generated
vendored
Executable file
|
|
@ -0,0 +1 @@
|
|||
test.js
|
||||
31
BACK_BACK/node_modules/physical-cpu-count/README.md
generated
vendored
Executable file
31
BACK_BACK/node_modules/physical-cpu-count/README.md
generated
vendored
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
# physical-cpu-count
|
||||
|
||||
Returns the number of physical CPU cores.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
const physicalCpuCount = require('physical-cpu-count')
|
||||
// 4
|
||||
|
||||
const logicalCpuCount = require('os').cpus().length
|
||||
// 8
|
||||
```
|
||||
|
||||
## Use Case
|
||||
|
||||
Working with clusters of Node.js processes it is common to see code using `os.cpus().length` as the number of child workers to fork. For some workloads this can negatively impact performance on CPUs that use simultaneous multithreading (SMT). Latency is doubled because two processes share the same physical CPU core to get their work done. Additionally there is memory spent for each running worker, as well as time to spawn their processes. It is better to fork no more child processes than there are physical cores.
|
||||
|
||||
## Known Limitations
|
||||
|
||||
Implemented for Linux, macOS, and Windows.
|
||||
|
||||
Other platforms use a naive approach that only looks at Intel CPUs, and assumes every Intel CPU supports, and has enabled, Hyper-Threading with two threads per physical core. These assumptions are not always correct.
|
||||
|
||||
Power management might also make CPU cores unavailable.
|
||||
|
||||
## See also:
|
||||
|
||||
- [Issue `nodejs/node#7730` to implement physical core detection natively in Node.js.](https://github.com/nodejs/node/issues/7730)
|
||||
- [Relevant Stack Overflow answer for macOS and Linux.](https://stackoverflow.com/a/23378780)
|
||||
- [Solutions for Windows WMIC from the command prompt.](http://superuser.com/questions/226552/how-to-tell-how-many-cpus-cores-you-have-on-windows-7)
|
||||
35
BACK_BACK/node_modules/physical-cpu-count/index.js
generated
vendored
Executable file
35
BACK_BACK/node_modules/physical-cpu-count/index.js
generated
vendored
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
'use strict'
|
||||
|
||||
const os = require('os')
|
||||
const childProcess = require('child_process')
|
||||
|
||||
function exec (command) {
|
||||
const output = childProcess.execSync(command, {encoding: 'utf8'})
|
||||
return output
|
||||
}
|
||||
|
||||
let amount
|
||||
const platform = os.platform()
|
||||
|
||||
if (platform === 'linux') {
|
||||
const output = exec('lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l')
|
||||
amount = parseInt(output.trim(), 10)
|
||||
} else if (platform === 'darwin') {
|
||||
const output = exec('sysctl -n hw.physicalcpu_max')
|
||||
amount = parseInt(output.trim(), 10)
|
||||
} else if (platform === 'windows') {
|
||||
const output = exec('WMIC CPU Get NumberOfCores')
|
||||
amount = output.split(os.EOL)
|
||||
.map(function parse (line) { return parseInt(line) })
|
||||
.filter(function numbers (value) { return !isNaN(value) })
|
||||
.reduce(function add (sum, number) { return sum + number }, 0)
|
||||
} else {
|
||||
const cores = os.cpus().filter(function (cpu, index) {
|
||||
const hasHyperthreading = cpu.model.includes('Intel')
|
||||
const isOdd = index % 2 === 1
|
||||
return !hasHyperthreading || isOdd
|
||||
})
|
||||
amount = cores.length
|
||||
}
|
||||
|
||||
module.exports = amount
|
||||
23
BACK_BACK/node_modules/physical-cpu-count/package.json
generated
vendored
Executable file
23
BACK_BACK/node_modules/physical-cpu-count/package.json
generated
vendored
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "physical-cpu-count",
|
||||
"version": "2.0.0",
|
||||
"description": "Provides the number of physical cores",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "snazzy && node test.js"
|
||||
},
|
||||
"keywords": [
|
||||
"os",
|
||||
"cpu",
|
||||
"cpus",
|
||||
"length",
|
||||
"physical",
|
||||
"logical",
|
||||
"cores"
|
||||
],
|
||||
"author": "Sebastiaan Deckers <sebdeckers83@gmail.com>",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"snazzy": "^5.0.0"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue