Skip to content

Use a single global timer wheel for query timeouts#225

Merged
penberg merged 1 commit into
mainfrom
timer
Jun 1, 2026
Merged

Use a single global timer wheel for query timeouts#225
penberg merged 1 commit into
mainfrom
timer

Conversation

@penberg

@penberg penberg commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Each connection previously constructed its own QueryTimeoutManager, and
since pre.36 that manager spawns a dedicated std::thread. The result was
one OS thread per open connection, exhausting the process thread limit
after a few hundred connections (pre.33 used a tokio task and opened
1500+ cleanly).

Make QueryTimeoutManager a process-wide singleton with one background
thread. Each registered timeout now carries a Weak on its
heap entry, so a single wheel interrupts the right connection regardless
of how many are open. Connections no longer hold a manager or shut one
down on close.

Also add an integration test that opens many connections at once as a
reproducer for the exhaustion.

Each connection previously constructed its own QueryTimeoutManager, and
since pre.36 that manager spawns a dedicated std::thread. The result was
one OS thread per open connection, exhausting the process thread limit
after a few hundred connections (pre.33 used a tokio task and opened
1500+ cleanly).

Make QueryTimeoutManager a process-wide singleton with one background
thread. Each registered timeout now carries a Weak<Connection> on its
heap entry, so a single wheel interrupts the right connection regardless
of how many are open. Connections no longer hold a manager or shut one
down on close.

Also add an integration test that opens many connections at once as a
reproducer for the exhaustion.
@penberg penberg merged commit 9181e85 into main Jun 1, 2026
13 checks passed
@penberg penberg deleted the timer branch June 1, 2026 08:35
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