storage/engine: cache iterators within read-only batches#16406
storage/engine: cache iterators within read-only batches#16406petermattis merged 1 commit intocockroachdb:masterfrom
Conversation
|
(Don't mind me—edited the description to align the benchmark results.) |
|
Looks good overall. I think we want to do this even though the performance benefit over using a normal batch is small. It ensures that read-only operations are truly read-only. Some comments below, the only major one being that Review status: 0 of 6 files reviewed at latest revision, 4 unresolved discussions, some commit checks pending. pkg/storage/replica.go, line 2285 at r1 (raw file):
Per my other comment, we need to pkg/storage/engine/batch_test.go, line 235 at r1 (raw file):
There is no need for the indirection here. It is done for some of the other tests where we're passing in different values. Just inline the body of pkg/storage/engine/engine.go, line 197 at r1 (raw file):
This method needs a documentation comment. pkg/storage/engine/rocksdb.go, line 649 at r1 (raw file):
We do need to destroy the iterators here. Something like: This also means we need to ensure we Comments from Reviewable |
|
Review status: 0 of 6 files reviewed at latest revision, 4 unresolved discussions, some commit checks pending. pkg/storage/replica.go, line 2285 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/storage/engine/batch_test.go, line 235 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/storage/engine/engine.go, line 197 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/storage/engine/rocksdb.go, line 649 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
changed Close to do this as well as set a boolean flag. Comments from Reviewable |
|
Review status: 0 of 6 files reviewed at latest revision, 1 unresolved discussion, some commit checks pending. pkg/storage/engine/rocksdb.go, line 649 at r1 (raw file): Previously, jonderry wrote…
Done. Comments from Reviewable |
|
One final bit is to tie the PR to the issue. Add the following to the end of the commit message: Review status: 0 of 6 files reviewed at latest revision, all discussions resolved, some commit checks pending. Comments from Reviewable |
|
@jonderry There are a few test failures (mostly style issues) that need to be fixed up before this can be merged. |
Read-only batches currently execute on a RocksDB which bypasses the optimization to reuse iterators across execution of a command that occurs when using a *rocksDBBatch. We create a minimalist wrapper for RocksDB called rocksDBReadOnly that caches iterators and does not have the overhead of state for supporting writes. Here are the results of microbenchmarks that test the relative performance of iterating over one key using the underlying engine, versus the read-write batch versus the read only wrapper: Engine vs. ReadOnly name old time/op new time/op delta IterOn/10-8 1.15us 0.51us -55.60% (p=0.000 n=10+9) IterOn/100-8 1.25us 0.66us -47.44% (p=0.000 n=9+10) IterOn/1000-8 1.42us 0.81us -42.99% (p=0.000 n=9+9) IterOn/10000-8 1.63us 0.99us -39.40% (p=0.000 n=10+10) Batch vs. ReadOnly name old time/op new time/op delta IterOn/10-8 568ns 510ns -10.27% (p=0.000 n=10+9) IterOn/100-8 705ns 659ns -6.51% (p=0.000 n=10+10) IterOn/1000-8 855ns 811ns -5.18% (p=0.000 n=10+9) IterOn/10000-8 1.02us 0.99us -3.33% (p=0.000 n=9+10) Fixes cockroachdb#6803
|
@jonderry I fixed the style issues. I'll merge this when green. |
| } | ||
|
|
||
| func (r *rocksDBReadOnly) NewTimeBoundIterator(start, end hlc.Timestamp) Iterator { | ||
| panic("not implemented") |
There was a problem hiding this comment.
This function gets called from sqlccl.BenchmarkClusterEmptyIncrementalBackup, which now panics. @petermattis
There was a problem hiding this comment.
Then it's likely this broke backups when enterprise.kv.timebound_iterator.enabled is true, too.
Read-only batches currently execute on a RocksDB which bypasses the
optimization to reuse iterators across execution of a command that
occurs when using a *rocksDBBatch. We create a minimalist wrapper for
RocksDB called rocksDBReadOnly that caches iterators and does not
have the overhead of state for supporting writes. Here are the results
of microbenchmarks that test the relative performance of iterating over
one key using the underlying engine, versus the read-write batch versus
the read only wrapper: