|
19 | 19 | hosts the open-file-descriptor limit caps real socket concurrency well below |
20 | 20 | that anyway), so the worker pool is capped: |
21 | 21 |
|
22 | | - workers = min(REQUEST_COUNT, CONCURRENCY) # CONCURRENCY default 5000 |
| 22 | + workers = min(REQUEST_COUNT, CONCURRENCY) # CONCURRENCY default 500 |
23 | 23 |
|
24 | 24 | At request counts above the cap, requests queue through the pool — so for the |
25 | | -sync path "concurrency" means the worker count, not REQUEST_COUNT. 5000 is the |
26 | | -starting default; lower `CONCURRENCY` (e.g. 500) if thread/FD pressure makes it |
27 | | -counterproductive on your host. |
| 25 | +sync path "concurrency" means the worker count, not REQUEST_COUNT. |
| 26 | +
|
| 27 | +The default cap is 500. The blocking client is GIL-bound, so adding threads |
| 28 | +past a few hundred does not raise throughput and actively hurts: in testing |
| 29 | +against the dev cluster (20 000 HTTP/1.1 requests), a 500-worker pool beat a |
| 30 | +5000-worker pool on throughput (260 vs 199 req/s) with ~10x lower p50 latency |
| 31 | +(1.6s vs 16.9s), because 5000 threads add GIL contention and context-switching |
| 32 | +with no upside. Raise `CONCURRENCY` only if you have evidence it helps on your |
| 33 | +host; lower it if thread/FD pressure dominates. |
28 | 34 | """ |
29 | 35 |
|
30 | 36 | from __future__ import annotations |
|
46 | 52 | USE_HTTP2 = os.environ.get("USE_HTTP2", "1") == "1" |
47 | 53 | # Async (asyncio) by default; set USE_SYNC=1 to benchmark the blocking client. |
48 | 54 | USE_SYNC = os.environ.get("USE_SYNC", "0") == "1" |
49 | | -# Worker-thread cap for the sync path (see module docstring). |
50 | | -SYNC_WORKER_CAP = int(os.environ.get("CONCURRENCY", "5000")) |
| 55 | +# Worker-thread cap for the sync path (see module docstring). Default 500: |
| 56 | +# the blocking client is GIL-bound, so more threads add contention without |
| 57 | +# raising throughput (500 beat 5000 in testing — see docstring). |
| 58 | +SYNC_WORKER_CAP = int(os.environ.get("CONCURRENCY", "500")) |
51 | 59 | PROGRESS_INTERVAL = 2.0 |
52 | 60 |
|
53 | 61 |
|
|
0 commit comments