On this page

How the numbers were measured

Is the program waiting or computing?

Asyncio vs threading for IO-bound work

The main risk of asyncio: one blocking call

Threading vs multiprocessing for CPU-bound work: four options

How many workers: Little's law and physical cores

Asyncio vs threading vs multiprocessing: the decision table

Frequently asked questions

Related reading

Asyncio vs Threading vs Multiprocessing in Python, With Measurements

Image
Arslan Ahmad
Asyncio vs threading vs multiprocessing in Python, measured: wall time, CPU time and memory for each model, plus subinterpreters and free threads.
Image

How the numbers were measured

Is the program waiting or computing?

Asyncio vs threading for IO-bound work

The main risk of asyncio: one blocking call

Threading vs multiprocessing for CPU-bound work: four options

How many workers: Little's law and physical cores

Asyncio vs threading vs multiprocessing: the decision table

Frequently asked questions

Related reading

The choice between asyncio vs threading vs multiprocessing in Python starts with one question: is the program waiting or computing? For waiting work, asyncio and threads finish in the same wall time at the same concurrency limit. They differ mainly in memory and in how easily work can be canceled. For computing work, threads on the standard build of Python barely help. The real choice is among four options: processes, subinterpreters, the free-threaded build, and C code that releases the GIL.

The GIL (global interpreter lock) is a lock inside the standard build of CPython that lets only one thread run Python bytecode at a time. It explains most of the usual advice, but measurements explain the trade-offs better than rules do. Many comparisons of these models use time.sleep() as their only workload, which hides the memory, startup and hardware costs that decide the choice in a real service.

This article classifies work by its CPU share and runs the same workloads through each model on two stated machines. It ends with a decision table and a sizing rule.

How the numbers were measured

Every number below comes from the course Grokking Concurrency in Python. Its example program, Harvest, is a small web crawler that fetches pages from a test site and indexes their words. The test site runs on the same machine and answers each request after 250 milliseconds, which is the delay of a slow remote server.

All runs used Python 3.15.2, on one of two machines:

  • Ryzen desktop: Windows on an AMD Ryzen 7 5800X with 8 cores and 16 logical CPUs, running both the standard and the free-threaded build. It was used for every result that needs real parallel execution.
  • Linux runner: a GitHub Actions virtual machine with 2 virtual CPUs, which are the two hardware threads of one physical core. It was used for results about waiting, where the core count matters little.

A logical CPU is one stream of instructions that the hardware can run, and one physical core often provides two of them. Each section below names the machine behind its numbers.

Is the program waiting or computing?

Work is IO bound when it spends most of its time waiting for input or output, such as a network reply, a disk read or a database query. Work is CPU bound when it spends most of its time executing instructions. Two clocks tell the two kinds apart. Wall time is the time that passes on a clock, including every wait, while CPU time is the time that a processor spends running the program's instructions.

The CPU share of a piece of work is its CPU time divided by its wall time. A share near 0 means the work was waiting, and a share near 100 percent means one CPU was busy the whole time. This script uses only the standard library, so you can run it as it is:

import time def measure(work): wall, cpu = time.perf_counter(), time.process_time() work() wall, cpu = time.perf_counter() - wall, time.process_time() - cpu return wall, cpu, cpu / wall def waiting(): time.sleep(0.25) # stands for a network reply def computing(): sum(i * i for i in range(5_000_000)) # plain Python code for name, work in [("waiting", waiting), ("computing", computing)]: wall, cpu, share = measure(work) print(f"{name:<10} wall {wall:5.2f} s CPU {cpu:5.2f} s CPU share {share:4.0%}")

The course measured Harvest's real steps the same way, on the Linux runner with Python 3.15.2:

StepWall timeCPU timeCPU shareKind
Fetch 1 page0.26 s0.01 s3%IO bound
Index 1 page0.25 s0.25 s100%CPU bound
Crawl 8 pages (fetch, then index)4.03 s2.02 s50%Mixed

The mixed line matters most, because most real programs look like it. In a second run, the same crawl took 4.04 seconds one at a time and 2.34 seconds with 8 threads, not half a second. The threads overlapped the eight waits. The 2 seconds of indexing still ran one thread at a time under the GIL, so the CPU share rose from 50 to 90 percent.

Classify each step of a program, not the whole program, because each step may need a different model.

Asyncio vs threading for IO-bound work

Threads overlap waiting well, even with the GIL, because a thread releases the GIL while it waits on a socket. On the Ryzen desktop with Python 3.15.2, fetching 8 pages one at a time took 2.06 seconds, and 8 threads fetched them in 0.28 seconds.

