Skip to content

perf(http): reduce async completion and timer overhead - #335

Merged
MisterVVP merged 1 commit into
perf/grpc-client-streamingfrom
perf/http-async-handoffs
Nov 15, 2026
Merged

MisterVVP merged 1 commit into
perf/grpc-client-streamingfrom
perf/http-async-handoffs

Conversation

@MisterVVP

Copy link
Copy Markdown
Owner

Summary

Stacked on #334 (perf/grpc-client-streaming, df97c3c). Keep this draft until CI's sync/async measurements have been reviewed.

HTTP unary responses currently queue an SDK completion after decoding on an SDK completion worker. Allow those internal HTTP JSON/JSON-RPC adapters to finish on the current completion worker, removing that second queue hop. Public initiation still defers callbacks, including nested calls started from callbacks; reactor threads never run application completions.

  • Keep a safe earlier timeout wait after completion, and compare new deadlines with that actual wait instead of the current map head. Completing calls and later admissions no longer wake the timer unnecessarily; earlier deadlines and shutdown still wake it.
  • Reuse the SSE encoder's owned string when adding HTTP chunk framing. Let ready socket writes complete on the network executor immediately, while application write acknowledgments still post back to the application executor. Preserve output limits, socket-acceptance backpressure, cancellation and connection reuse.
  • Cover nested initiation, continuation cleanup after scope destruction/throwing callbacks, and exact chunk framing. Document the threading behavior. Retain independent HTTP-client/SDK cancellation scopes.

Shared-executor experiment

Also tested sharing the HTTP application and native dispatcher executor and resuming pending mailbox continuations without an extra post. A two-worker shared pool reduced the existing four-worker application budget and hurt concurrent unary throughput. Matching the four-worker budget restored throughput to roughly baseline, without a consistent benefit. Leave that executor API, ownership/drain plumbing and SUT wiring out of this patch.

No PostgreSQL, dependency, benchmark-runner or CI workflow changes. No benchmark artifacts are committed.

Local measurements

Exact parent binaries versus this branch, Release/in-memory, 250 ms warmup and three seconds per case, concurrency 1 and 64, one pass per distinct configuration. The local host has a two-CPU quota, with one CPU assigned to each process; CI has two CPUs per process. These are local experiment results, not new CI results or statistical proof. Controls also fluctuate.

All throughput columns below are at c64. Unary async columns use both async client and server; streams use the same observer client and compare server modes. The sync column uses this branch's synchronous mode.

Transport Operation Sync ops/s Parent async ops/s New async ops/s New/parent
HTTP JSON GetTask 12,507 14,440 14,669 1.02×
HTTP JSON ListTasks 7,593 9,626 9,792 1.02×
HTTP JSON Finite stream 12,089 12,020 11,833 0.98×
JSON-RPC GetTask 5,766 7,904 7,589 0.96×
JSON-RPC ListTasks 6,837 8,480 7,982 0.94×
JSON-RPC Finite stream 11,001 11,807 11,950 1.01×

C1 full-async GetTask p50: HTTP JSON 230 → 231 µs, JSON-RPC 331 → 328 µs. ListTasks: 305 → 295 µs and 352 → 428 µs. Finite streams: 279 → 276 µs and 283 → 290 µs. Subscription and idle-cancellation cases are included in the 56-row comparison, with zero errors in both revisions.

Holding the synchronous server constant isolates the client comparison: c1 async-client GetTask p50 is 192 → 179 µs for HTTP JSON and 274 → 268 µs for JSON-RPC. Its measured gap relative to the synchronous client narrows 14 → 7 µs and 10 → 4 µs, respectively. Async-client ListTasks p50 is 253 → 246 µs and 296 → 283 µs. This is consistent with lower client overhead; the larger remaining c1 penalty appears when switching the server to async.

The additional eight-row gRPC GetTask check also has zero errors: c64 full-async throughput 32,944 → 33,341 ops/s (1.01×) and p99 4.066 → 4.705 ms.

A separate syscall trace isolates the reduced machinery: for 500 successful async HTTP JSON GetTask calls per driver, using the same new server, the client's deadline thread made 507 → 1 timed futex-wait calls. Completion-worker condition-variable futex-wait calls fell 1,004 → 504, consistent with removing the extra delivery hop. Traced timings are excluded from the throughput table.

This does not resolve the c1 or HTTP streaming performance gap. The trace confirms less scheduling work, but there is no broad measured throughput win: HTTP concurrent unary improves slightly, JSON-RPC concurrent unary declines in this pass, and streams remain near baseline. Unmodified fully synchronous c64 controls also range from 0.87–1.01× their earlier results, so these single-pass differences cannot establish causation. CI results should determine whether each fast path is worth retaining. Further work needs profiling of the HTTP application/dispatcher and stream handoffs; both synchronous and asynchronous HTTP clients already share the libcurl-multi reactor.

