- Updated: April 3, 2026
- 2 min read
Bun Introduces cgroup‑aware AvailableParallelism and HardwareConcurrency on Linux for Boosted Performance
Bun Introduces cgroup‑aware AvailableParallelism and HardwareConcurrency on Linux for Boosted Performance
In a significant step toward better resource management on Linux, the Bun runtime has become cgroup‑aware. The new implementation adds support for AvailableParallelism and HardwareConcurrency that respect container and cgroup limits, delivering more accurate concurrency metrics and improved performance for cloud‑native workloads.

Why cgroup awareness matters
Containers and orchestration platforms such as Docker and Kubernetes rely on Linux cgroups to limit CPU, memory, and I/O resources. Until now, Bun’s os.availableParallelism() and os.hardwareConcurrency() functions reported the host’s total CPU count, ignoring any cgroup restrictions. This mismatch could lead to oversubscribed thread pools, higher latency, and sub‑optimal scaling in multi‑tenant environments.
What’s new in the PR
The GitHub pull request #28801 introduces three key changes:
- cgroup‑aware detection: Bun now reads the
cpu.cfs_quota_usandcpu.cfs_period_usfiles from the/sys/fs/cgrouphierarchy to calculate the effective CPU limit. - Accurate
AvailableParallelism: The function returns the number of CPUs that the current cgroup is allowed to use, falling back to the host count when no limits are set. - Adjusted
HardwareConcurrency: The value now reflects the same cgroup‑aware calculation, ensuring that thread pools and worker threads are sized correctly.
These updates also include extensive test coverage, CI checks across multiple Linux distributions, and documentation revisions to guide developers on the new behavior.
Performance impact
Early benchmarks show that applications running inside constrained containers now allocate the right number of worker threads, reducing context‑switch overhead by up to 30 % in CPU‑bound workloads. For I/O‑heavy services, respecting cgroup limits prevents thread starvation and leads to smoother request handling.
How to adopt the changes
Developers can start using the updated APIs immediately – the changes are backward compatible. If a project relies on the previous “host‑wide” values, the new behavior can be overridden by setting the --no-cgroup-aware flag (currently experimental) until the migration is complete.
Further reading
For a deeper dive into Bun’s performance optimizations, check out our internal articles:
With cgroup awareness now baked into its core, Bun positions itself as a first‑class runtime for cloud‑native JavaScript and TypeScript workloads, delivering both speed and responsible resource usage.
Author: UBOS Tech Team
Andrii Bidochko
CTO UBOS
Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.