Repository navigation
perf: group-commit acks and enqueues per file - #15
Merged
Merged
Conversation
Concurrent Enqueue and Acknowledge calls on one file now share a transaction. The first caller with no round running leads: it commits what has queued up, at most its own round plus one more, under the file's write mutex, then hands the lead to the oldest waiting caller. Each caller still gets its own result. If the grouped transaction fails, the round rolls back and each call runs in a transaction of its own, so one bad call fails alone. Claims, pops and purge keep taking the write mutex directly.
A database/sql Tx costs a cancelable context and a goroutine per transaction. A round of one op has nothing to share, and in the folder layout about half the rounds hold one op, so at GOMAXPROCS=24 the Tx setup cost more than grouping saved (Mixed10Q/Folder-ckpt1000 fell about 19% below the per-call commits). A lone op now runs as one autocommit statement, still under the write mutex.
A leader ending its turn used to keep the lead set and pass it to the oldest waiting caller, so the next round waited for that goroutine to be woken and scheduled. Now the lead is given up and the oldest waiter is woken for it; a caller that arrives first takes it instead and commits the waiter's op in its own round. A leader still commits at most its own round plus one more. An op's done channel holds two: at most one wake-up and the outcome, so a commit never blocks on a caller that has not woken yet.
database/sql converts each argument inside Exec, and Exec now runs in whichever goroutine leads the round. An item whose driver.Valuer panicked there unwound past the batcher, so the lead stayed taken, the round's other callers never got a result, and a grouped round left its write transaction open. Enqueue now converts the item with the default parameter converter, as database/sql would for this driver, before the op joins a round, so such a panic stays with its own caller. Tests: a panicking item panics in its caller and later writes still work; a committing grouped round gives each op its own result from one transaction; the batching test queues writes behind a held round instead of counting rounds under a racing scheduler.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Stacked on #14 (
perf/batch-pop). Fourth of five for sqliteq v0.3.0.What changes
EnqueueandAcknowledgecalls that run at the same time on one file now commit together in one transaction (group commit). Seecommit.go.database/sqlTx.driver.Valuerstays with its own caller and cannot wedge the batcher.The branch keeps the two earlier hand-off designs as separate commits. The first passed the lead to a fixed successor, which left the file idle between rounds and lost about 20% at 24 CPUs. The second added the one-op autocommit. Both are kept for review history; squash on merge if you prefer.
Effect
From the end-to-end varmq benchmark, A/B/A against PR 3 with 8 samples per row:
WithSingleFile) gain +47% to +108%;Tests
go test -race ./...passes, including the batcher tests at GOMAXPROCS 1, 2 and 24. Tests cover:Closewhile rounds are in flight.