New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cpu-count-js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpu-count-js

A container-friendly alternative to os.cpus().length. Both cgroups v1 and cgroups v2 are supported.

  • 0.1.3
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

cpu-count-js

A container-friendly alternative to os.cpus().length. Both cgroups v1 and cgroups v2 are supported.

Installation

$ npm install cpu-count-js

Usage

cpuCount(min = 1, max = os.cpus().length): Promise<number>

Get available logical CPU count (CPU quota / CPU period for cgroups, fallback to os.cpus().length).

It always returns an integer by ceiling the result. The result can be used as the number of cluster workers.

min or max can be specified to determine the minimal and the maximum CPU count (which also overrides the fallback value).

cpuCountSync(min = 1, max = os.cpus().length): number

A synchronous version of cpuCount.

Examples

$ git clone https://github.com/lujjjh/cpu-count-js.git && cd cpu-count-js

$ docker run --rm -it -v $(pwd):/app node node /app/examples
8
8

$ docker run --rm -it -v $(pwd):/app --cpus=2 node node /app/examples
2
2

$ docker run --rm -it -v $(pwd):/app --cpus=2.1 node node /app/examples
3
3

Keywords

FAQs

Package last updated on 15 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc