added get benchmark for bbolt

This commit is contained in:
Andy Arthur
2022-09-08 17:12:42 -07:00
parent 6bedfcdeb3
commit 1a6a68ec26
2 changed files with 85 additions and 4 deletions
@@ -17,6 +17,7 @@ package benchmark
import (
"context"
"fmt"
"github.com/stretchr/testify/require"
"math/rand"
"sync"
"testing"
@@ -78,14 +79,18 @@ func BenchmarkStepParallelMapGet(b *testing.B) {
}
}
func BenchmarkProllyGetLarge(b *testing.B) {
func BenchmarkGetLargeProlly(b *testing.B) {
benchmarkProllyMapGet(b, 1_000_000)
}
func BenchmarkNomsGetLarge(b *testing.B) {
func BenchmarkGetLargeNoms(b *testing.B) {
benchmarkTypesMapGet(b, 1_000_000)
}
func BenchmarkGetLargeBBolt(b *testing.B) {
benchmarkBBoltMapGet(b, 1_000_000)
}
func BenchmarkProllyParallelGetLarge(b *testing.B) {
benchmarkProllyMapGetParallel(b, 1_000_000)
}
@@ -96,6 +101,7 @@ func BenchmarkNomsParallelGetLarge(b *testing.B) {
func benchmarkProllyMapGet(b *testing.B, size uint64) {
bench := generateProllyBench(b, size)
b.ResetTimer()
b.Run(fmt.Sprintf("benchmark new format reads"), func(b *testing.B) {
ctx := context.Background()
@@ -112,6 +118,7 @@ func benchmarkProllyMapGet(b *testing.B, size uint64) {
func benchmarkTypesMapGet(b *testing.B, size uint64) {
bench := generateTypesBench(b, size)
b.ResetTimer()
b.Run(fmt.Sprintf("benchmark old format reads"), func(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
@@ -122,6 +129,23 @@ func benchmarkTypesMapGet(b *testing.B, size uint64) {
})
}
func benchmarkBBoltMapGet(b *testing.B, size uint64) {
bench := generateBBoltBench(b, size)
b.ResetTimer()
b.Run(fmt.Sprintf("benchmark bbolt reads"), func(b *testing.B) {
tx, err := bench.db.Begin(false)
require.NoError(b, err)
bck := tx.Bucket(bucket)
for i := 0; i < b.N; i++ {
idx := rand.Uint64() % uint64(len(bench.tups))
key := bench.tups[idx][0]
_ = bck.Get(key)
}
b.ReportAllocs()
})
}
func benchmarkProllyMapGetParallel(b *testing.B, size uint64) {
bench := generateProllyBench(b, size)
b.Run(fmt.Sprintf("benchmark new format %d", size), func(b *testing.B) {
+59 -2
View File
@@ -16,7 +16,11 @@ package benchmark
import (
"context"
"github.com/stretchr/testify/require"
"go.etcd.io/bbolt"
"math/rand"
"os"
"path/filepath"
"testing"
"github.com/dolthub/dolt/go/store/chunks"
@@ -37,6 +41,11 @@ type typesBench struct {
tups [][2]types.Tuple
}
type bboltBench struct {
db *bbolt.DB
tups [][2]val.Tuple
}
func generateProllyBench(b *testing.B, size uint64) prollyBench {
b.StopTimer()
defer b.StartTimer()
@@ -44,7 +53,7 @@ func generateProllyBench(b *testing.B, size uint64) prollyBench {
ns := newTestNodeStore()
kd := val.NewTupleDescriptor(
val.Type{Enc: val.Int64Enc, Nullable: false},
val.Type{Enc: val.Uint64Enc, Nullable: false},
)
vd := val.NewTupleDescriptor(
val.Type{Enc: val.Int64Enc, Nullable: true},
@@ -85,7 +94,7 @@ func generateProllyTuples(kd, vd val.TupleDesc, size uint64) [][2]val.Tuple {
for i := range tups {
// key
kb.PutInt64(0, int64(i))
kb.PutUint64(0, uint64(i))
tups[i][0] = kb.Build(shared)
// val
@@ -151,3 +160,51 @@ func generateTypesTuples(size uint64) [][2]types.Tuple {
return tups
}
func generateBBoltBench(b *testing.B, size uint64) bboltBench {
b.StopTimer()
defer b.StartTimer()
kd := val.NewTupleDescriptor(
val.Type{Enc: val.Uint64Enc, Nullable: false},
)
vd := val.NewTupleDescriptor(
val.Type{Enc: val.Int64Enc, Nullable: true},
val.Type{Enc: val.Int64Enc, Nullable: true},
val.Type{Enc: val.Int64Enc, Nullable: true},
val.Type{Enc: val.Int64Enc, Nullable: true},
val.Type{Enc: val.Int64Enc, Nullable: true},
)
path, err := os.MkdirTemp("", "*")
require.NoError(b, err)
path = filepath.Join(path, "bolt.db")
db, err := bbolt.Open(path, 0666, &bbolt.Options{
// turn off fsync
NoGrowSync: true,
NoFreelistSync: true,
NoSync: true,
})
require.NoError(b, err)
err = db.Update(func(tx *bbolt.Tx) error {
_, err = tx.CreateBucket(bucket)
return err
})
require.NoError(b, err)
tups := generateProllyTuples(kd, vd, size)
const batch = 4096
for i := 0; i < len(tups); i += batch {
err = db.Update(func(tx *bbolt.Tx) error {
bck := tx.Bucket(bucket)
for j := i; j < (i+batch) && j < len(tups); j++ {
require.NoError(b, bck.Put(tups[j][0], tups[j][1]))
}
return nil
})
require.NoError(b, err)
}
return bboltBench{db: db, tups: tups}
}