Skip to content

Commit

Permalink
fix iavl benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Jan 31, 2024
1 parent de7ab09 commit 87ea39d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
4 changes: 4 additions & 0 deletions tm2/pkg/db/boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func NewBoltDBWithOpts(name string, dir string, opts *bbolt.Options) (db.DB, err
return nil, errors.New("ReadOnly: true is not supported")
}

if err := os.MkdirAll(dir, 0o700); err != nil {
return nil, fmt.Errorf("error creating dir: %w", err)
}

dbPath := filepath.Join(dir, name+".db")
db, err := bbolt.Open(dbPath, os.ModePerm, opts)
if err != nil {
Expand Down
71 changes: 33 additions & 38 deletions tm2/pkg/iavl/benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"os"
"runtime"
"slices"
"testing"

"github.com/jaekwon/testify/require"
Expand Down Expand Up @@ -151,63 +152,56 @@ type benchmark struct {
keyLen, dataLen int
}

func BenchmarkMedium(b *testing.B) {
b.Skip("TODO: benchmark panicking")
benchmarks := []benchmark{
{"memdb", 100000, 100, 16, 40},
{"goleveldb", 100000, 100, 16, 40},
// FIXME: this crashes on init! Either remove support, or make it work.
// {"cleveldb", 100000, 100, 16, 40},
{"leveldb", 100000, 100, 16, 40},
}
runBenchmarks(b, benchmarks)
func backendList() []db.BackendType {
return slices.DeleteFunc(db.BackendList(), func(s db.BackendType) bool {
// fsdb doesn't support batch ops, and it's slow anyways, so let's skip.
return s == db.FSDBBackend
})
}

func BenchmarkSmall(b *testing.B) {
b.Skip("TODO: benchmark panicking")
benchmarks := []benchmark{
{"memdb", 1000, 100, 4, 10},
{"goleveldb", 1000, 100, 4, 10},
// FIXME: this crashes on init! Either remove support, or make it work.
// {"cleveldb", 100000, 100, 16, 40},
{"leveldb", 1000, 100, 4, 10},
var bs []benchmark
for _, backend := range backendList() {
bs = append(bs, benchmark{backend, 1_000, 100, 16, 40})
}
runBenchmarks(b, benchmarks)
runBenchmarks(b, bs)
}

func BenchmarkMedium(b *testing.B) {
var bs []benchmark
for _, backend := range backendList() {
bs = append(bs, benchmark{backend, 100_000, 100, 16, 40})
}
runBenchmarks(b, bs)
}

func BenchmarkLarge(b *testing.B) {
b.Skip("TODO: benchmark panicking")
benchmarks := []benchmark{
{"memdb", 1000000, 100, 16, 40},
{"goleveldb", 1000000, 100, 16, 40},
// FIXME: this crashes on init! Either remove support, or make it work.
// {"cleveldb", 100000, 100, 16, 40},
{"leveldb", 1000000, 100, 16, 40},
var bs []benchmark
for _, backend := range backendList() {
bs = append(bs, benchmark{backend, 1_000_000, 100, 16, 40})
}
runBenchmarks(b, benchmarks)
runBenchmarks(b, bs)
}

func BenchmarkLevelDBBatchSizes(b *testing.B) {
b.Skip("TODO: benchmark panicking")
benchmarks := []benchmark{
{"goleveldb", 100000, 5, 16, 40},
{"goleveldb", 100000, 25, 16, 40},
{"goleveldb", 100000, 100, 16, 40},
{"goleveldb", 100000, 400, 16, 40},
{"goleveldb", 100000, 2000, 16, 40},
{db.GoLevelDBBackend, 100000, 5, 16, 40},
{db.GoLevelDBBackend, 100000, 25, 16, 40},
{db.GoLevelDBBackend, 100000, 100, 16, 40},
{db.GoLevelDBBackend, 100000, 400, 16, 40},
{db.GoLevelDBBackend, 100000, 2000, 16, 40},
}
runBenchmarks(b, benchmarks)
}

// BenchmarkLevelDBLargeData is intended to push disk limits
// in the leveldb, to make sure not everything is cached
func BenchmarkLevelDBLargeData(b *testing.B) {
b.Skip("TODO: benchmark panicking")
benchmarks := []benchmark{
{"goleveldb", 50000, 100, 32, 100},
{"goleveldb", 50000, 100, 32, 1000},
{"goleveldb", 50000, 100, 32, 10000},
{"goleveldb", 50000, 100, 32, 100000},
{db.GoLevelDBBackend, 50000, 100, 32, 100},
{db.GoLevelDBBackend, 50000, 100, 32, 1000},
{db.GoLevelDBBackend, 50000, 100, 32, 10000},
{db.GoLevelDBBackend, 50000, 100, 32, 100000},
}
runBenchmarks(b, benchmarks)
}
Expand All @@ -230,8 +224,9 @@ func runBenchmarks(b *testing.B, benchmarks []benchmark) {

// note that "" leads to nil backing db!
var d db.DB
var err error
if bb.dbType != "nodb" {
d, err := db.NewDB("test", bb.dbType, dirName)
d, err = db.NewDB("test", bb.dbType, dirName)
require.NoError(b, err)
defer d.Close()
}
Expand Down

0 comments on commit 87ea39d

Please sign in to comment.