num_cpus

A small Rust crate for counting the logical and physical CPU cores on the current machine.

Library
Cargo
v1.17.0
629stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity4
Maintenance20
Community76
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture70
Code Quality75
Innovation50
Learning Curve92

num_cpus is a focused Rust utility crate that answers one question: how many CPUs does the current machine (or container) have available? It exposes num_cpus::get() for logical core count and num_cpus::get_physical() for physical core count, with platform-specific implementations for Linux, macOS, Windows, BSD variants, and other Unix-likes, including cgroup-aware detection so containerized workloads report the CPU quota they’re actually allowed to use rather than the host machine’s full core count.

Despite its narrow scope, num_cpus is one of the most widely depended-upon crates in the Rust ecosystem (500M+ total downloads) because it’s the standard way for thread pools, async runtimes, and parallel-processing libraries to size themselves appropriately without hand-rolling platform-specific CPU detection.

What You Get

  • num_cpus::get() returning the number of logical CPUs available to the current process
  • num_cpus::get_physical() returning the number of physical CPU cores, distinct from logical/hyperthreaded cores
  • Cgroup v1/v2-aware detection so containerized processes report their CPU quota, not the host’s full core count
  • Platform-specific implementations covering Linux, macOS, Windows, and various BSD/Unix variants
  • hermit-abi support for the Hermit unikernel target

Common Use Cases

  • Sizing a thread pool (e.g. Rayon, Tokio) to match the number of available CPU cores
  • Configuring worker/connection counts in servers based on available parallelism
  • Detecting the actual CPU quota inside a Docker/Kubernetes container rather than the host’s total cores
  • Build scripts or CLI tools that parallelize work based on detected core count
  • Any library needing a sensible default level of parallelism without requiring user configuration

Under The Hood

Architecture - The entire crate is implemented in a single src/lib.rs (491 lines) using conditional compilation (#[cfg(...)]) to select the correct core-counting strategy per target OS: reading /proc/cpuinfo and cgroup CPU quota files on Linux, calling sysctl via libc on macOS/BSD, and using the Windows API on Windows. The fixtures/cgroups and fixtures/cgroups2 directories hold sample cgroup filesystem layouts used to test the container-aware detection logic against both cgroup v1 and v2 formats.

Tech Stack - Pure Rust with a single dependency, libc, gated to non-Windows targets via [target.'cfg(not(windows))'.dependencies], plus an optional hermit-abi dependency for the Hermit unikernel target. This minimal, platform-gated dependency tree is intentional given how many downstream crates depend on num_cpus transitively.

Code Quality - The crate includes 2 inline #[test] functions plus an examples/values.rs example demonstrating both get() and get_physical(), and ships dedicated cgroup fixture data specifically to test container-quota detection paths that are otherwise hard to exercise in CI. GitHub’s health signal shows low recent development activity and infrequent maintenance, which is typical and appropriate for a small, stable, feature-complete utility crate rather than a sign of an abandoned project — the core functionality (reading CPU counts) doesn’t need frequent changes.

API Design - The API is two functions: get() and get_physical(), both zero-argument and returning a plain usize. There’s no configuration, builder pattern, or error type to handle — a deliberate minimalism appropriate for a crate whose entire job is answering one simple platform query, though it does mean callers can’t easily override or mock the detected count for testing without wrapping it themselves.

Used by 12 apps in this directory

TypeScript
55%
Other

Cap

Team Chat · Video Conferencing

20,986

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
65
Dependency
Built with
TypeScript55%
Rust40%
Updated yesterday
Rust
93%
Apache 2.0

helix-db

Databases

5,803

A graph-vector database built from scratch in Rust that unifies graph traversal, vector search, key-value, and relational storage into a single platform for AI applications.

View details
85
Repo Health
80
Technical
81
Dependency
Built with
Rust93%
Updated today
TypeScript
69%
Apache 2.0

Laminar

AI Development · Monitoring

3,180

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
85
Repo Health
76
Technical
70
Dependency
Built with
TypeScript69%
Rust29%
Updated yesterday
JavaScript
57%
Other

Lokus

Note Taking · Knowledge Management

774

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
78
Repo Health
75
Technical
65
Dependency
Built with
JavaScript57%
HTML24%
Updated 1 weeks ago
Python
33%
Apache 2.0

magika

Developer Tools · Security

17,958

AI-powered file type detection that identifies 200+ content types with ~99% accuracy in milliseconds using a compact deep learning model.

View details
75
Repo Health
85
Technical
77
Dependency
Built with
Python33%
Rust26%
TypeScript18%
Updated today
Rust
100%
Other

Meilisearch

Search

59,012

Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.

View details
90
Repo Health
88
Technical
68
Dependency
Built with
Rust100%
Updated 5 days ago
Rust
89%
Apache 2.0

Qdrant

Databases · AI Development · Search

34,058

Open-source vector database and search engine built in Rust for production-grade AI applications — from semantic search to RAG pipelines and recommendation systems.

View details
92
Repo Health
87
Technical
69
Dependency
Built with
Rust89%
Updated yesterday
Rust
68%
AGPL 3.0

RustDesk

Networking

121,233

Open-source, self-hosted remote desktop built in Rust — your data, your infrastructure, no third-party cloud.

View details
93
Repo Health
84
Technical
75
Dependency
Built with
Rust68%
Dart24%
Updated today
Rust
77%
AGPL 3.0

Spacedrive

File Storage · Collaboration

38,790

One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.

View details
60
Repo Health
84
Technical
65
Dependency
Built with
Rust77%
TypeScript20%
Updated 3 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search