Repository navigation
perf(async): optimize client and server transports - #339
Merged
MisterVVP merged 16 commits intoNov 25, 2026
Merged
Conversation
Bound HTTP callback batches and add optional queue-wait diagnostics. Avoid copying JSON-RPC streaming responses, update Windows gRPC dependencies, and ignore generated validation artifacts. AI-assisted contribution: implementation, tests, and documentation generated with Codex.
Use 1.41.0 because the vcpkg version database has no entry for 1.38.0. This preserves the Windows callback support requirement.
## 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 #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 - [x] Contains substantive content generated by an AI agent ## Checklist - [x] `./scripts/verify_changes.sh` passed locally - [x] Docs updated
## 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.
) ## Summary - Route canonical native HTTP/JSON `GetTask` ingress onto the dispatcher pool owned by `AsyncRuntime`. Requests start through the existing queued per-request strand. - Keep JSON-RPC, streams, and other REST routes on the listener application pool. - Drain borrowed ingress callbacks during listener join. Cover route eligibility and shutdown with focused tests. ## Authorship and AI usage - [x] Contains substantive content generated by an AI agent ## Testing The prototype passed 38 focused tests. The seven paired Release repetitions produced 98 result rows with zero errors. The comparison used an in-memory store, the same async unary client, fixed CPU placement, a 250 ms warmup, and three-second timed runs. | Workload | Result | | --- | --- | | HTTP/JSON `GetTask`, concurrency 1 | Paired median p50 improved 17.79 µs, with gains in 7/7 pairs | | HTTP/JSON `GetTask`, concurrency 64 | Throughput +0.41%, p99 +4.47% | | JSON-RPC `GetTask`, concurrency 64 | Throughput −0.25%, p99 −0.81% | | gRPC `GetTask`, concurrency 64 | Throughput +3.52%, p99 −14.31% | | Mixed finite SSE | Throughput +7.78%, p99 −12.28% | | Mixed HTTP/JSON `GetTask` | Throughput −3.32%, p99 −6.00% | | Bounded HTTP/JSON task creation | Throughput −1.89%. Median p99 across runs +17.31%. Median paired p99 change −2.4%, with increases in 3/7 pairs. | The benchmark results are from the existing prototype runs. Full validation is deferred to CI.
## Changes - Route native HTTP request preparation through the dispatcher runtime when the server uses `AsyncRuntime`. REST, JSON-RPC, discovery, and SSE share the same ingress choice. - Add regression tests for JSON-RPC shutdown draining and dispatcher-backed discovery and ListTasks. Add benchmarks for client concurrency, dispatcher overhead, and cancellable waits. - Require no regression in mandatory TCK compliance against the target branch, checking both the score and previously passing requirements. [Contributor policy](AGENTS.md) ## Measured performance ### Native HTTP ingress compared with `5202055` | Workload | Throughput, baseline → candidate | p99, baseline → candidate | | --- | ---: | ---: | | JSON-RPC GetTask, C16 | 7,301 → 8,063 req/s (**+10.4%**) | 4.13 → 3.58 ms (−13.3%) | | JSON-RPC GetTask, C64 | 7,552 → 8,263 req/s (**+9.4%**) | 17.41 → 20.88 ms (+19.9%) | | JSON-RPC GetTask, C256 | 8,654 → 8,528 req/s (−1.5%) | 45.33 → 48.73 ms (+7.5%) | These percentages use `(candidate / baseline − 1) × 100` on the reported medians. For example, `(8,263 / 7,552 − 1) × 100 = 9.4%`. The C64 throughput gain came with higher p99. In a separate sync-versus-async test on the starting branch, a simulated 1 ms HTTP wait at C256 went from 9,899 to 14,111 req/s (+42.5%) and from 120.40 to 30.07 ms p99 (−75.0%). The server thread count went from 265 to 21 (−92.1%). This test measures the effect of suspending the request, independently of the ingress change above. ### Topology and serialization follow-up The corrected one-core topology sweep completed 684 samples with zero errors across C1, C16, C64, and C256. Four shared dispatcher workers at C64 moved real JSON-RPC median throughput from 18,064 to 19,299 req/s, and real gRPC from 46,696 to 41,110 req/s. The median changes calculated within each interleaved pair were **+7.5%** and **−12.6%**, respectively. Real JSON-RPC at C256 lost 4.0% throughput and gained 15.1% p99 by the same paired calculation. The local CPU quota supported one dedicated server core and one client core. The direct JSON-RPC envelope experiment reduced isolated serialization from 14.59 to 7.54 µs (−48.3%, or 1.94× as many serializations per unit time). Real async JSON-RPC C1 throughput improved 7.3% by the paired calculation. At C256 the real sync server lost throughput and p99 increased 9.0% with the sync load driver and 13.0% with the async load driver. Those C256 results ruled out the candidate. The C64 native trace measured 390.52 µs p99 waiting to start posted JSON-RPC serialization, 390.41 µs returning the reply to the network loop, and 31.17 µs for the socket write callback. Each interval is measured separately. Their percentiles cannot be added. ## Local validation - The starting branch and candidate matched at 84.6% mandatory TCK compatibility across all four sync/async and in-memory/PostgreSQL profiles. Each profile passed 216 executed tests and every mandatory requirement and transport status matched. - The standard `verify_changes.sh` build, test, and full lint checks passed, along with HTTP and gRPC interoperability and the 54-row performance smoke. The signing-enabled test run reproduced the same signing-corpus failure on `main`. The OSV service returned HTTP 403 for the vendored component scan. ## Authorship The proposed changes were generated by an AI agent.
## Summary - Keep SSE write buffers on the connection and move the acknowledgment through the write queue. A write ID prevents late cancellation from closing a connection after that write has completed. - Count active native unary replies through serialization. Uncontended compact replies, including short task status messages and lists of up to four small tasks, encode on the dispatcher. Contended replies and expensive shapes use the HTTP application executor. - Store the typed stop callback in each dispatcher call and skip deadline clock reads where no deadline exists. This applies to both HTTP and gRPC. - Run the normal and PostgreSQL write CI matrices at 1, 16, 64, and 256 concurrency. The PostgreSQL tail job uses 16, 64, and 256 alongside its focused concurrency-1 profile. ## Tradeoffs and evidence - Each SSE event waits for socket acceptance. I ruled out batching events and removing the per-request strand to preserve per-write backpressure and serialized cancellation and interceptor callbacks. - The existing wire benchmark, profiled over 4,096 requests per workload, recorded 6.3 fewer server malloc calls per two-event SSE request and 4.1 fewer per GetTask. The uninstrumented concurrent GetTask run used about 5% less median server CPU per request. SSE throughput varied across repeats. ## Follow-up benchmark HTTP+JSON `GetTask` medians in requests per second, using two repeats on the same pinned server and client cores. | Concurrency | Sync | Previous async | Updated async | | ---: | ---: | ---: | ---: | | 1 | 9,919 | 7,252 | 7,827 | | 16 | 18,195 | 17,490 | 17,725 | | 64 | 20,361 | 20,475 | 22,109 | | 256 | 16,344 | 18,713 | 20,306 | At concurrency 1, the updated async server measured 2,152 requests/s for `ListTasks` with a 20-task fixture and 3,673 requests/s for finite SSE. Sync measured 2,314 and 4,917 requests/s, respectively. ## Testing - [x] `./scripts/verify_changes.sh` with Asio and PostgreSQL enabled. - [x] Mandatory TCK on gRPC, JSON-RPC, and HTTP+JSON with in-memory and PostgreSQL stores. Each store had 216 passes, 13 skips, and zero failures. All 88 previously passing mandatory requirements retained their passing transport results. - [x] Performance smoke with 54 cases and zero errors. Another 18 targeted concurrency-256 cases passed across the in-memory and PostgreSQL stores. - [x] `mdbook build book`. - The separate optional signing profile failed `AgentCardSigningJsonTest.IndependentRfc8785Corpus` on two existing rejection vectors. ## Authorship - [x] Contains substantive content generated by an AI agent.
Owner
Author
|
@codex review this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82d34deb7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Verification
The identical head commit (
355db351f7e1161fdffad55e2f2baf33d8e5fe8a) passed the CI, TCK Conformance, CodeQL, Docs, Tutorials and Commit messages workflows on #334: CI #1571.Policy note: the diff includes the contributor TCK-gate change from #338 (100% mandatory compliance → no regression), which should be reviewed independently of performance improvements.
Replaces #334 without changing code; target branch remains
release/v0.6.0.Authorship
The proposed changes were generated by an AI agent.