Repository navigation
Write each changed B-tree node once per async batch - #307
Conversation
a44dfc4 to
27e2581
Compare
8ef5a12 to
791bdb6
Compare
commit: |
791bdb6 to
6b09aeb
Compare
27e2581 to
afe137f
Compare
6b09aeb to
f80b0e1
Compare
afe137f to
cd3730c
Compare
f80b0e1 to
982df18
Compare
cd3730c to
2c2aa0b
Compare
982df18 to
b0f3330
Compare
b13d55a to
2968655
Compare
30bd753 to
bc6db89
Compare
2968655 to
80ef64c
Compare
bc6db89 to
731ffa8
Compare
51642f8 to
68730cd
Compare
4f93c01 to
dcbf793
Compare
fb302cc to
daf838b
Compare
26ee7df to
e363966
Compare
8e7cceb to
bc66a1f
Compare
e363966 to
1168555
Compare
2a9f92c to
f2ba2f7
Compare
0ac8c1e to
03058d4
Compare
276478e to
b23eac9
Compare
b23eac9 to
1931363
Compare
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
1931363 to
0371b87
Compare
| if (entry?.node && entry.pendingSize !== undefined) { | ||
| this.pendingDocuments--; | ||
| this.pendingWriteBytes -= entry.pendingSize; | ||
| this.pendingReadBytes -= entry.storedSize; |
There was a problem hiding this comment.
I think we still charge for reads when the user deletes
There was a problem hiding this comment.
Yeah, though we directly delete the node from the database, so the usage will have been charged already (and won't be charged again when flushing). Added a comment to clarify
| return BATCH_LIMITS.every( | ||
| (limit) => metrics[limit].remaining > FINISH_RESERVE[limit], | ||
| (limit) => | ||
| metrics[limit].remaining - pending[limit] > FINISH_RESERVE[limit], |
There was a problem hiding this comment.
| metrics[limit].remaining - pending[limit] > FINISH_RESERVE[limit], | |
| metrics[limit].remaining - (pending[limit] ?? 0) > FINISH_RESERVE[limit], |
we may add more metrics in the future. unless BATCH_LIMITS is already type-checked against BatchLimit keys in pending?
There was a problem hiding this comment.
yeah it is defined as
const BATCH_LIMITS = [
"bytesRead",
"bytesWritten",
"databaseQueries",
"documentsRead",
"documentsWritten",
] as const;
so it should be future proof
ianmacartney
left a comment
There was a problem hiding this comment.
I'm getting a bit nervous about how much of the convex internals we're having to duplicate.. ideally we could have the syscalls be so efficient that we don't need to do these user-space optimizations of optimizations we already have in Rust
|
Yeah... maybe runtime v2 will help? or maybe this is a good candidate for a Rust component... |
Every write patches each node on its path to keep counts and sums current, so a batch rewrote a tree's root once per operation. Hold node writes in the batch's node cache and flush them when the batch ends, counting the held writes against the transaction's headroom so the flush always fits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0371b87 to
4e0a605
Compare
Keeps node writes pending in the batch's
NodeCachingDatabaseWriterand writes each changed node once when the batch ends. Pending writes count against the transaction's headroom so the flush always fits.With the whole stack of changes, a 1024-op batch over 220 trees went from about 11k reads and 2.4k writes to 2.2k reads and 600 writes, and drain throughput rose from 279 to 481 ops/s. A batch over 11 trees used to run out the 1s user-code limit about 2.7s in and be retried forever, stalling the worker; it now finishes in about 0.4s.
Stack
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
🤖 Generated with Claude Code