Skip to content

Commit

Permalink
storage/engine: add BenchmarkRocksDBDeleteRangeIterate
Browse files Browse the repository at this point in the history
Demonstrate the performance problem with iterating through a range
tombstone.

name                                        time/op
RocksDBDeleteRangeIterate/entries=10-8      6.09µs ± 3%
RocksDBDeleteRangeIterate/entries=1000-8     131µs ± 3%
RocksDBDeleteRangeIterate/entries=100000-8  12.3ms ± 3%

See cockroachdb#24029

Release note: None
  • Loading branch information
petermattis committed Jul 9, 2018
1 parent 8a71c5a commit 72dfb99
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions pkg/storage/engine/rocksdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,3 +1390,73 @@ func TestRocksDBDeleteRangeCompaction(t *testing.T) {
6: "b000000000" - "b000009999"
`)
}

func BenchmarkRocksDBDeleteRangeIterate(b *testing.B) {
for _, entries := range []int{10, 1000, 100000} {
b.Run(fmt.Sprintf("entries=%d", entries), func(b *testing.B) {
db := setupMVCCInMemRocksDB(b, "unused").(InMem)
defer db.Close()

makeKey := func(i int) roachpb.Key {
return roachpb.Key(fmt.Sprintf("%09d", i))
}

// Create an SST with N entries and ingest it. This is a fast way to get a
// lof of entries into RocksDB.
{
sst, err := MakeRocksDBSstFileWriter()
if err != nil {
b.Fatal(sst)
}
defer sst.Close()

for i := 0; i < entries; i++ {
kv := MVCCKeyValue{
Key: MVCCKey{
Key: makeKey(i),
},
}
if err := sst.Add(kv); err != nil {
b.Fatal(err)
}
}

sstContents, err := sst.Finish()
if err != nil {
b.Fatal(err)
}

filename := fmt.Sprintf("ingest")
if err := db.WriteFile(filename, sstContents); err != nil {
b.Fatal(err)
}

err := db.IngestExternalFiles(context.Background(), []string{filename}, true)
if err != nil {
b.Fatal(err)
}
}

// Create a range tombstone that overlaps all of these entries.
from := makeKey(0)
to := makeKey(entries)
if err := db.ClearRange(MakeMVCCMetadataKey(from), MakeMVCCMetadataKey(to)); err != nil {
b.Fatal(err)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
iter := db.NewIterator(IterOptions{UpperBound: roachpb.KeyMax})
iter.Seek(MakeMVCCMetadataKey(from))
ok, err := iter.Valid()
if err != nil {
b.Fatal(err)
}
if ok {
b.Fatal("unexpected key found")
}
iter.Close()
}
})
}
}

0 comments on commit 72dfb99

Please sign in to comment.