Skip to content

Commit

Permalink
colblk: minor benchmark refactoring
Browse files Browse the repository at this point in the history
Adding a "short" version for the iterator benchmarks. We will add
combinations of various transforms with these selected configs.

We also slightly improve the benchmark naming.
  • Loading branch information
RaduBerinde committed Sep 29, 2024
1 parent 3fb8ee4 commit d93251c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
5 changes: 3 additions & 2 deletions internal/crdbtest/crdbtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"slices"
"time"

"github.com/cockroachdb/crlib/crstrings"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/internal/base"
"golang.org/x/exp/rand"
Expand Down Expand Up @@ -348,8 +349,8 @@ type KeyConfig struct {
}

func (cfg KeyConfig) String() string {
return fmt.Sprintf("AlphaLen=%d,Shared=%d,PrefixLen=%d,Logical=%d",
cfg.PrefixAlphabetLen, cfg.PrefixLenShared, cfg.PrefixLen, cfg.Logical)
return fmt.Sprintf("AlphaLen=%d,Prefix=%d,Shared=%d%s",
cfg.PrefixAlphabetLen, cfg.PrefixLen, cfg.PrefixLenShared, crstrings.If(cfg.Logical != 0, ",Logical"))
}

// RandomKVs constructs count random KVs with the provided parameters.
Expand Down
64 changes: 51 additions & 13 deletions sstable/colblk/cockroach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,36 +444,74 @@ func benchmarkCockroachDataBlockWriter(b *testing.B, keyConfig crdbtest.KeyConfi
}
}

func BenchmarkCockroachDataBlockIter(b *testing.B) {
func BenchmarkCockroachDataBlockIterFull(b *testing.B) {
for _, alphaLen := range []int{4, 8, 26} {
for _, lenSharedPct := range []float64{0.25, 0.5} {
for _, prefixLen := range []int{8, 32, 128} {
lenShared := int(float64(prefixLen) * lenSharedPct)
for _, logical := range []uint32{0, 1} {
for _, valueLen := range []int{8, 128, 1024} {
keyConfig := crdbtest.KeyConfig{
PrefixAlphabetLen: alphaLen,
PrefixLen: prefixLen,
PrefixLenShared: lenShared,
Logical: logical,
BaseWallTime: uint64(time.Now().UnixNano()),
cfg := benchConfig{
KeyConfig: crdbtest.KeyConfig{
PrefixAlphabetLen: alphaLen,
PrefixLen: prefixLen,
PrefixLenShared: lenShared,
Logical: logical,
},
ValueLen: valueLen,
}
b.Run(fmt.Sprintf("%s,value=%d", keyConfig, valueLen),
func(b *testing.B) {
benchmarkCockroachDataBlockIter(b, keyConfig, valueLen)
})
b.Run(cfg.String(), func(b *testing.B) {
benchmarkCockroachDataBlockIter(b, cfg)
})
}
}
}
}
}
}

func benchmarkCockroachDataBlockIter(b *testing.B, keyConfig crdbtest.KeyConfig, valueLen int) {
var shortBenchConfigs = []benchConfig{
{
KeyConfig: crdbtest.KeyConfig{
PrefixAlphabetLen: 8,
PrefixLen: 8,
PrefixLenShared: 4,
},
ValueLen: 8,
},
{
KeyConfig: crdbtest.KeyConfig{
PrefixAlphabetLen: 8,
PrefixLen: 128,
PrefixLenShared: 64,
},
ValueLen: 128,
},
}

func BenchmarkCockroachDataBlockIterShort(b *testing.B) {
for _, cfg := range shortBenchConfigs {
b.Run(cfg.String(), func(b *testing.B) {
benchmarkCockroachDataBlockIter(b, cfg)
})
}
}

type benchConfig struct {
crdbtest.KeyConfig
ValueLen int
}

func (cfg benchConfig) String() string {
return fmt.Sprintf("%s,ValueLen=%d", cfg.KeyConfig, cfg.ValueLen)
}

func benchmarkCockroachDataBlockIter(b *testing.B, cfg benchConfig) {
const targetBlockSize = 32 << 10
seed := uint64(time.Now().UnixNano())
rng := rand.New(rand.NewSource(seed))
keys, values := crdbtest.RandomKVs(rng, targetBlockSize/valueLen, keyConfig, valueLen)
cfg.BaseWallTime = seed
keys, values := crdbtest.RandomKVs(rng, targetBlockSize/cfg.ValueLen, cfg.KeyConfig, cfg.ValueLen)

var w DataBlockWriter
w.Init(cockroachKeySchema)
Expand Down

0 comments on commit d93251c

Please sign in to comment.