DEV Community

TildAlice
TildAlice

Posted on • Originally published at tildalice.io

asyncio vs threading vs multiprocessing: Real Latency

Why This Matters More Than You Think

Most Python devs pick asyncio because it's trendy, or reach for threading because it's familiar, or avoid multiprocessing because "it's complicated." Then they hit production and wonder why their API is crawling at 2 req/s.

I ran the same 10,000-request workload across all three concurrency models to see what actually happens. The winner depends entirely on what your code is doing — and the performance gap is massive.

Here's the setup: a simple task that either does I/O (fetch a URL), CPU work (compute SHA256 of 1MB data), or both. Python 3.11 on an M1 MacBook with 8 cores. No tricks, no hand-waving — just time.perf_counter() and real numbers.

Yellow albino python being gently handled outdoors during daytime.

Photo by Kamil Zubrzycki on Pexels

The GIL Problem Nobody Explains Well

Python's Global Interpreter Lock (GIL) means only one thread executes Python bytecode at a time. But here's what's counterintuitive: threading can still outperform sequential code, even with the GIL.


Continue reading the full article on TildAlice

Top comments (0)