Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
Python interview question
Concurrency & parallelismMiddleCommonDesign

How do you tell whether a workload is CPU-bound or I/O-bound, and why does that classification drive the choice of concurrency model?

Answer

A workload is CPU-bound if its runtime is dominated by computation the processor must actually perform — parsing, math, image transforms — and profiling shows high CPU utilization throughout. It is I/O-bound if most of its runtime is spent waiting on something external — a network response, disk access, another service — with the CPU sitting mostly idle during those waits. The classification matters because in the default GIL-enabled CPython build, threads and asyncio coroutines only help I/O-bound work, since the GIL prevents CPU-bound Python code on threads from running in true parallel; CPU-bound work on that build needs `multiprocessing`, or offloading to a C extension or native library that releases the GIL, to actually go faster on multiple cores. Python 3.14's officially supported free-threaded build changes this specifically for CPU-bound threads, letting them scale across cores without multiprocessing, though it remains an opt-in alternative build rather than the default.

Strong answer includes

  • CPU-bound: runtime dominated by actual computation, high CPU use
  • I/O-bound: runtime dominated by waiting on something external, CPU mostly idle
  • on the default GIL build only multiprocessing/native code parallelizes CPU-bound work; free-threaded 3.14 is the exception

Practical example

Parsing and validating a million JSON records in memory is CPU-bound and needs `multiprocessing` to speed up; downloading a million small files over HTTP is I/O-bound and speeds up dramatically with `asyncio` or a thread pool.

#concurrency#design#performance

Sources

asyncio — Asynchronous I/OPython Software Foundation · Event loop, coroutines, tasks and structured concurrency primitivesmultiprocessing — Process-based parallelismPython Software Foundation · Process pools, pickling constraints and inter-process communication