The asyncio module runs many tasks on one thread with an event loop. An event loop is a loop that runs one task until that task must wait, and then runs another task that is ready. For a fair comparison, the course wrote the same minimal HTTP request twice: once with a plain socket for a thread pool, and once with asyncio.open_connection for tasks limited by a semaphore. Both versions fetched 1,000 pages at two concurrency limits, where the limit is the largest number of fetches in progress at the same moment.

Results on the Linux runner with Python 3.15.2:

Model and limitWall timeCPU timePeak memory
Threads, 50 at a time5.07 s0.25 s64 MB
asyncio, 50 at a time5.08 s0.38 s54 MB
Threads, 1,000 at a time0.68 s0.44 s95 MB
asyncio, 1,000 at a time0.70 s0.31 s59 MB

The limit set the wall time, not the model. At 50 at a time, 1,000 pages need 20 rounds of 250 milliseconds, which is 5.0 seconds, and both models took about 5.1 seconds. Moving a service from threads to asyncio at the same limit does not make it faster.

Memory grew with the number of threads. From a limit of 50 to a limit of 1,000, the thread version's peak grew by 31 MB and the asyncio version's peak by 5 MB. Spread over the 950 extra workers, that is about 33 KB per thread and about 5 KB per task. A thread carries its own stack and operating system structures, while a task is an ordinary Python object. CPU time did not favor either model at both limits: threads used less at 50 and more at 1,000.

Since the speed was equal, other facts about the program decide:

  • Blocking libraries favor threads. Many database drivers and HTTP clients have no asyncio version, and threads run them unchanged.
  • Thousands of connections favor asyncio, because each extra task cost about 5 KB against about 33 KB for a thread in this run.
  • Cancellation favors asyncio. A task can be canceled at its next await. Python cannot stop a running thread from outside, so every blocking call in a thread needs its own timeout.
  • A modest limit favors threads. At 50 at a time, threads used less CPU, and the code needed no async keyword.

The main risk of asyncio: one blocking call

Every asyncio task shares one thread, so a single blocking call inside a coroutine stops all of them. Loop lag is the delay between the moment a task should resume and the moment the event loop actually resumes it. A small heartbeat task that sleeps for 10 milliseconds and records how late it wakes up measures it.

In the course's test on the Linux runner with Python 3.15.2, eight async tasks fetched and saved pages using awaits only, and the heartbeat was at most 0.001 seconds late. When each task fetched with urllib, which blocks, the heartbeat was 2.001 seconds late. No error appeared, and the whole program simply became slower.

This standard library script shows the same effect in less than a second:

import asyncio import time async def heartbeat(lateness): while True: start = time.perf_counter() await asyncio.sleep(0.01) lateness.append(time.perf_counter() - start - 0.01) async def main(blocking): lateness = [] beat = asyncio.create_task(heartbeat(lateness)) await asyncio.sleep(0.05) if blocking: time.sleep(0.5) # a blocking call inside async code else: await asyncio.sleep(0.5) await asyncio.sleep(0.05) beat.cancel() print(f"blocking={blocking!s:<5} worst heartbeat lateness {max(lateness):.3f} s") asyncio.run(main(False)) asyncio.run(main(True))

On the Ryzen desktop with Python 3.15.2, the first run reported about 0.01 seconds of lateness and the second about 0.51 seconds. A heartbeat like this one, kept running in a service, detects a blocked event loop from a metric rather than from user reports.

Want to measure each model on your own code? Grokking Concurrency in Python builds Harvest step by step with threads, processes, asyncio, subinterpreters and the free-threaded build. Every lesson shows the measured output of a program you can run.

Threading vs multiprocessing for CPU-bound work: four options

On the standard build, threads cannot run Python code in parallel, so a pure Python function gains almost nothing from them. Python now offers four ways around that limit:

  • Processes. ProcessPoolExecutor runs each task in a separate process with its own GIL. Arguments and results are pickled, which means converted to bytes, and copied between processes.
  • Subinterpreters. InterpreterPoolExecutor, added in Python 3.14, runs each task in a separate Python interpreter with its own GIL, inside one process.
  • Free threads. The free-threaded build of CPython, often installed as python3.15t, has no GIL, so ordinary threads run Python code in parallel.
  • C code in threads. Libraries such as zlib, hashlib and NumPy release the GIL inside their C code, so plain threads run that code in parallel on either build.

The course indexed 8 pages of 500,000 words each on the Ryzen desktop with Python 3.15.2. The warm time is the median of three runs on a pool that is already running, and the first run includes starting the pool:

Option, 8 workersWarm timeFirst run with startup
One thread, standard build2.40 sNo pool
Threads, standard build2.20 s2.26 s
Processes0.31 s0.49 s
Subinterpreters0.36 s0.41 s
Threads, free-threaded build0.41 s0.44 s
zlib compression, one thread1.47 sNo pool
zlib compression, 8 threads, standard build0.24 s0.18 s

Processes indexed the pages 7.7 times faster than one thread, and subinterpreters 6.7 times faster, while plain threads saved only 0.20 seconds. On the free-threaded build, 8 threads took 0.41 seconds, which is 4.0 times faster than one thread on that build (1.65 seconds). The compression lines show the fourth option: plain threads on the standard build compressed 6.1 times faster, because zlib released the GIL.

The first three options were close in speed, so other costs decide between them:

  • Startup. The process pool needed 0.18 seconds more on its first run, and the interpreter pool 0.05 seconds more. A service that creates a new pool for each request pays that cost every time, so keep one pool running.
  • Memory. In a separate run on the Ryzen desktop, each subinterpreter added about 13.5 MB and each process about 16.4 MB, while a thread added about 0.1 MB.
  • Crash isolation. Only a process pool keeps the program running when one worker crashes.
  • Requirements. Subinterpreters need Python 3.14 or later and extension modules that support them. Free threads need every compiled dependency to support the free-threaded build, because an extension that does not declare support turns the GIL back on.

The function sys._is_gil_enabled() reports whether the GIL is on in the running process, which is the check to run after any dependency upgrade. This script prints it and then runs the same pure Python function on three pools:

import sys import time from concurrent.futures import (InterpreterPoolExecutor, ProcessPoolExecutor, ThreadPoolExecutor) def work(n): return sum(i * i for i in range(n)) # plain Python code, holds the GIL def timed(label, make_pool, jobs): with make_pool(max_workers=8) as pool: list(pool.map(work, jobs)) # first run starts the workers start = time.perf_counter() list(pool.map(work, jobs)) print(f"{label:<14}{time.perf_counter() - start:6.2f} s") if __name__ == "__main__": jobs = [3_000_000] * 8 print(f"Python {sys.version.split()[0]}, GIL enabled: {sys._is_gil_enabled()}") start = time.perf_counter() [work(n) for n in jobs] print(f"{'one at a time':<14}{time.perf_counter() - start:6.2f} s") timed("threads", ThreadPoolExecutor, jobs) timed("processes", ProcessPoolExecutor, jobs) timed("interpreters", InterpreterPoolExecutor, jobs)

Run it with python3.15 and then with python3.15t if you have both builds. On the standard build, the threads line should be close to the one at a time line. On the free-threaded build, it should drop close to the processes line. The if __name__ == "__main__": guard is required, because on Windows and macOS, and on Linux from Python 3.14, a process pool starts each worker in a way that imports the main module again.

How many workers: Little's law and physical cores

Little's law states that the average number of items in a system equals the rate at which they arrive multiplied by the time each one spends in the system. For fetching, pages in flight equal pages per second multiplied by seconds per page. A crawler that must fetch 40 pages per second at 0.25 seconds each therefore needs at least 10 fetches in progress at every moment.

The law held for both models on the Linux runner with Python 3.15.2, fetching 32 pages:

WorkersThroughputTime per pagePages in flight
1 thread3.9 pages/s256 ms1.0
8 threads29.6 pages/s265 ms7.8
16 threads52.2 pages/s288 ms15.1
16 asyncio tasks47.9 pages/s329 ms15.7

For computing work, the number of workers that help is close to the number of physical cores, not the number that os.cpu_count() reports. Simultaneous multithreading, which Intel calls hyperthreading, lets one physical core run two instruction streams by sharing its execution units between them. The operating system counts each stream as a logical CPU. The second stream gains only from the parts of the core that the first one leaves idle.

The Linux runner reports 2 CPUs, but lscpu shows 1 core with 2 threads per core. On that runner, 2 processes indexed pages in 1.44 seconds against 1.68 seconds for one process, a speedup of only 1.17 times, and 4 processes took 1.45 seconds. Before trusting a speedup measured on a cloud machine or a CI runner, count its physical cores with lscpu, or time one worker against two.

Asyncio vs threading vs multiprocessing: the decision table

Decision map for asyncio vs threading vs multiprocessing in Python, with measured numbers

