Skip to content

Commit

Permalink
db: amend BenchmarkRangeDelIterate
Browse files Browse the repository at this point in the history
Amend BenchmarkRangeDelIterate to include benchmarks that iterate
through keys that are deleted by a range tombstone within the same
SSTable.

See #1070.

```
goos: linux
goarch: amd64
pkg: github.com/cockroachdb/pebble
BenchmarkRangeDelIterate
BenchmarkRangeDelIterate/entries=10
BenchmarkRangeDelIterate/entries=10/deleted=10
BenchmarkRangeDelIterate/entries=10/deleted=10/snapshotAndCompact=false
BenchmarkRangeDelIterate/entries=10/deleted=10/snapshotAndCompact=false-24         	 1868349	       636 ns/op
BenchmarkRangeDelIterate/entries=10/deleted=10/snapshotAndCompact=true
BenchmarkRangeDelIterate/entries=10/deleted=10/snapshotAndCompact=true-24          	  403632	      2945 ns/op
BenchmarkRangeDelIterate/entries=10/deleted=9
BenchmarkRangeDelIterate/entries=10/deleted=9/snapshotAndCompact=false
BenchmarkRangeDelIterate/entries=10/deleted=9/snapshotAndCompact=false-24          	  647324	      1855 ns/op
BenchmarkRangeDelIterate/entries=10/deleted=9/snapshotAndCompact=true
BenchmarkRangeDelIterate/entries=10/deleted=9/snapshotAndCompact=true-24           	  425908	      2793 ns/op
BenchmarkRangeDelIterate/entries=1000
BenchmarkRangeDelIterate/entries=1000/deleted=1000
BenchmarkRangeDelIterate/entries=1000/deleted=1000/snapshotAndCompact=false
BenchmarkRangeDelIterate/entries=1000/deleted=1000/snapshotAndCompact=false-24     	 1874809	       642 ns/op
BenchmarkRangeDelIterate/entries=1000/deleted=1000/snapshotAndCompact=true
BenchmarkRangeDelIterate/entries=1000/deleted=1000/snapshotAndCompact=true-24      	   10000	    106763 ns/op
BenchmarkRangeDelIterate/entries=1000/deleted=999
BenchmarkRangeDelIterate/entries=1000/deleted=999/snapshotAndCompact=false
BenchmarkRangeDelIterate/entries=1000/deleted=999/snapshotAndCompact=false-24      	  613291	      1895 ns/op
BenchmarkRangeDelIterate/entries=1000/deleted=999/snapshotAndCompact=true
BenchmarkRangeDelIterate/entries=1000/deleted=999/snapshotAndCompact=true-24       	   10000	    106169 ns/op
BenchmarkRangeDelIterate/entries=100000
BenchmarkRangeDelIterate/entries=100000/deleted=100000
BenchmarkRangeDelIterate/entries=100000/deleted=100000/snapshotAndCompact=false
BenchmarkRangeDelIterate/entries=100000/deleted=100000/snapshotAndCompact=false-24 	 1865816	       640 ns/op
BenchmarkRangeDelIterate/entries=100000/deleted=100000/snapshotAndCompact=true
BenchmarkRangeDelIterate/entries=100000/deleted=100000/snapshotAndCompact=true-24  	     106	  10928184 ns/op
BenchmarkRangeDelIterate/entries=100000/deleted=99999
BenchmarkRangeDelIterate/entries=100000/deleted=99999/snapshotAndCompact=false
BenchmarkRangeDelIterate/entries=100000/deleted=99999/snapshotAndCompact=false-24  	  614889	      1937 ns/op
BenchmarkRangeDelIterate/entries=100000/deleted=99999/snapshotAndCompact=true
BenchmarkRangeDelIterate/entries=100000/deleted=99999/snapshotAndCompact=true-24   	     105	  10958571 ns/op
```
  • Loading branch information
jbowens committed Feb 25, 2021
1 parent 560af6e commit 68984a5
Showing 1 changed file with 79 additions and 59 deletions.
138 changes: 79 additions & 59 deletions range_del_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,70 +452,90 @@ func BenchmarkRangeDelIterate(b *testing.B) {
b.Run(fmt.Sprintf("entries=%d", entries), func(b *testing.B) {
for _, deleted := range []int{entries, entries - 1} {
b.Run(fmt.Sprintf("deleted=%d", deleted), func(b *testing.B) {
mem := vfs.NewMem()
cache := NewCache(128 << 20) // 128 MB
defer cache.Unref()

d, err := Open("", &Options{
Cache: cache,
FS: mem,
DebugCheck: DebugCheckLevels,
})
if err != nil {
b.Fatal(err)
for _, snapshotCompact := range []bool{false, true} {
b.Run(fmt.Sprintf("snapshotAndCompact=%t", snapshotCompact), func(b *testing.B) {
benchmarkRangeDelIterate(b, entries, deleted, snapshotCompact)
})
}
defer d.Close()
})
}
})
}
}

makeKey := func(i int) []byte {
return []byte(fmt.Sprintf("%09d", i))
}
func benchmarkRangeDelIterate(b *testing.B, entries, deleted int, snapshotCompact bool) {
mem := vfs.NewMem()
cache := NewCache(128 << 20) // 128 MB
defer cache.Unref()

// Create an sstable with N entries and ingest it. This is a fast way
// to get a lot of entries into pebble.
f, err := mem.Create("ext")
if err != nil {
b.Fatal(err)
}
w := sstable.NewWriter(f, sstable.WriterOptions{
BlockSize: 32 << 10, // 32 KB
})
for i := 0; i < entries; i++ {
key := base.MakeInternalKey(makeKey(i), 0, InternalKeyKindSet)
if err := w.Add(key, nil); err != nil {
b.Fatal(err)
}
}
if err := w.Close(); err != nil {
b.Fatal(err)
}
if err := d.Ingest([]string{"ext"}); err != nil {
b.Fatal(err)
}
d, err := Open("", &Options{
Cache: cache,
FS: mem,
DebugCheck: DebugCheckLevels,
})
if err != nil {
b.Fatal(err)
}
defer d.Close()

// Create a range tombstone that deletes most (or all) of those entries.
from := makeKey(0)
to := makeKey(deleted)
if err := d.DeleteRange(from, to, nil); err != nil {
b.Fatal(err)
}
makeKey := func(i int) []byte {
return []byte(fmt.Sprintf("%09d", i))
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
iter := d.NewIter(nil)
iter.SeekGE(from)
if deleted < entries {
if !iter.Valid() {
b.Fatal("key not found")
}
} else if iter.Valid() {
b.Fatal("unexpected key found")
}
if err := iter.Close(); err != nil {
b.Fatal(err)
}
}
})
// Create an sstable with N entries and ingest it. This is a fast way
// to get a lot of entries into pebble.
f, err := mem.Create("ext")
if err != nil {
b.Fatal(err)
}
w := sstable.NewWriter(f, sstable.WriterOptions{
BlockSize: 32 << 10, // 32 KB
})
for i := 0; i < entries; i++ {
key := base.MakeInternalKey(makeKey(i), 0, InternalKeyKindSet)
if err := w.Add(key, nil); err != nil {
b.Fatal(err)
}
}
if err := w.Close(); err != nil {
b.Fatal(err)
}
if err := d.Ingest([]string{"ext"}); err != nil {
b.Fatal(err)
}

// Some benchmarks test snapshots that force the range tombstone into the
// same level as the covered data.
// See https://github.com/cockroachdb/pebble/issues/1070.
if snapshotCompact {
s := d.NewSnapshot()
defer func() { require.NoError(b, s.Close()) }()
}

// Create a range tombstone that deletes most (or all) of those entries.
from := makeKey(0)
to := makeKey(deleted)
if err := d.DeleteRange(from, to, nil); err != nil {
b.Fatal(err)
}

if snapshotCompact {
require.NoError(b, d.Compact(makeKey(0), makeKey(entries)))
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
iter := d.NewIter(nil)
iter.SeekGE(from)
if deleted < entries {
if !iter.Valid() {
b.Fatal("key not found")
}
})
} else if iter.Valid() {
b.Fatal("unexpected key found")
}
if err := iter.Close(); err != nil {
b.Fatal(err)
}
}
}

0 comments on commit 68984a5

Please sign in to comment.