Skip to content

perf(server): keep web responsive under provider load - #849

Open
seonghobae wants to merge 17 commits into
mainfrom
feat/async-web-k6
Open

perf(server): keep web responsive under provider load#849
seonghobae wants to merge 17 commits into
mainfrom
feat/async-web-k6

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Outcome

Slow provider calls no longer amplify the stdlib server's five-connection backlog or force a new TCP connection for every fixed-length response.

  • retains the existing daemon request-thread isolation for blocking provider I/O
  • uses the operating system's native SOMAXCONN accept backlog
  • uses HTTP/1.1 persistent connections for fixed-length JSON/text/SSE responses
  • preserves explicit nonblocking max_concurrent_runs admission (503 on saturation)
  • adds a real k6 E2E workload with 64 simultaneous delayed inference users and concurrent /healthz arrival traffic

Exact k6 evidence

Command:

uv run python tests/load/serve_synthetic_delay.py --delay-seconds 1 --max-concurrent-runs 64
BASE_URL=http://127.0.0.1:18089 k6 run tests/load/k6_web_concurrency.js --summary-mode=full

Base 838b3de1 -> tested candidate source 97ce7ed7:

  • authenticated inference checks: 128/128 -> 128/128
  • HTTP failures: 0/229 -> 0/229
  • inference scenario rate: 16.18 -> 25.02 req/s (+54.61%, measured only; not a routing weight)
  • inference connection-blocked average: 571.73 ms -> 1.79 ms
  • inference connection-blocked p95: 3.95 s -> 9.16 ms
  • liveness p99 during one-second provider waits: 18.73 ms -> 9.90 ms
  • candidate liveness checks: 101/101

The liveness threshold is an isolation invariant (p99 < synthetic provider delay), not a fabricated production SLO. Full details and APA 7 references: docs/benchmarks/2026-08-25-web-concurrency-k6.md.

Verification

  • python -m pytest -q tests/test_web_concurrency.py tests/test_healthz.py tests/test_security_hardening.py tests/test_api_contract.py tests/test_review_gateway.py tests/test_workflow_run_object_authorization.py — 52 passed
  • python -m pytest -q tests/test_request_framing.py tests/test_web_concurrency.py tests/test_healthz.py tests/test_security_hardening.py — 33 passed
  • full suite reached 1876 passed with one intentional HTTP/1.0 assertion exposed; that assertion was updated to the new HTTP/1.1 contract and the owning framing suite then passed
  • git diff --check origin/main...HEAD

Scope

No provider credentials or production data are used. TLS, real provider quotas, multi-process serving, and sustained soak capacity remain deployment-specific measurements rather than claims in this PR.


Open in Devin Review

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 20 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9067879e-51e3-4fb5-a129-8bd2ac36c092

📥 Commits

Reviewing files that changed from the base of the PR and between 5a01759 and ede33b5.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • contextual_orchestrator/__main__.py
  • contextual_orchestrator/server.py
  • docs/architecture.md
  • docs/benchmarks/2026-08-25-web-concurrency-k6.md
  • docs/rest_api_design.md
  • loadtests/k6_gateway_smoke.js
  • tests/load/k6_web_concurrency.js
  • tests/load/serve_synthetic_delay.py
  • tests/test_cli_auth.py
  • tests/test_http11_unread_body.py
  • tests/test_request_framing.py
  • tests/test_web_concurrency.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@seonghobae
seonghobae enabled auto-merge (squash) August 25, 2026 12:02
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@opencode-agent
opencode-agent Bot disabled auto-merge August 25, 2026 14:17
@seonghobae
seonghobae enabled auto-merge (squash) August 25, 2026 14:39
@opencode-agent
opencode-agent Bot disabled auto-merge August 25, 2026 14:41
@seonghobae
seonghobae enabled auto-merge (squash) August 25, 2026 14:56
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@opencode-agent
opencode-agent Bot disabled auto-merge August 26, 2026 00:48
@seonghobae
seonghobae enabled auto-merge (squash) August 26, 2026 00:50
@seonghobae

Copy link
Copy Markdown
Contributor Author

Exact-head k6 E2E rerun on 6103806: 64 concurrent delayed inference users completed 128/128 inference checks while 101/101 liveness checks completed; 0/229 HTTP failures, 25.07 inference requests/s, and 6.2 ms liveness p99 against a deliberate 1 s provider delay. This is loopback synthetic-delay gateway evidence, not a production TLS/provider/soak SLO.

@opencode-agent

Copy link
Copy Markdown
Contributor

Scheduled review-feedback autofix for this PR head.

  • Head SHA: d88e3218f093c7d4b77bd78a1d2b54445595ecb5

…zing

k6 end-to-end evidence (loadtests/k6_gateway_smoke.js, mock agent pool so
results measure the gateway layer, not provider latency):

- Baseline (HTTP/1.0, default backlog 5): healthz error rate 7.8% at
  200 req/s from connection-reset storms; client-side ephemeral-port
  exhaustion ('dial: i/o timeout') at burst; chat error rate 3.4% against
  the default 60 req/min per-IP budget.
- After: checks 100%, http_req_failed 0% across 19k requests,
  healthz p95 34.5ms / chat p95 52ms under combined load. Thresholds in
  the k6 script encode this measured baseline as a regression gate.

Changes:
- Handler.protocol_version = 'HTTP/1.1' — responses already set
  Content-Length, so connections are reusable instead of paying a TCP
  handshake + TIME_WAIT socket per request.
- GatewayHTTPServer.request_queue_size = 128 — accept queue no longer
  overflows under probe bursts.
- Framing guard now emits 'Connection: close' on ambiguous-frame
  rejections so keep-alive clients can see the termination they always
  enforced server-side (test updated to assert both status and close).
- --rate-limit-requests / --rate-limit-window-seconds CLI flags so
  operators and load tests can size the per-client budget explicitly.
@opencode-agent
opencode-agent Bot disabled auto-merge August 26, 2026 10:11
@seonghobae
seonghobae enabled auto-merge (squash) August 26, 2026 10:21
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@opencode-agent
opencode-agent Bot disabled auto-merge August 26, 2026 12:45
@seonghobae
seonghobae enabled auto-merge (squash) August 26, 2026 12:53

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Open in Devin Review

Comment thread contextual_orchestrator/server.py
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