Kind of workStart withMain reasonSize the pool by
IO bound, blocking libraries, modest limitThreadsRuns existing code unchangedLittle's law
IO bound, thousands of connections or cancellationasyncioAbout 5 KB per task, cancel at any awaitLittle's law
CPU bound, pure Python, crash isolation neededProcessesEach worker has its own GIL and memoryPhysical cores
CPU bound, Python 3.14 or later, compatible extensionsSubinterpretersFaster startup than processesPhysical cores
CPU bound, large shared objects, all dependencies readyFree-threaded buildNo copying between workersPhysical cores
CPU bound inside zlib, hashlib or NumPyThreads on either buildThe C code releases the GILPhysical cores
MixedSeparate the stepsEach step has its own best modelEach step by its own rule

One program often combines several rows. Harvest can fetch pages with asyncio and index them in a process pool through loop.run_in_executor. It can also compress them on a thread pool in the same run, because only the indexing step runs Python code that needs more than one GIL. Measure each step at the limit the service really uses, on hardware whose cores you have counted.

Frequently asked questions

Is asyncio faster than threading in Python? Not for the same work at the same concurrency limit. In the measurements above, 1,000 fetches took 0.68 seconds with threads and 0.70 seconds with asyncio. The asyncio version used less memory at high limits, about 5 KB per task against about 33 KB per thread.

When should I use multiprocessing instead of threading in Python? Use processes when the slow part is pure Python code on the standard build, because threads take turns on the GIL there. In the course's test, 8 processes indexed pages in 0.31 seconds, while 8 threads took 2.20 seconds. If the slow part runs inside a C library that releases the GIL, such as zlib, threads are enough.

What is the difference between ThreadPoolExecutor and ProcessPoolExecutor? Both have the same interface, with submit() and map(), so switching between them is often a one-line change. A ThreadPoolExecutor runs tasks on threads that share memory, while a ProcessPoolExecutor runs them in separate processes and copies arguments and results. Processes run Python code in parallel on the standard build, but they cost startup time and memory.

Does the free-threaded build make multiprocessing unnecessary? Not always. Free threads ran the indexer 4.0 times faster than one thread on 8 cores, without copying data between workers. Processes still give crash isolation, run on any Python version, and do not need every compiled dependency to support the free-threaded build.

Can I use asyncio and multiprocessing together? Yes. An asyncio program can send CPU-bound calls to a process pool with loop.run_in_executor, and blocking calls to a thread with asyncio.to_thread. The event loop keeps serving other tasks while the pool computes.

How many threads should a Python thread pool have? For waiting work, use Little's law: the target rate multiplied by the time per request gives the minimum number of requests in progress. For computing work, start near the number of physical cores and measure, because logical CPUs from hyperthreading add much less.

Want to choose a concurrency model from measurements instead of rules? Grokking Concurrency in Python teaches threads, processes, asyncio, subinterpreters and free threads on one crawler, with a measured run behind every claim.

Python
Coding Interview
System Design Fundamentals

What our users say

Eric

I've completed my first pass of "grokking the System Design Interview" and I can say this was an excellent use of money and time. I've grown as a developer and now know the secrets of how to build these really giant internet systems.

KAUSHIK JONNADULA

Thanks for a great resource! You guys are a lifesaver. I struggled a lot in design interviews, and Grokking System Design gave me an organized process to handle a design problem. Please keep adding more questions.

Arijeet

Just completed the “Grokking the system design interview”. It's amazing and super informative. Have come across very few courses that are as good as this!

More From Designgurus
Annual Subscription
Get instant access to all current and upcoming courses for one year.

Access to 50+ courses

New content added monthly

Certificate of completion

$31.08

/month

Billed Annually

Recommended Course
Grokking Dynamic Programming Patterns for Coding Interviews

Grokking Dynamic Programming Patterns for Coding Interviews

13,417+ students

4.4

Grokking Dynamic Programming Patterns for Coding Interviews in Python, Java, JavaScript, and C++. A complete guide to grokking dynamic programming.

View Course
Join our Newsletter

Get the latest system design articles and interview tips delivered to your inbox.

Read More

Top 20 Google Coding Interview Questions (With Solutions)

Arslan Ahmad

Arslan Ahmad

The Roadmap To Clearing Technical Interview in 2025

Arslan Ahmad

Arslan Ahmad

OpenAI Full Stack Engineer Interview: Rounds, Questions, and How to Prepare

Arslan Ahmad

Arslan Ahmad

Free System Design Interview Guide on GitHub: Patterns, Questions, and Deep Dives

Arslan Ahmad

Arslan Ahmad

Design Gurus logo
One-Stop Portal For Tech Interviews.
About Us
Our Team
Careers
Partners
Contact Us
Become Affiliate
Copyright © 2026 Design Gurus, LLC. All rights reserved.