Repository navigation
Add HTTP/1.1 persistent connections with connection-scoped buffering and diagnostics - #204
Conversation
|
@codex review this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e77c21fc47
ℹ️ 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".
|
@codex please review this PR. Do exhaustive review. Please report only actionable remaining issues that should block merge. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86ffd9aa8c
ℹ️ 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".
|
@codex review this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f62b66e26c
ℹ️ 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".
1023f27 to
e2bb73e
Compare
… latency (#223) ## Summary Closes #209. This PR reduces startup, first-event, completion, and cancellation overhead in the existing synchronous/public streaming APIs, with a particular focus on HTTP+JSON and JSON-RPC SSE streaming under concurrency. The default HTTP streaming path now uses a bounded, process-wide event-driven libcurl architecture instead of creating one OS worker thread per stream. Network progress is separated from application callback execution while preserving the existing `A2AClient`, `StreamHandle`, transport, observer, and server-streaming APIs. ## What changed ### Shared event-driven HTTP execution Default HTTP+JSON and JSON-RPC streaming now use shared `CURLM` reactors instead of one blocking libcurl worker per stream. - The process-wide reactor pool is bounded to four reactors. - Linux uses `epoll`, `eventfd`, and `timerfd`. - Other platforms use libcurl's portable multi-event path. - Unary and streaming requests participate in the same low-level reactor infrastructure. - Reusable request/stream slots retain reactor affinity for connection-cache locality. ### Bounded callback dispatch Application observer callbacks run away from the network reactor on a bounded shared executor. - Per-stream callback ordering remains serialized. - Callback backlog is bounded by task count and pending bytes. - Slow observers do not block network progress. - Cancellation, shutdown, and transport finalization do not depend on unrelated callback workers becoming available. ### Streaming latency and allocation reductions The streaming path also reduces avoidable work by: - delivering finite HTTP streams incrementally; - reducing SSE framing/parsing temporary allocations and copies; - avoiding unnecessary JSON/protobuf round trips in JSON-RPC streaming where possible; - preserving response validation and protocol error mapping; - reusing HTTP connections for finite streams where safe. ### Cancellation and lifecycle correctness The implementation now covers and tests: - prompt cancellation of idle transfers; - cancellation racing remote completion; - cancellation from inside callbacks; - cross-stream cancellation without cyclic waits; - shutdown racing stream startup; - bounded reactor creation during teardown; - safe reactor destruction off the reactor thread; - callback-executor construction failure; - reactor-thread construction failure; - safe copied/moved low-level HTTP client ownership; - `A2AClient::Destroy()` with active streams; - synchronous cancellation-predicate serialization; - suppression of new callbacks after shutdown. Custom injected synchronous stream requesters retain their compatibility path and continue using `StreamHandle`-owned workers. ### Diagnostics and performance tooling The performance suite now includes wire-level measurements and diagnostics for: - finite-stream first-event latency; - finite-stream completion latency; - task-subscription first-event latency; - shared-client streaming; - local cancellation latency; - finite-stream connection reuse; - client/server subscription phase attribution. Diagnostics are reset at the measurement boundary so warmup/setup traffic is not attributed to measured rows. ### Implementation cleanup The low-level HTTP implementation was split by responsibility: - `src/http/http_client.cpp` — public client lifecycle and unary orchestration; - `src/http/http_client_curl.cpp` — libcurl request/response configuration and parsing; - `src/http/http_client_streaming.cpp` — streaming state, callback dispatch, cancellation, and completion; - `src/http/curl_stream_reactor.cpp` — event-driven reactor implementation; - `src/http/http_client_internal.h` — private cross-translation-unit implementation types. This reduces `http_client.cpp` from roughly 52 KB to roughly 9 KB without changing public behavior. ## Performance ### Comparison methodology For acceptance validation, this table compares complete normal-CI artifacts produced with the same performance configuration. Baseline: - PR #204 head: `e2bb73e18a6910bb1c94213872f7a0f74b160ffd` - CI run: `31522741927` - artifact: `perf-artifacts-normal` / `9114133095` PR #223 final head: - head: `1fa92d8ffb7f0965db7696c56df88d52ee0eb567` - CI run: `34695805370` - artifact: `perf-artifacts-normal` / `10298841665` Configuration: ```text A2A_PERF_TRANSPORTS=grpc,jsonrpc,http_json A2A_PERF_STORE_BACKENDS=inmemory,postgres A2A_PERF_REQUESTS=1000 A2A_PERF_POSTGRES_POOL_SIZES=64 A2A_PERF_CONCURRENCY=1,4,16,64 A2A_PERF_WARMUP_SECONDS=0 ``` The table below shows the acceptance-critical in-memory, wire-level, concurrency-64 coordinate. | Scenario | Transport | First-event p95 | Completion p95 | Throughput | |---|---|---:|---:|---:| | Finite stream | gRPC | 8.923 → 7.049 ms (**-21.0%**) | 12.256 → 9.617 ms (**-21.5%**) | 6,464 → 8,495 ops/s (**+31.4%**) | | Finite stream | HTTP+JSON | 21.219 → 15.105 ms (**-28.8%**) | 21.438 → 15.816 ms (**-26.2%**) | 4,687 → 6,731 ops/s (**+43.6%**) | | Finite stream | JSON-RPC | 34.981 → 19.290 ms (**-44.9%**) | 35.099 → 19.964 ms (**-43.1%**) | 2,939 → 5,989 ops/s (**+103.8%**) | | Subscribe | gRPC | 10.295 → 8.083 ms (**-21.5%**) | 21.807 → 19.692 ms (**-9.7%**) | 2,412 → 2,850 ops/s (**+18.2%**) | | Subscribe | HTTP+JSON | 17.025 → 12.864 ms (**-24.4%**) | 43.448 → 30.379 ms (**-30.1%**) | 1,717 → 2,098 ops/s (**+22.2%**) | | Subscribe | JSON-RPC | 44.445 → 26.470 ms (**-40.4%**) | 83.695 → 60.793 ms (**-27.4%**) | 890 → 1,090 ops/s (**+22.4%**) | All target rows completed with zero operation errors. The final normal performance artifact contains 568 result rows / 568,000 measured operations with zero operation errors. The PostgreSQL c64 verification also improved the target HTTP streaming coordinates versus the same PR #204 artifact: - finite-stream first-event p95: HTTP+JSON **-17.1%**, JSON-RPC **-16.7%**; - finite-stream completion p95: HTTP+JSON **-15.0%**, JSON-RPC **-15.9%**; - subscription first-event p95: HTTP+JSON **-54.1%**, JSON-RPC **-57.1%**. > Note: issue #209's context table records a different baseline sample. The acceptance criteria call for equivalent runs, so the comparison above uses the complete PR #204 and PR #223 normal-CI artifacts generated with the same configuration. ## Validation Current head `1fa92d8ffb7f0965db7696c56df88d52ee0eb567` passes: - build / unit tests / changed-file clang-tidy; - formatting checks; - coverage; - benchmarks and benchmark thresholds; - ASan/UBSan; - Linux CI; - macOS build; - Windows/MSVC build; - Python/C++ cross-SDK interoperability; - HTTP SSE interoperability; - normal performance matrix; - PostgreSQL tail performance validation; - mandatory TCK conformance for both in-memory and PostgreSQL stores. The mandatory TCK workflow reports no mandatory requirement failures for either backend. ## Issue #209 acceptance The PR meets the issue's functional and performance goals: - existing synchronous/public APIs remain source-compatible; - streaming event ordering, cancellation, terminal delivery, and error behavior remain covered; - finite-stream c64 p95 improves by more than 15% for both HTTP+JSON and JSON-RPC in equivalent in-memory runs; - subscription first-event c64 p95 improves by more than 15% for both HTTP+JSON and JSON-RPC; - gRPC does not regress and instead improves on the acceptance-critical coordinates; - target performance rows report zero operation errors; - shared/bounded execution has dedicated concurrency, cancellation, destruction, and worker-growth coverage; - streaming interoperability passes; - mandatory TCK remains conformant for executed/non-skipped mandatory requirements. The separate opt-in asynchronous API tracked by #169 remains out of scope. --------- Co-authored-by: Vladimir Pavlov <[email protected]>
Closes #203
Summary
This PR removes the per-request HTTP connection churn that was limiting HTTP+JSON and JSON-RPC wire scalability.
It keeps the existing HTTP/1.1 transport model, but adds persistent connection support so ordinary unary requests can reuse the same TCP connection instead of paying a new accept/close cycle for every operation.
The implementation also adds connection-scoped buffering, deterministic persistence coverage, connection-reuse diagnostics, Windows-safe shutdown behavior, and request-framing hardening discovered during review.
Why HTTP/1.1 keep-alive
Issue #203 allowed HTTP/1.1 persistence, HTTP/2, or another reusable transport strategy.
HTTP/1.1 keep-alive was selected because it directly addresses the measured structural bottleneck without:
The server can now serve multiple sequential unary requests on one connection while preserving existing SSE/streaming behavior.
What changed
Persistent HTTP connections
Connection: closefor reusable unary responses.Connection: close.HttpAdapter::WriteResponse(...)API while adding explicit connection-close control.Connection-scoped request buffering
HttpConnectionStatenow retains bytes that were read beyond the current request boundary.This allows the adapter to correctly handle:
Request-framing hardening
The adapter explicitly rejects
Transfer-Encoding.The current raw HTTP adapter frames request bodies using
Content-Length; accepting transfer-encoded requests could otherwise leave encoded bytes in the connection buffer and desynchronize subsequent request parsing.Rejecting unsupported transfer encoding preserves deterministic framing and prevents ambiguous request-stream interpretation.
Server lifecycle and portability
FIONBIO.WSAEWOULDBLOCK/WSAEINTRin the Windows accept loop.CTRL_BREAK_EVENTfor graceful performance-SUT shutdown so shutdown-time diagnostics are emitted consistently.Performance diagnostics
The performance runner now records:
http_coordinate_accepted_connections;http_coordinate_completed_unary_operations;http_coordinate_operations_per_connection.The denominator counts only connections that actually carried unary work, so readiness probes and streaming-only sockets do not distort unary connection-reuse measurements.
Diagnostics are available in both JSON and CSV reports.
The parser also accepts scientific-notation values emitted by C++ stream formatting.
Focused performance execution
The performance runner supports focused scenario selection, including the case where the selected scenarios contain no wire-capable workload.
This makes targeted transport validation easier without requiring the entire performance matrix.
Connection reuse evidence
Latest in-memory HTTP wire diagnostics:
The important result is structural: ordinary unary operations no longer require one accepted TCP connection per operation.
At c64, 27,048 unary operations were completed using 1,834 unary-carrying connections.
Performance comparison
Representative in-memory wire throughput at c64 compared with the final PR #202 CI artifact:
GetTask_ExistingTaskListTasks_WithPaginationListTasks_NoPaginationSendMessage_CreateTaskThese values come from separate GitHub-hosted CI executions, so the exact percentages should be treated as directional rather than precise same-machine benchmark deltas.
As an additional control, normalizing HTTP throughput against gRPC within each corresponding run still improves the relative c64 throughput for all four representative scenarios, supporting that the improvement is transport-specific rather than simply a faster runner.
Tail latency is noisier across unrelated hosted-runner executions, so this PR does not claim precise p95/p99 improvements from those cross-run values.
The latest performance matrix completed 512 result rows with zero operation errors.