Validation

  • Final ./scripts/verify_changes.sh: passed (exit 0); full build, 1,199 CTest cases with zero failures and three expected skips, and all 190 source/test/example lint checks passed.
  • CI GoogleTest 1.14 / clang-tidy 19 preflight passes for the modified tests.
  • ASan/UBSan with leak detection: 98 focused tests passed, one expected skip, no sanitizer findings.
  • Mandatory TCK (pytest -m must, all three transports, upstream checkout unchanged): 215 passed, 14 skipped, 34 deselected, zero failed MUST checks. The upstream catalogue still lists unimplemented/manual checks; this is not a claim of 100% catalogue coverage. The separate existing MUST/SHOULD Content-Type contradiction in [Feature]: [Release v0.6.0] Finalize SDK packaging, versions, and documentation #328 is unchanged.
  • Required performance smoke: 54 rows, zero errors. Exact CI formatting and mdbook build book pass.
  • No dependency changes. OSV scanning was attempted; its API is blocked with HTTP 403, so vulnerability status remains unverified.

Authorship and AI usage

  • Contains substantive content written by a human
  • Contains substantive content generated by an AI agent

Checklist

  • ./scripts/verify_changes.sh passed locally
  • Docs updated

@MisterVVP MisterVVP added AI agent AI agent contribution performance Performance improvement related tasks based on benchmark results. Performance tests changes. labels Nov 14, 2026 — with ChatGPT Codex Connector
@MisterVVP MisterVVP self-assigned this Nov 14, 2026
@MisterVVP
MisterVVP marked this pull request as ready for review November 15, 2026 16:34
@MisterVVP
MisterVVP merged commit 81473a1 into perf/grpc-client-streaming Nov 15, 2026
22 of 23 checks passed
@MisterVVP
MisterVVP deleted the perf/http-async-handoffs branch November 15, 2026 16:34
MisterVVP added a commit that referenced this pull request Nov 19, 2026
## Summary

- Add callback-driven `SendMessage_CreateTask` alongside the synchronous
API. Both require a task ID, and each async lane keeps one call in
flight.
- Start each client/server comparison on a fresh in-memory SUT. Warm
each measured client with one task, wait for completion, and reuse its
connection for measurement.
- Add a fixed-count CI step to the existing performance artifact and
label wire streams and subscriptions `observer` in JSON, CSV, and
Markdown.

## Local task-creation results

The hosted performance job passed the 24-wire-row check and uploaded the
report. [CI performance
artifact](https://github.com/MisterVVP/a2a-cpp/actions/runs/44519412513/artifacts/14529500461)

The local Release run also produced **24 wire rows**, **2,000 measured
requests per row**, and **zero errors**. All 12 fixed-client server
comparisons were valid. Each cell lists ops/s · p50/p99 in ms from a
single pass on a shared host while local analysis was running.

| Transport | Concurrency | Sync client / sync server | Sync client /
async server | Async client / sync server | Async client / async server
|
| --- | ---: | ---: | ---: | ---: | ---: |
| grpc | 1 | 4,614 · 0.214/0.316 | 3,856 · 0.242/0.669 | 3,978 ·
0.227/1.004 | 3,632 · 0.263/0.565 |
| grpc | 64 | 13,367 · 4.129/9.097 | 11,960 · 4.775/12.000 | 11,568 ·
4.893/11.364 | 14,074 · 4.403/7.754 |
| jsonrpc | 1 | 2,026 · 0.470/1.034 | 1,598 · 0.545/2.924 | 2,188 ·
0.457/0.545 | 1,542 · 0.543/2.765 |
| jsonrpc | 64 | 15,751 · 2.737/26.392 | 9,514 · 5.509/26.867 | 18,420 ·
3.093/9.034 | 10,583 · 5.623/12.290 |
| http_json | 1 | 2,817 · 0.349/0.657 | 2,335 · 0.410/0.906 | 2,579 ·
0.349/1.425 | 1,997 · 0.423/2.617 |
| http_json | 64 | 20,397 · 2.142/19.636 | 13,050 · 3.628/33.597 |
17,848 · 2.683/10.170 | 14,231 · 3.826/13.989 |

## HTTP/JSON server follow-up

In the earlier concurrency-one HTTP/JSON `GetTask` run, holding the
async client fixed, p50 rose from **179 µs** on the sync server to **231
µs** on the async server, a gap of **52 µs (29%)**. [Earlier GetTask
comparison](#335)

Start the server investigation with the network-to-application,
application-to-dispatcher, and response-to-network handoffs in the HTTP
unary path.

## Validation

- `./scripts/verify_changes.sh` and `./scripts/run_clang_tidy.sh build`
both exited successfully. The clean Asio Debug build and CTest completed
with zero failures across 1,135 registered tests. Three tests were
skipped by CTest.
- CI-equivalent clang-format, changed-file Clang 19 analysis,
actionlint, mdBook, and the 54-row performance smoke passed.
- Ubuntu's installed-package security check found no pending security
updates. OSV returned no matches for the Boost.Asio and simdjson
releases used in final verification. Local TCK was skipped at the
maintainer's request, and hosted TCK passed. Full local clang-tidy
finished after the authorized push.

## AI authorship

An AI agent generated the submitted code, tests, workflow, and
documentation from the maintainer-approved plan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution performance Performance improvement related tasks based on benchmark results. Performance tests changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant