Skip to content

fix(benchmarks): run benchmark.py users in processes with asyncio - #257

Draft
kkurzacz-intel wants to merge 4 commits into
release-3.1from
kkurzacz/benchmark-async-client
Draft

kkurzacz-intel wants to merge 4 commits into
release-3.1from
kkurzacz/benchmark-async-client

Conversation

@kkurzacz-intel

@kkurzacz-intel kkurzacz-intel commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

benchmark.py runs every simulated user as a thread in one Python process. At high concurrency the GIL delays requests long enough that Envoy closes TLS handshakes the client hasn't finished (SSL: UNEXPECTED_EOF_WHILE_READING). A failed worker then retries immediately, so 128 workers reach the failure limit (-e) within seconds and the run ends with no successful requests. The delay also lands inside the measured TTFT and TPOT.

This keeps the tool's interface and replaces how it generates load:

  • Users run as asyncio tasks, split over processes. -p sets how many processes the -c users are split across: each process runs its share of users in parallel with the others, so users in different processes never wait for each other's Python work. Users are dealt round-robin (-c 10 -p 3 gives users 0,3,6,9 / 1,4,7 / 2,5,8). The default, -p 0, uses one process per 16 users (at most the CPU count), so -c 128 gets 8 processes. -p doesn't change what a user does: each still sends one request at a time, on a new connection.

  • Every request still opens its own TCP and TLS connection (force_close), so users stay independent, as before.

  • Users start over a 2 s ramp on top of -u (--ramp), so 128 handshakes don't land on Envoy at once.

  • After an error a user backs off (0.5 s doubling to 8 s, with jitter) instead of retrying at once. Errors count toward -e as before, and 429 still waits 5 s without counting.

  • The request loop only records timestamps (perf_counter) and the answer text. Tokens are counted in the main process after each response, so tokenizing can't delay a request.

  • The bearer file (-b) is checked before any load: if it's missing or has fewer than -c tokens, the run stops with exit code 1 and says which line is missing. Before, each worker without a token logged no bearer, quitting and the run went on with fewer users, still exiting 0 and writing bench_…_c-<users>_… as if every user had run (2 tokens with -c 4: 2 users loaded, exit 0; no file: empty CSV, exit 0).

  • Proxy settings (HTTP(S)_PROXY, no_proxy) apply as they did with requests (trust_env=True).

Unchanged: every option, the warmup and failure semantics, the bench_<date>_c-<users>_d-<delay>.result.csv file and its columns, so parse.py, benchmark_sweep.sh, run_benchmark_sweep.sh and the nightly playbook work as they are. New dependency: aiohttp.

Evidence (single-node GNR, 2× Xeon 6760P, same deployment)

Threads (current) Processes + asyncio (this PR)
Runs 152 246
Runs at 128 users 12, 4 failed (0 successful requests) 45, 0 failed
Envoy downstream_pre_cx_timeout (connection opened, TLS never completed) 1,769 over 108,873 connections 0 over the next 151,312 connections

The 4 failed cases all succeed with the new load generator (474 to 2,793 successful requests each). The client process under the current tool was a single process at about 114% CPU with 418 threads.

Not yet shown: unchanged numbers

The runs above differ in more than the client (vector DB size, dates), so they don't show whether the results match at concurrency levels both tools handle. A controlled A/B on the same deployment, alternating the two clients, is planned and will be added here. Expected: equal within noise at low concurrency, lower TTFT at 32+ users where the current client's own delay is counted.

Testing

  • Against a local SSE stub, run as a script from its folder (as the nightly does): 417 requests over 417 distinct connections, 385 rows (warmup excluded), exit 0; parse.py reads the CSV unchanged.
  • Against a GNR deployment with 128 users for 2 minutes, tokens from generate_uat_to_file.sh: 8 processes, exit 0, 1 client error; parse.py summary as usual.

benchmark.py ran every user as a thread in one process, so at high
concurrency the GIL delayed requests long enough that Envoy closed TLS
handshakes the client had not finished, and the immediate retries pushed
runs past the failure limit with no successful requests. Users now run
as asyncio tasks in several processes (16 users each). Every request
still opens its own TCP and TLS connection, users start over a short
ramp, errors back off with jitter, and tokens are counted in the main
process after each response. The options, output file and CSV columns
are unchanged.

Signed-off-by: Kurzacz, Kamil <kamil.kurzacz@intel.com>
…sses

Signed-off-by: Kurzacz, Kamil <kamil.kurzacz@intel.com>
… settings

benchmark.py now stops with exit code 1 before any load when the bearer
file is missing or has fewer than -c tokens. Before, the workers without
a token quit with a log line and the run went on with fewer users, still
exiting 0 under a -c <users> file name. The aiohttp session also reads
HTTP(S)_PROXY and no_proxy, as requests did.

Signed-off-by: Kurzacz, Kamil <kamil.kurzacz@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant