One Slow Call, Three Runtimes: How PHP-FPM, Python ASGI and Node Fall Over When a Dependency Takes 200 ms
I put the same 200 ms wait behind PHP-FPM, FastAPI on uvicorn and a plain Node server, then hit each one with 50 concurrent requests. Handled correctly, the async runtimes served 205-211 req/s against FPM's 19.6. One blocking call in the wrong place took both of them down to 4.98, slower than...
Every production incident I've read about that starts with "the site got slow, then it went down" has the same first chapter. Some dependency, a database, a payment API or a DNS lookup, got slower. Nothing failed outright. It just took 200 ms instead of 20, and the application server turned that extra latency into a queue, the queue into timeouts, and the timeouts into retries.
How badly that goes depends almost entirely on the concurrency model of your runtime, and PHP, Python and Node each have a different one. So I put the same artificial 200 ms wait behind each of them and measured what happens under load, including what happens when someone writes the blocking version by accident. That last case is the one that pages you at night.
How PHP-FPM, Python ASGI and Node Handle a Slow Dependency
The three models in one sentence each:
- PHP-FPM: a pool of processes, one request per process at a time. A waiting request ties up a whole process.
- Python ASGI (FastAPI on uvicorn): one event loop per worker process.
async defhandlers share it, and plaindefhandlers get sent to a thread pool. - Node: one event loop per process. Everything shares it.
The test endpoints, in full. PHP:
<?php
usleep(200_000); // stand-in for a 200 ms database or API call
echo "slow\n";
FastAPI, with the correct version and the two common ways of writing it wrong:
import asyncio, time
from fastapi import FastAPI
app = FastAPI()
@app.get("/fast")
async def fast():
return {"ok": "fast"}
@app.get("/slow-await")
async def slow_await():
await asyncio.sleep(0.2) # yields to the event loop while waiting
return {"ok": "slow"}
@app.get("/slow-blocking")
async def slow_blocking():
time.sleep(0.2) # blocks the event loop: a sync driver inside async def
return {"ok": "slow"}
@app.get("/slow-sync-def")
def slow_sync_def():
time.sleep(0.2) # plain def: FastAPI runs it in a worker thread
return {"ok": "slow"}
Node, with the correct version and a blocking one. Atomics.wait is a stand-in for any synchronous call: fs.readFileSync on a slow disk, a sync crypto call, a CPU-heavy JSON parse, or a native module that blocks.
import { createServer } from "node:http";
import { setTimeout as sleep } from "node:timers/promises";
const blockFor = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
createServer(async (req, res) => {
if (req.url === "/slow-await") {
await sleep(200); // yields to the event loop while waiting
} else if (req.url === "/slow-blocking") {
blockFor(200); // blocks the event loop: a sync call in the handler
}
res.end(req.url + "\n");
}).listen(8082);
The setup: PHP 8.6.0 FPM with a static pool of 4 children behind nginx, FastAPI 0.165.0 on uvicorn 0.54.0 with Python 3.14.10 in a single worker, and Node 26.13.1 in a single process, all on one 2-vCPU VM. Each test sent 300 requests at concurrency 50 to the slow endpoint. While that was running, I sent 20 sequential requests to a fast endpoint on the same server, to see what happens to everything else when one endpoint gets slow.
The Results
Two rounds each, both shown:
php-fpm (4 workers) usleep 19.65 req/s p50 2412 ms p99 2613 ms failed 0 | fast endpoint meanwhile: 731.534 ms
uvicorn async + await sleep 205.25 req/s p50 208 ms p99 216 ms failed 0 | fast endpoint meanwhile: 0.821 ms
uvicorn async + time.sleep 4.98 req/s p50 10049 ms p99 11660 ms failed 0 | fast endpoint meanwhile: 2965.263 ms
uvicorn plain def + time.sleep 159.87 req/s p50 213 ms p99 413 ms failed 0 | fast endpoint meanwhile: 0.651 ms
node await setTimeout 210.79 req/s p50 203 ms p99 209 ms failed 0 | fast endpoint meanwhile: 0.230 ms
node Atomics.wait (blocking) 4.98 req/s p50 10037 ms p99 10046 ms failed 0 | fast endpoint meanwhile: 2961.558 ms
php-fpm (4 workers) usleep 19.65 req/s p50 2413 ms p99 2614 ms failed 0 | fast endpoint meanwhile: 703.435 ms
uvicorn async + await sleep 205.44 req/s p50 208 ms p99 215 ms failed 0 | fast endpoint meanwhile: 0.373 ms
uvicorn async + time.sleep 4.98 req/s p50 10046 ms p99 10048 ms failed 0 | fast endpoint meanwhile: 2964.456 ms
uvicorn plain def + time.sleep 163.39 req/s p50 213 ms p99 414 ms failed 0 | fast endpoint meanwhile: 0.583 ms
node await setTimeout 210.73 req/s p50 204 ms p99 206 ms failed 0 | fast endpoint meanwhile: 0.122 ms
node Atomics.wait (blocking) 4.98 req/s p50 10032 ms p99 10033 ms failed 0 | fast endpoint meanwhile: 2959.536 ms
| Setup | req/s | p50 | p99 | A fast request, meanwhile |
|---|---|---|---|---|
| PHP-FPM, 4 workers | 19.65 | 2,412 ms | 2,613 ms | 704–732 ms |
uvicorn, async def + await asyncio.sleep |
205.3 | 208 ms | 216 ms | 0.4–0.8 ms |
uvicorn, async def + time.sleep |
4.98 | 10,049 ms | 11,660 ms | 2,965 ms |
uvicorn, plain def + time.sleep |
159.9–163.4 | 213 ms | 413 ms | 0.6 ms |
Node, await setTimeout |
210.8 | 203 ms | 209 ms | 0.1–0.2 ms |
| Node, blocking call in handler | 4.98 | 10,037 ms | 10,046 ms | 2,962 ms |
Every number in that table follows from simple arithmetic, which is the useful part. If you know the model, you can predict the outage.
We recommend reading The JavaScript Event Loop: Call Stack, Task Queue & Microtasks to continue reading our selection of content. The Node and Python numbers come down to how an event loop schedules work, and this walks through Node's step by step.
The JavaScript Event Loop: Call Stack, Task Queue & Microtasks A production-focused deep dive into the JavaScript event loop: call stack mechanics, microtasks vs. macrotasks, and how async code really runs. SudoSecurity · Santhdium
PHP-FPM: Throughput Equals Workers Divided by Latency
Four workers, each busy for 200 ms per request, gives 4 ÷ 0.2 = 20 requests per second. I measured 19.65. The other 46 concurrent requests wait in the FastCGI listen queue, so the median request took 2.4 seconds even though the work only takes 0.2.
The fast endpoint suffered just as much. A request for a page that does nothing still has to wait for a free worker, so it took 700 ms. That's FPM's failure mode: a slow dependency on one route starves every route, because they all share the pool.
The fix is more workers, and FPM scales that way without complaint. With pm.max_children = 50:
php-fpm (50 workers) usleep 208.31 req/s p50 202 ms p99 222 ms failed 0 | fast endpoint meanwhile: 10.895 ms
php-fpm (50 workers) usleep 207.44 req/s p50 203 ms p99 219 ms failed 0 | fast endpoint meanwhile: 1.714 ms
50 children: total RSS 626 MB, total PSS 31 MB (n=50)
208 req/s, and the fast endpoint dropped back to milliseconds. FPM's model isn't slow. It's capacity-bound. The question is what 50 workers cost, and that's covered in the memory section below.
The Event Loops: Excellent Until One Call Blocks
With the correct await, both uvicorn and Node handled 50 concurrent waits on one process: 205 and 211 req/s, a p99 within 16 ms of the 200 ms floor, and a fast endpoint answering in under a millisecond. While a coroutine waits, the loop runs everything else. That's the whole pitch for async, and it delivers.
Then look at the blocking rows. 4.98 req/s for both, exactly 1 ÷ 0.2 = 5. One blocking call inside a handler freezes the only loop, so the process serves one request at a time, worse than four PHP workers by a factor of four. The p50 hit ten seconds. And the fast endpoint, which does nothing, took 2.96 seconds, because it's on the same frozen loop as everything else.
This failure is easy to ship and hard to spot:
- In Python, it's a sync library inside
async def:requests.get(), a sync database driver,time.sleep, or a bigjson.loads. The code works, the tests pass, and with one user it's fast. - In Node, it's any
*Synccall, a heavy computation, or a native addon that blocks, and in Node there's no thread pool to fall back to for your own handler code.
The event loop amplifies a slow dependency into a full outage, where FPM only degrades.
FastAPI's Plain def: The Safety Net and Its Ceiling
The fourth Python row shows something FastAPI does that a lot of people don't know about. A plain def handler isn't run on the event loop. FastAPI hands it to a thread pool through AnyIO. So time.sleep in a plain def gave 160 req/s, and the fast endpoint stayed fast.
The p99 of 413 ms is the clue to the limit. AnyIO's default thread pool has 40 slots:
anyio default thread limiter tokens: 40
40 threads ÷ 0.2 s = 200 req/s at most, so with 50 concurrent requests, 10 of them always had to wait for a free thread. That's where the 413 ms p99 comes from, and it's FPM's pool problem again, just with threads instead of processes.
The rule that falls out of this: in FastAPI, use async def only when everything inside it is awaited. If you call sync libraries, write plain def and let the thread pool absorb the blocking. Mixing the two is what gives you the 4.98 row.
What a Worker Costs in Memory
Memory after the load runs, as RSS (resident set) and PSS (proportional set size, which divides shared pages among the processes that use them). PSS is the number that adds up correctly:
RSS 25.2 PSS 15.4 php-fpm: master process (/usr/local/etc/
RSS 13.3 PSS 3.3 php-fpm: pool www
RSS 12.4 PSS 2.8 php-fpm: pool www
RSS 12.6 PSS 2.8 php-fpm: pool www
RSS 12.5 PSS 2.8 php-fpm: pool www
RSS 56.7 PSS 54.8 /tmp/blk/bin/python -m uvicorn app:app -
RSS 73.2 PSS 73.1 node server.mjs
And the same FPM pool after 2,000 requests to the Laravel 13 app from my OPcache tests:
RSS 25.2 PSS 11.9 php-fpm: master process (/usr/local/etc/
RSS 35.9 PSS 12.0 php-fpm: pool www
RSS 32.3 PSS 8.5 php-fpm: pool www
RSS 32.3 PSS 8.5 php-fpm: pool www
RSS 32.3 PSS 8.5 php-fpm: pool www
./load.sh "php-fpm (4 workers) usleep" h
| Process | RSS | PSS |
|---|---|---|
| PHP-FPM child, hello-world script | 12.4–13.3 MB | 2.8–3.3 MB |
| PHP-FPM child, Laravel 13 | 32.3–35.9 MB | 8.5–12.0 MB |
| uvicorn + FastAPI, one worker | 56.7 MB | 54.8 MB |
| Node 26, one process | 73.2 MB | 73.1 MB |
RSS makes FPM look expensive: 50 children showed 626 MB of RSS combined, but only 31 MB of PSS, because most of each child's resident memory is the PHP binary, its libraries and the OPcache shared memory, mapped once and shared by all of them. For Laravel, each child's private memory is closer to 8–12 MB. Fifty Laravel workers come to roughly 400–600 MB, which on most servers is less than one misconfigured cache.
The single-process runtimes are the reverse: one uvicorn worker or one Node process holds 55–73 MB, nearly all of it private. That's cheap for the 50-way concurrency they give you, until one blocking call collapses them to one request at a time.
Picking the Defense for Your Runtime
| The risk | The fix | |
|---|---|---|
| PHP-FPM | Pool exhaustion: a slow dependency starves every route | Size pm.max_children to memory using PSS, set timeouts on every outbound call, and consider a separate pool for slow routes |
| Python ASGI | One sync call inside async def freezes the worker |
async def only with async libraries, plain def for sync code, several uvicorn workers, and the 40-thread limit in mind |
| Node | One sync call anywhere freezes the process | No *Sync calls in request paths, CPU work moved to worker_threads, a process per core via cluster or the orchestrator, and event-loop lag monitoring |
One defense applies to all three: put a timeout on every outbound call. A 200 ms slowdown is survivable. A dependency that hangs forever with no timeout turns every one of these models into the 4.98 row eventually: FPM runs out of workers, the thread pool fills up, and the event loop fills with promises that never settle.
We recommend reading Python's async/await: How It Actually Works and Why You Need It to continue reading our selection of content. If the difference between awaiting and blocking still feels slippery, this goes through the event loop model behind Python async.
Python's async/await: How It Actually Works and Why You Need It asyncio is a loop that checks a queue. The event loop mental model behind Python async/await, real code examples, and the mistakes to avoid. SudoSecurity · Santhdium
The Default Timeouts Will Not Save You
"Put a timeout on every outbound call" is easy to say. So what do the HTTP clients do if you don't? I ran a fake dependency that accepts connections and never sends a byte, then pointed the most common client in each language at it, with a 15-second limit on each test:
node fetch default: still waiting when the test killed it (15 s limit)
node fetch timeout: TimeoutError after 2.0 s
python requests-default: still waiting when the test killed it (15 s limit)
python requests-timeout: ReadTimeout after 2.0 s
python httpx-default: ReadTimeout after 5.0 s
php curl-default: still waiting when the test killed it (15 s limit)
php curl-timeout: Operation timed out after 2002 milliseconds with 0 bytes received after 2.0 s
php fgc-default: still waiting when the test killed it (15 s limit)
php fgc-timeout: failed after 2.0 s (default_socket_timeout=2)
| Client | Default behavior against a silent server | With an explicit timeout |
|---|---|---|
Node fetch |
Still waiting at 15 s. Undici's documented headersTimeout default is 300e3 ms, five minutes |
AbortSignal.timeout(2000): TimeoutError at 2.0 s |
Python requests |
Still waiting at 15 s. The docs say "requests do not time out unless a timeout value is set explicitly" | timeout=2: ReadTimeout at 2.0 s |
Python httpx |
ReadTimeout at 5.0 s, its built-in default |
— |
| PHP cURL | Still waiting at 15 s (CURLOPT_TIMEOUT defaults to 0, no limit) |
CURLOPT_TIMEOUT 2: timed out at 2.0 s |
PHP file_get_contents |
Still waiting at 15 s. default_socket_timeout is 60 s |
default_socket_timeout=2: failed at 2.0 s |
Of the five clients, only httpx protects you out of the box. The rest wait one minute, five minutes or forever. Now combine that with the arithmetic from the start of this piece. One dependency that stops answering takes a four-worker FPM pool to zero capacity in four requests, and with a 60-second socket default it stays there for a minute per request. In Node, nothing freezes, but five minutes of pending requests pile up in memory with their sockets open.
The client code for each fix:
const opts = mode === "timeout" ? { signal: AbortSignal.timeout(2000) } : {};
await fetch("http://127.0.0.1:9999/", opts);
elif mode == "requests-timeout": requests.get("http://127.0.0.1:9999/", timeout=2)
if ($mode === "curl-timeout") curl_setopt($ch, CURLOPT_TIMEOUT, 2);
Pick the timeout from the dependency's real latency, its p99 plus some headroom, not a round number, and make sure the total of all your outbound timeouts stays below the timeout of whatever is calling you. A 30-second database timeout behind a 10-second load balancer timeout just means the user has left by the time your error handling runs.
What This Doesn't Cover
- Persistent PHP runtimes. FrankenPHP worker mode, RoadRunner and Swoole change FPM's model completely.
- Multiple Python workers. I ran one uvicorn worker to isolate the event loop. Production uses several, which multiplies everything here, including memory.
- Real databases. Connection pool limits add another queue in front of each model. That's usually where the next bottleneck is.
- CPU-bound work. This test was all waiting. CPU work is a different story, covered in the free-threading piece.
- Bun and Deno. Both have the same event-loop failure mode as Node, with different internals.
The Actual Point
Every runtime here can handle a slow dependency, and every one has a specific way of falling over. PHP-FPM degrades predictably: throughput is workers divided by latency, and its memory cost is lower than RSS suggests. The event loops give you enormous concurrency for little memory, but one blocking call inside them is a cliff, not a slope: 205 req/s down to 4.98 in my test, with the healthy endpoints taken down too. Know your runtime's arithmetic, put timeouts on everything, and make "no blocking calls in async handlers" a code review rule, not a hope.
Sources: the FastAPI, uvicorn and AnyIO packages (versions as printed), the undici Client docs, the Requests advanced-usage docs, php.net's filesystem configuration page, the PHP-FPM and Node.js documentation, and my earlier Laravel OPcache test setup. All load and memory tests were run by me on php:8.6-fpm with nginx:alpine, Python 3.14.10 with FastAPI 0.165.0 and uvicorn 0.54.0, and node:26-slim. All server code is original demonstrative code using each framework's public API, and every output block is reproduced verbatim from those runs.
$ tail -f /forums
Discussion
Comments live on the community forums — sign in there to reply.