1.0.1 • Published 9 years ago
processing-units v1.0.1
processing-units

Get the number of processing units available
Get the number of processing units available to the current process, which may be less than the number of online processors. If this information is not accessible, then print the number of processors installed.
Install
npm install processing-unitsUsage
const processingUnits = require('processing-units');
processingUnits(); // => 4Motivation
When running a docker container with fewer cpus than the host, os.cpus().length returns the number of processors on the host.
$ docker run -it \
> --cpuset-cpus="0-1" \
> node \
> node -e "console.log(os.cpus().length)"
4To get the number of processing units we could run nproc
$ docker run -it \
> --cpuset-cpus="0-1" \
> node \
> nproc
2This is an abstraction.
Behind the scenes
Uses nproc on linux if awilable. When unavailable, returns the number of cpus.