22.4 I/O-Bound vs. CPU-Bound Tasks
Distinguishing I/O-bound from CPU-bound tasks is essential when picking a concurrency model:
- I/O-Bound: Spends most of its time waiting on external operations (like network or disk). Async runtimes are particularly beneficial here, because many waiting tasks can be managed by fewer threads without heavy overhead.
- CPU-Bound: Spends most of its time doing computations. Achieving speedups requires parallel execution across multiple CPU cores. Rust typically handles this through threads or via libraries like Rayon that automate parallelism internally.
Understanding your workload enables you to choose between threads, async, or a hybrid approach to maximize performance.