Repository navigation
Make every transaction's tenant binding and pool checkout cheaper on the server (CHOO-3667) - #1224
Closed
abeldantas wants to merge 1 commit into
Closed
abeldantas wants to merge 1 commit into
abeldantas wants to merge 1 commit into
Conversation
…the server (CHOO-3667) A CPU profile under message load put the tenant binding that starts each transaction at about 2% of a pod's CPU and the pool's hold timer at about 0.5%. The binding built and compiled a text() statement every time; it now goes to the driver as it is, the same statement in the same transaction. The hold timer formatted a stack of strings on every checkout; it now keeps each function's label, stops walking once it has the frames it shows, and writes the stack out only for a long hold.
abeldantas
requested review from
agent-runner353,
amaudruz,
christian-mcdermott,
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq,
petr-sandbox,
raullopez-sandbox and
simonflk-sb
as code owners
October 31, 2026 13:40
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Approval is deferred because the security-critical tenant hook now emits asyncpg-specific $1 SQL on every transaction, requiring a real Postgres/asyncpg integration run plus statement-count and hold-timer validation.
No open issues 🎉
What changed in this PR
This pull request reduces server overhead from per-transaction tenant binding and connection-pool hold tracking while preserving tenant isolation and long-hold diagnostics.
Changes:
- Uses a reusable driver-level statement for tenant binding.
- Caches pool borrower labels and limits stack traversal.
- Defers stack formatting until long-hold warnings are emitted.
- Updates the related test fixture and changelog.
| File | Description |
|---|---|
core/tests/switch_core/observability/test_pool_holds.py |
Updates _Hold construction for deferred stack data. |
core/switch_core/observability/pool.py |
Optimizes caller detection, frame walking, label caching, and deferred stack formatting. |
core/switch_core/db/tenant_session.py |
Uses a constant driver-level SQL statement for transaction tenant binding. |
CHANGELOG.md |
Documents the transaction and pool-checkout performance improvements. |
Review effort: Lite
Collaborator
Author
|
Combined into #1307 with the other scaling PRs. |
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.
The same profile put the tenant binding at the start of every transaction at about 2% of a pod's CPU, and the pool's hold timer at about 0.5%.
In this PR we:
text()statement for every transaction; the same statement in the same transaction