Skip to content

Avoid waiting for cleanup of drained async statements - #507

Open
vuanhphung wants to merge 3 commits into
mainfrom
perf/async-close
Open

vuanhphung wants to merge 3 commits into
mainfrom
perf/async-close

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Async result consumers await a CloseStatement round trip after draining the result. On a warm live warehouse, SELECT 1 spends 113 ms of its 306 ms median in close. A 50 ms/route HTTPS mock confirms one request delay leaves the critical path; both variants still send one POST, status GET and DELETE per operation.

Once any result stream of an execution reaches successful EOF, detach the subsequent explicit close, even if another stream is unread or partly read. Ownership invalidates synchronously; cleanup errors are not returned or retried by Drop. Without a successful drain, close still awaits the RPC. Keep the statement alive until explicit close for independent readers and repeated fetches. Binding APIs stay unchanged; this is independent of #459 (response-body draining) and #472 (synchronous inline cleanup).

Testing

Workspace/binding tests, fmt/clippy, targeted live lifecycle/cancel/C ABI checks, logical value/type/null comparisons and mutation tests pass. Measurements below precede review hardening: five rotated fresh processes per variant, warmups discarded (25 native samples, 50 per binding).

Live end-to-end ms, median / p95 / p99 main branch
Native SELECT 1 305.59 / 352.94 / 469.55 186.95 / 219.51 / 222.00
Python execute_async 373.51 / 437.56 / 461.40 256.10 / 303.38 / 376.77
Node async API 301.73 / 357.13 / 439.99 194.79 / 222.69 / 234.38
Native ~1 s query 1048.39 / 1130.00 / 1159.79 952.96 / 1325.21 / 13854.24
Native ~5 s query 5055.15 / 8708.26 / 8772.76 5786.71 / 9146.98 / 9174.05

Native close medians fall from 108–114 ms to 0.005–0.007 ms. No long-query end-to-end/tail gain is claimed: the five-second sample regressed overall, with variation concentrated in await_result. Sync control is unchanged (102.60 → 102.47 ms); mock totals are 155.13 → 103.74 ms. Reproduction and all samples are in the factory evidence handoff.

Additional notes

Cleanup is best-effort on runtime shutdown. A drained-close failure after session closure logs at debug, otherwise WARN; the synchronous drained path has the same session-close race on main and is unchanged here. Full external Go/ODBC/Node-driver suites were not run; C ABI/direct napi were checked. CI's integration status auto-passes PRs. The optional macOS symbol step cancels at 45 minutes on pinned main too; its workflow is unchanged.

Independent review confirms the gain back-to-back and through Python, with one extra pooled HTTP/1.1 connection per process; Drop's spawn intentionally now carries the session span.

Adversarial review: converged in round 1; all six scoped lows and both judged bot nits fixed, followed by a clean bot approval.

This pull request and its description were written by Isaac.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 2 Nit

Looks good: 2 low concerns. The drained-close detach logic, the drain signal's error handling and the Drop refactor all look correct, and the tests cover the mock-server and live-warehouse paths.

Other findings

  • ⚪ Nit — napi/index.d.ts is the generated binding file and still carries the old close() doc, because the Rust doc comment changed in this PR without regenerating it. Regenerate index.d.ts, or edit it by hand, and commit it. (Found by Claude Opus 5.5 · confirmed by the judge)
  • ⚪ Nit — The new tests/v0_async_close_logging_wiremock.rs starts directly with use and has no Apache 2.0 license header. Every sibling test file begins with // Copyright (c) 2026 Databricks, Inc. and the license block. Add the standard header. (Found by Claude Opus 5.5 · confirmed by the judge)

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@vuanhphung

Copy link
Copy Markdown
Collaborator Author

Fixed both judge-confirmed nits in 0374109: aligned the generated AsyncStatement.close() documentation and added the standard test license header. No runtime changes.


This comment was generated with GitHub MCP.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

This branch was successfully deployed

1 active deployment
azure-prod — 03741097 Deployed Nov 26, 2026 by vuanhphung via review #1561
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