Repository navigation
feat(qwp): batch socket writes and wake ack waits on progress - #235
Conversation
The background runner now opens a bounded send burst per step: ready SF frames are handed to the transport back to back, and the blocking transport encodes them into one buffer that reaches the socket in writes of up to 64 KiB when the burst closes. Every QWP message keeps its own WebSocket frame, wire sequence and ACK, so the server sees the same frame stream as before; only the number of write syscalls changes. A failed group write is recovered by the ordinary reconnect replay because the SF log retains every frame until it is acknowledged. Manual progress mode and test transports keep their immediate one-frame writes through the trait defaults. Extracted from the wire-batching part of PR #234 (commit 2bbdfea), without the commit windows and frame splicer introduced there. Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Background publication first tries a plain append to the already allocated active segment. Only when that fails does it start the append deadline and enter the rotation and backpressure loop, so the common path no longer reads the clock or sets up a wait budget per flush. Ported from PR #234 (commit 2bbdfea). Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The sender error log publishes a pending flag; empty error polls read it and return without taking the shared store mutex, which storage maintenance may hold for a while. Both poll cursors must drain before the flag clears, and a poisoned store still goes through the lock so the poison surfaces. Ported from PR #234 (commit 2bbdfea). Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A pool with sender_pool_min equal to sender_pool_max cannot shrink, so its entries no longer carry an idle timestamp and the reaper skips them instead of timing them out and reopening the same connection. Ported from PR #234 (commit 2bbdfea). Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 4a31e33)
(cherry picked from commit 8f4de58)
Buffer::clear keeps the validated schema, so a buffer that always writes the same single table reuses it on the next table() call instead of revalidating and hashing the name after every flush. A symbol column with one distinct value no longer builds its hash index; the index is created when a second value arrives, keeping the dictionary IDs intact across rollback and clear. Ported from PR #234 (commit 2bbdfea). Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 88dc156)
(cherry picked from commit 3b90574)
Each table buffer keeps its column schema already encoded as (name, wire type) pairs, appended when a column is added and rebuilt after a rollback truncates columns. The replay message copies it instead of re-encoding every column name on every flush. Ported from PR #234 (commits 40160af and 73634e9). Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Pooled wait paths slept 10 ms between watermark checks. They now take the runner's progress generation before each check and block on its notifier until the next send, ACK, maintenance step or terminal error, bounded by the same no-progress deadline. Unrelated notifications do not extend the deadline; only watermark advancement resets it. Ported from PR #234 (commits d9d9884 and 4dbaebb). Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A terminal initial-connect failure that finds the shared store poisoned now terminalizes the lifecycle and notifies the progress notifier before the pending runner stops, so an event-driven boundary wait observes the failure instead of sleeping to its deadline. Ported from PR #234 (commit 5abf8c7). Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Releasing the send cursor no longer forgets where it was. The cursor keeps its frame sequence, offset and segment base as a hint, and the next lookup in the same segment scans forward from that hint instead of walking every frame from the segment header. A sender that keeps up with publication releases the cursor at the tail after every frame, so this turns a per-frame rescan into a constant-size step. Ported from PR #234 (commit 3e2a418) without the splicer-specific rewind, which has no counterpart on this branch. Co-authored-by: victor <victorgaoyh@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 6838e5f)
(cherry picked from commit f552a64)
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Pool idle state and reaping questdb-rs/src/db.rs, questdb-rs/src/tests/qwp_sender_pool.rs |
Pool entries use optional idle timestamps. Fixed-size pools do not mark store-and-forward entries as reapable, while returned direct senders receive timestamps. Borrow waiters and the reaper use separate condition variables. Tests cover manual and automatic reaping and fixed-size pool reuse. |
QWP buffer metadata
| Layer / File(s) | Summary |
|---|---|
Cached schema and replay questdb-rs/src/ingress/buffer/qwp.rs |
Table buffers retain encoded schemas for replay and rebuild schema metadata after rollback. Tests cover size hints, schema reuse, rollback, and clone rewinds. |
Table and symbol lookup questdb-rs/src/ingress/buffer/qwp.rs |
Dirty tracking and table selection add fast paths. Symbol indexing starts when a second distinct symbol is added, with tests for promotion and rollback. |
QWP/WebSocket sender
| Layer / File(s) | Summary |
|---|---|
Store-and-forward submission and maintenance questdb-rs/src/ingress/sender/qwp_ws_sfa_queue.rs |
Active-segment submission can report insufficient space without rotating. Disk rotation defers while spare creation is in flight. Tests cover submission, spare creation, and cleanup. |
Segment cursor scanning and release questdb-rs/src/ingress/sender/qwp_ws_sfa_queue.rs, questdb-rs/src/ingress/sender/qwp_ws_sfa_segment.rs, questdb-rs/src/ingress/sender/qwp_ws_driver.rs |
Send cursors can release segment references while retaining scan positions. Segment lookup accepts an optional starting boundary. |
Segment CRC updates questdb-rs/src/ingress/sender/qwp_ws_sfa_segment.rs |
CRC updates use detected hardware instructions for supported short inputs and fall back to the crate implementation otherwise. Tests compare results across input lengths and seeds. |
Background WebSocket frame batching questdb-rs/src/ingress/sender/qwp_ws.rs, questdb-rs/src/ingress/sender/qwp_ws_batch.rs, questdb-rs/src/ingress/sender/qwp_ws_driver.rs, questdb-rs/src/ingress/sender.rs |
The background runner sends bounded bursts through transport batch hooks. The blocking transport groups masked frames and flushes at the byte limit or burst end. Tests cover batching and replay after flush failures. |
Progress waits and sender errors questdb-rs/src/ingress/column_sender/sender.rs, questdb-rs/src/ingress/sender/qwp_ws.rs, questdb-rs/src/ingress/sender/qwp_ws_driver.rs, questdb-rs/src/tests/qwp_ws.rs |
Store-and-forward waits use progress notifications instead of fixed polling sleeps. Sender-error polling checks a shared pending flag. Tests cover wait notifications, error handling, and stalled-connect cleanup. |
Priority:
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant SyncQwpWsRunner
participant QwpWsSendCore
participant BlockingQwpWsTransport
participant QwpWsBatch
participant WebSocketStream
SyncQwpWsRunner->>QwpWsSendCore: Begin batch and get byte budget
SyncQwpWsRunner->>QwpWsSendCore: Send ready frames in the burst
QwpWsSendCore->>BlockingQwpWsTransport: Send frame
BlockingQwpWsTransport->>QwpWsBatch: Append masked frame
SyncQwpWsRunner->>QwpWsSendCore: Finish batch
QwpWsSendCore->>BlockingQwpWsTransport: Finish and flush batch
BlockingQwpWsTransport->>QwpWsBatch: Flush buffered frames
QwpWsBatch->>WebSocketStream: Write and flush encoded frames
Possibly related issues
- questdb/c-questdb-client#229: The PR changes QWP buffer schema and replay state, which is related to the issue’s concern about retained column state and later frame size.
- questdb/c-questdb-client#233: The PR adds rollback coverage for schema state after a failed row, but the summaries do not establish that it addresses terminal schema rejection.
- questdb/c-questdb-client#231: The PR changes reconnect batching and replay behavior, but the summaries do not establish that it addresses reconnect behavior when the maximum duration is zero.
Possibly related PRs
- questdb/c-questdb-client#234: Both PRs change QWP sender batching and runner behavior.
Suggested reviewers: kafka1991, mtopolnik
Merge Risk: 
Minimal · up to dd1ad
-
The reviewed test changes do not introduce an identified merge-blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 56 functions across 10 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
Grouped background sends can put both the Chunk frame (bravo) and the Arrow frame (charlie) on the dead socket in one burst before the runner reads the close, so the dictionary mirror, and with it the catch-up on the replacement endpoint, may already hold charlie. Replayed frames that overlap the catch-up are the tolerated idempotent case, and the data-frame assertions are unchanged. The test accepted only alpha or alpha+bravo, so it failed intermittently in the arrow cargo legs (mac cargo tests and the linux arrow/polars version-range job in build 283902). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewing PR #235 at level 3, head dd1ad55, base b3e60e2. Verdict: approve with comments. There are no Critical findings, and the coverage-gap check passes. One Moderate item (an inert change in The PR moved during the review. It started at CriticalNone. ModerateM1. Fixed-size pool "never reap" change has no effect, and its new test passes without it
Minorm1. Two comments still describe one-write-per-frame behaviour
m2. Dead code
m3. PR metadata
Adjacent findingsNone proved. Coverage map
Summary
|
|
Reviewing PR #235 at level 3, head dd1ad55, base b3e60e2. Verdict: approve with comments. No Critical findings, and the test gate passes. Please address Moderate 1 (fixed-size pool) and Moderate 2 (burst-path tests) in this PR. Moderate 3 and 4 are cheap and also belong here. CriticalNone. Moderate1. Fixed-size in-memory pools now keep over-cap senders forever
Trigger. Configure Why. The over-cap state comes from an older accounting bug in let _release = release_slot.then_some(SenderSlotRelease { decrement_in_use: true, decrement_closing: true, .. });
At base, the reaper repaired this after The commit message's premise ("cannot shrink … instead of timing them out and reopening the same connection") does not hold at base. With correct accounting, Fix (choose one):
In either case, add a regression test using the trigger above that asserts 2. The background burst's failure handling and byte bound have no failing test
Why the existing tests miss these:
Suggested tests, all built on existing helpers:
3. An indefinite durable wait depends on a single notification that no test checks
With the default The code is correct today: the 4. The PR description is a placeholder
Please describe the user-visible changes:
Also state that Minor
Adjacent findings (not blocking; issue draft, not filed)In-memory sender pools can exceed
Coverage mapThe test gate passes. There are 2 admitted coverage gaps (Moderate 2 and 3), both Moderate. The affected tests run in the PR CI Summary
|
Faster pooled QWP/WebSocket ingestion. These are the parts of #234 that don't change sender behaviour; #234's commit window (
commit_rows/commit_interval_ms), which merges frames on the client, is left out. No newconfiguration keys and no protocol changes.
wait()/flush_and_waitno longer cost ~10 ms each. They wake on sender progress instead of polling: ~99 → ~6.7k batches/s per thread.sender_pool_min=sender_pool_max) no longer close and reopen idle connections.Each flush is still its own QWP message, ACK and rejection.
Measured against a server with commit coalescing questdb/questdb#8110 Against current QuestDB master, async stays at the
mainlevel.