Skip to content

[Perf]: add event-driven Windows readiness backend for libcurl streaming #232

Open

Description

@MisterVVP

Problem

On Linux, the SDK's shared libcurl streaming reactor uses socket/timer callbacks with epoll, eventfd and timerfd. The existing Windows fallback works, but lacks an equivalent explicitly readiness-driven backend. This may increase wakeup and cancellation costs for many idle or concurrent HTTP+JSON/JSON-RPC streams.

Goal

Make the Windows shared HTTP client reactor event-driven and promptly cancellable without creating a thread per stream, changing the public streaming API or rebuilding the libcurl client stack.

Ownership and issue boundaries (v0.6.0)

Owns: Windows readiness/wakeup backend for the existing outbound shared libcurl streaming reactor; this same backend must support #269 HTTP async unary work.

Prerequisites and integration: #269 consumes this reactor, but its API/fake-transport work can proceed independently. #270 is inbound server networking and must remain separate.

Must not absorb: No new per-stream reactor or thread, Linux reactor rewrite, inbound HTTP, gRPC, client API redesign, or Windows handle-count ceiling.

Issue management: Retain this issue and use separate independently reviewable PRs for the checkpoints below. Close only when final acceptance criteria pass. Do not pull future checkpoints into earlier PRs.

Implementation PR checklist

  • PR 1 — Baseline and decision record: measure Windows fallback; select scalable socket readiness, timer and explicit Add/Cancel/Shutdown wakeup mechanism; demonstrate support for >64 streams.
  • PR 2 — Isolated Windows libcurl backend preserving single CURLM owner, multi-socket callbacks, non-reentrant mutation and callback dispatch off the reactor.
  • PR 3 — Deterministic Windows cancellation/timer/shutdown race tests; 1/16/64 streams; baseline first-event/completion/cancel/thread evidence.
  • PR 4 — Document the backend under book/ (not root docs/), Windows CI, interoperability, TCK and mandatory perf smoke.

PR merge rule: Narrow changes, deterministic scope-specific tests, documented lifecycle ownership, and applicable AGENTS.md validation. Measure performance-sensitive behavior against equivalent baseline workloads. Preserve synchronous behavior.

Detailed technical requirements — scope and implementation phases

Phase 1 — Choose the Windows readiness mechanism

  • Review current CURLM ownership, fallback behavior, Windows socket handles, timer semantics and command queues; measure existing cancellation/first-event/resource behavior.
  • Choose a Windows-compatible scalable readiness mechanism, such as WSAPoll with an explicit wake socket or a better justified alternative. Avoid a single WaitForMultipleObjects-style wait set capped at 64 handles.
  • Keep libcurl's multi-socket contract: CURLMOPT_SOCKETFUNCTION, CURLMOPT_TIMERFUNCTION and curl_multi_socket_action().
  • Document why the selected mechanism handles Add/Cancel/Shutdown wakeups, timer deadlines and more than 64 streams correctly.

Checkpoint: Readiness design and baseline are reviewable before swapping the backend.

Phase 2 — Implement Windows backend in isolation

  • Preserve exactly one owner for mutating CURLM membership; do not perform unsafe reentrant curl_multi_* work from libcurl callbacks.
  • Wake promptly when other threads queue Add, Cancel or Shutdown, even when all sockets are idle. Avoid fixed-interval polling and busy spinning.
  • Integrate libcurl timer callback deadlines correctly, including immediate timers; invoke timeout actions on the reactor thread.
  • Preserve shared callback dispatch away from the network reactor and ordered delivery to StreamObserver.
  • Avoid changing Linux epoll paths except for small shared correctness helpers with explicit justification.

Checkpoint: Windows can use the new readiness backend with unchanged client-facing APIs.

Phase 3 — Validate behavior and scalability

  • Add deterministic tests for idle cancel/wakeup, timer expiry, start/shutdown races, repeated/concurrent cancellation, server completion racing cancellation, and cancellation of one stream while peers remain active.
  • Test 1/16/64 established streams on one client without a 64-handle ceiling; thread count must remain effectively constant.
  • Compare first-event, finite-completion and cancellation latency against the existing Windows fallback, with zero errors and no material regression.
  • Preserve the existing intended cancellation targets of p95 under 10 ms and p99 under 20 ms under a documented local workload, or explicitly investigate any inability to meet them.
  • Update docs/streaming-usage.md and run Windows CI plus required SDK validation.

Relationship to other issues

  • #269 may reuse the shared libcurl reactor for async unary client calls. Keep the backend reusable, but do not implement the public async client API here.
  • #270 concerns inbound server sockets; this is strictly outbound client scheduling.
  • #169 concerns server-side gRPC streaming and is unrelated to the Windows libcurl backend.

Out of scope

  • Replacing libcurl, redesigning StreamObserver, changing gRPC, implementing io_uring, rebuilding the Linux readiness backend, or adding inbound HTTP server I/O.
  • One OS thread, CURLM, or blocking network worker per stream.

Acceptance criteria

  • Windows shared libcurl reactor reacts to socket readiness and timer deadlines without a periodic polling interval.
  • Add/Cancel/Shutdown immediately wake the reactor; owner-thread and callback isolation invariants are preserved.
  • At least 64 simultaneous streams work without a wait-handle ceiling or per-stream SDK thread growth.
  • Cancellation/shutdown/race tests pass and unrelated streams are unaffected by one stream's cancellation.
  • HTTP+JSON and JSON-RPC streaming retain correct event ordering, zero-error operation and comparable performance.
  • Windows CI, mandatory repository validation, TCK/HTTP SSE interoperability and performance smoke pass.
  • Backend and wakeup/timer mechanism are documented.

Activity

  1. self-assigned this
    on Aug 30, 2026
  2. added
    enhancement
    performance
    on Aug 30, 2026
  3. added this to the v0.6.0 milestone on Sep 21, 2026
  4. linked a pull request that will close this issueRelease v0.6.0 #322on Nov 6, 2026
  5. moved this from Todo to In Progress in a2a-cpp SDK Roadmapon Nov 6, 2026
  6. moved this from In Progress to In Review in a2a-cpp SDK Roadmapon Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementperformance

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions