# physical-cpu-count

> Provides the number of physical cores

Latest version **2.0.0** (published 2016-12-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install physical-cpu-count
pnpm add physical-cpu-count
yarn add physical-cpu-count
bun add physical-cpu-count
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-12-07 |
| First published | 2016-12-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/physical-cpu-count) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sebastiaan Deckers |
| Maintainers | seb |
| Keywords | os, cpu, cpus, length, physical, logical, cores |

## Links

- npm: https://www.npmjs.com/package/physical-cpu-count
- npm.io page: https://npm.io/package/physical-cpu-count

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2016-12-07
- 1.0.0 — 2016-12-05

## README

# 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)

---
_Source: https://npm.io/package/physical-cpu-count · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
