processing-units

1.0.1 • Public • Published

processing-units travis npm

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-units

Usage

const processingUnits = require('processing-units');
 
processingUnits(); // => 4

Motivation

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)"
4

To get the number of processing units we could run nproc

$ docker run -it \
>   --cpuset-cpus="0-1" \
>   node \
>   nproc
2

This is an abstraction.

Behind the scenes

Uses nproc on linux if awilable. When unavailable, returns the number of cpus.

Package Sidebar

Install

npm i processing-units

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • laat