Oversubscription¶
Category: Foundations · Status: stub
One line: More busy threads than there are cores, so the machine spends its time switching between them instead of running them.
How it connects¶
flowchart LR
n_contention["Contention"]
n_oversubscription["Oversubscription"]
n_oversubscription -->|can cause| n_contention
classDef center stroke-width:3px
class n_oversubscription center
classDef outside stroke-dasharray: 4 3
class n_contention outside
- Can lead to: Contention
- See also: Context switch, Granularity, Thread pool and executor
In each language¶
| Rust | available_parallelism ↗ estimates how many threads a program should use |
| Go | runtime.GOMAXPROCS ↗ caps how many CPUs execute Go code simultaneously, however many goroutines there are |
| C++ | std::thread::hardware_concurrency ↗ is only a hint, and may be 0 |
| Python | os.process_cpu_count ↗ (3.13) counts the logical CPUs the calling thread may use, and ThreadPoolExecutor ↗ sizes its default pool from it |
| JavaScript | navigator.hardwareConcurrency ↗ is the number of logical processors available to run threads |
| Kotlin | Dispatchers.Default ↗ uses at most as many threads as there are CPU cores, and at least two |
| The operating system | sched_getaffinity ↗ gives the CPUs a thread may run on, which can be fewer than the machine has |
Where to read more¶
- In the books: Pro TBB, Michael Voss, Rafael Asenjo, James Reinders — ch. 11, 'Controlling the Number of Threads Used for Execution'
- In the books: C++ Concurrency in Action, Anthony Williams — ch. 2, 'Managing threads' → 'Choosing the number of threads at runtime'
- In the books: Functional and Concurrent Programming, Michel Charpentier — ch. 24, 'Case Study: Parallel Execution' → 'Bounded Number of Threads'
- Notes: oversubscription ↗