Skip to content

Commit

Permalink
benchmarking for store batching
Browse files Browse the repository at this point in the history
  • Loading branch information
werty144 committed Jul 19, 2023
1 parent 7ca253f commit 2fa2e38
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ func makeStateAndBlockStore() (sm.State, *BlockStore, cleanupFunc) {
return state, NewBlockStore(blockDB), func() { os.RemoveAll(config.RootDir) }
}

func makeStateAndBlockStoreSpecificBackend(backendType dbm.BackendType) (sm.State, *BlockStore, cleanupFunc) {
config := test.ResetTestRoot("blockchain_reactor_test")
blockDB, err := dbm.NewDB("block", backendType, config.DBDir())
if err != nil {
panic(fmt.Errorf("error creating %s: %w", backendType, err))
}
stateDB, err := dbm.NewDB("state", backendType, config.DBDir())
if err != nil {
panic(fmt.Errorf("error creating %s: %w", backendType, err))
}
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
state, err := stateStore.LoadFromDBOrGenesisFile(config.GenesisFile())
if err != nil {
panic(fmt.Errorf("error constructing state from genesis file: %w", err))
}
return state, NewBlockStore(blockDB), func() { os.RemoveAll(config.RootDir) }
}

func TestLoadBlockStoreState(t *testing.T) {
type blockStoreTest struct {
testName string
Expand Down Expand Up @@ -356,6 +376,85 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
}
}

func TestBlockStore_SaveBlockWithExtendedCommit(t *testing.T) {
dbTypes := []dbm.BackendType{
// - requires gcc
// - use cleveldb build tag (go build -tags cleveldb)
// - you should have levelDB installed
dbm.CLevelDBBackend,
// - requires gcc
// - use rocksdb build tag (go build -tags rocksdb)
// - you should have rocksDB installed
dbm.RocksDBBackend,
// - use badgerdb build tag (go build -tags badgerdb)
dbm.BadgerDBBackend,
// - use boltdb build tag (go build -tags boltdb)
dbm.BoltDBBackend,
dbm.GoLevelDBBackend,
dbm.MemDBBackend,
}
NTXs := int64(1000)

for _, dbType := range dbTypes {
state, bs, cleanup := makeStateAndBlockStoreSpecificBackend(dbType)
t.Run(fmt.Sprintf("DBType:%s;NTxs:%d", dbType, NTXs),
func(t *testing.T) {
height := bs.Height() + 1
block := state.MakeBlock(height, test.MakeNTxs(height, NTXs), new(types.Commit), nil, state.Validators.GetProposer().Address)
validPartSet, err := block.MakePartSet(2)
if err != nil {
t.Error(err)
}
seenCommit := makeTestExtCommit(block.Header.Height, cmttime.Now())

bs.SaveBlockWithExtendedCommit(block, validPartSet, seenCommit)
retrievedBlock := bs.LoadBlock(height)
require.Equal(t, retrievedBlock.Hash(), block.Hash())
})

cleanup()
}
}

func BenchmarkBlockStore_SaveBlockWithExtendedCommit(b *testing.B) {
dbTypes := []dbm.BackendType{
// - requires gcc
// - use cleveldb build tag (go build -tags cleveldb)
// - you should have levelDB installed
dbm.CLevelDBBackend,
// - requires gcc
// - use rocksdb build tag (go build -tags rocksdb)
// - you should have rocksDB installed
dbm.RocksDBBackend,
// - use badgerdb build tag (go build -tags badgerdb)
dbm.BadgerDBBackend,
// - use boltdb build tag (go build -tags boltdb)
dbm.BoltDBBackend,
dbm.GoLevelDBBackend,
dbm.MemDBBackend,
}
NTXs := int64(1000)

for _, dbType := range dbTypes {
state, bs, cleanup := makeStateAndBlockStoreSpecificBackend(dbType)
b.Run(fmt.Sprintf("DBType:%s;NTxs:%d", dbType, NTXs),
func(b *testing.B) {
height := bs.Height() + 1
block := state.MakeBlock(height, test.MakeNTxs(height, NTXs), new(types.Commit), nil, state.Validators.GetProposer().Address)
validPartSet, err := block.MakePartSet(2)
if err != nil {
b.Error(err)
}
seenCommit := makeTestExtCommit(block.Header.Height, cmttime.Now())

bs.SaveBlockWithExtendedCommit(block, validPartSet, seenCommit)
})

cleanup()
}

}

// stripExtensions removes all VoteExtension data from an ExtendedCommit. This
// is useful when dealing with an ExendedCommit but vote extension data is
// expected to be absent.
Expand Down

0 comments on commit 2fa2e38

Please sign in to comment.