From ef5db7bbe3edeed066faf36156f09f23deed2387 Mon Sep 17 00:00:00 2001 From: Oliver Bundalo Date: Fri, 5 Apr 2024 14:47:52 +0200 Subject: [PATCH 1/2] Benchmark tests for DBs --- .../storagev2/leveldb/leveldb_perf_test.go | 109 +++----------- blockchain/storagev2/leveldb/leveldb_test.go | 58 +++----- blockchain/storagev2/mdbx/mdbx_perf_test.go | 83 +++-------- blockchain/storagev2/mdbx/mdbx_test.go | 50 ++----- blockchain/storagev2/storage_write.go | 4 +- blockchain/storagev2/testing.go | 18 +-- blockchain/storagev2/testing_perf.go | 136 ++++++++++++------ 7 files changed, 176 insertions(+), 282 deletions(-) diff --git a/blockchain/storagev2/leveldb/leveldb_perf_test.go b/blockchain/storagev2/leveldb/leveldb_perf_test.go index b05fd58be6..8f16a2d546 100644 --- a/blockchain/storagev2/leveldb/leveldb_perf_test.go +++ b/blockchain/storagev2/leveldb/leveldb_perf_test.go @@ -1,119 +1,48 @@ package leveldb import ( - "math/rand" "os" - "path/filepath" - "strings" "testing" - "time" "github.com/0xPolygon/polygon-edge/blockchain/storagev2" "github.com/hashicorp/go-hclog" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/syndtr/goleveldb/leveldb/opt" ) -func openStorage(t *testing.T, p string) (*storagev2.Storage, func(), string) { - t.Helper() +func openStorage(b *testing.B, p string) (*storagev2.Storage, func(), string) { + b.Helper() s, err := NewLevelDBStorage(p, hclog.NewNullLogger()) - require.NoError(t, err) + require.NoError(b, err) closeFn := func() { - require.NoError(t, s.Close()) + require.NoError(b, s.Close()) if err := s.Close(); err != nil { - t.Fatal(err) + b.Fatal(err) } - require.NoError(t, os.RemoveAll(p)) + require.NoError(b, os.RemoveAll(p)) } return s, closeFn, p } -func dbSize(t *testing.T, path string) int64 { - t.Helper() +func Benchmark(b *testing.B) { + b.StopTimer() - var size int64 + s, cleanUpFn, path := openStorage(b, "/tmp/leveldbV2-test-perf") + defer func() { + s.Close() + cleanUpFn() + }() - err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { - if err != nil { - t.Fail() - } - - if info != nil && !info.IsDir() && strings.Contains(info.Name(), ".ldb") { - size += info.Size() - } - - return err - }) - if err != nil { - t.Log(err) - } - - return size -} - -func TestWriteBlockPerf(t *testing.T) { - t.SkipNow() - - s, _, path := openStorage(t, "/tmp/leveldbV2-test") - defer s.Close() - - var watchTime int64 - - count := 10000 - b := storagev2.CreateBlock(t) - - for i := 1; i <= count; i++ { - storagev2.UpdateBlock(t, uint64(i), b) - batchWriter := storagev2.PrepareBatch(t, s, b) - - tn := time.Now().UTC() - - require.NoError(t, batchWriter.WriteBatch()) + blockCount := 1000 + storagev2.BenchmarkStorage(b, blockCount, s, 47, 33) // CI times - d := time.Since(tn) - watchTime += d.Milliseconds() - } - - time.Sleep(time.Second) - - size := dbSize(t, path) - t.Logf("\tdb size %d MB", size/(1*opt.MiB)) - t.Logf("\ttotal WriteBatch %d ms", watchTime) -} - -func TestReadBlockPerf(t *testing.T) { - t.SkipNow() - - s, _, _ := openStorage(t, "/tmp/leveldbV2-test") - defer s.Close() - - var watchTime int64 - - count := 1000 - for i := 1; i <= count; i++ { - n := uint64(1 + rand.Intn(10000)) - - tn := time.Now().UTC() - h, ok := s.ReadCanonicalHash(n) - _, err1 := s.ReadBody(n, h) - _, err3 := s.ReadHeader(n, h) - _, err4 := s.ReadReceipts(n, h) - b, err5 := s.ReadBlockLookup(h) - d := time.Since(tn) - - watchTime += d.Milliseconds() - - if !ok || err1 != nil || err3 != nil || err4 != nil || err5 != nil { - t.Logf("\terror") - } - - assert.Equal(t, n, b) - } - t.Logf("\ttotal read %d ms", watchTime) + size, err := dbSize(path) + require.NoError(b, err) + b.Logf("\tldb file count: %d", countLdbFilesInPath(path)) + b.Logf("\tdb size %d MB", size/(1*opt.MiB)) } diff --git a/blockchain/storagev2/leveldb/leveldb_test.go b/blockchain/storagev2/leveldb/leveldb_test.go index cb180a5212..610623377a 100644 --- a/blockchain/storagev2/leveldb/leveldb_test.go +++ b/blockchain/storagev2/leveldb/leveldb_test.go @@ -6,6 +6,7 @@ import ( "os" "os/signal" "path/filepath" + "strings" "sync" "syscall" "testing" @@ -18,10 +19,10 @@ import ( "github.com/syndtr/goleveldb/leveldb/opt" ) -func newStorage(t *testing.T) (*storagev2.Storage, func()) { +func newStorage(t *testing.T) (*storagev2.Storage, func(), string) { t.Helper() - path, err := os.MkdirTemp("/tmp", "minimal_storage") + path, err := os.MkdirTemp("", "leveldbV2") if err != nil { t.Fatal(err) } @@ -41,31 +42,7 @@ func newStorage(t *testing.T) (*storagev2.Storage, func()) { } } - return s, closeFn -} - -func newStorageP(t *testing.T) (*storagev2.Storage, func(), string) { - t.Helper() - - p, err := os.MkdirTemp("", "leveldbV2-test") - require.NoError(t, err) - - require.NoError(t, os.MkdirAll(p, 0755)) - - s, err := NewLevelDBStorage(p, hclog.NewNullLogger()) - require.NoError(t, err) - - closeFn := func() { - require.NoError(t, s.Close()) - - if err := s.Close(); err != nil { - t.Fatal(err) - } - - require.NoError(t, os.RemoveAll(p)) - } - - return s, closeFn, p + return s, closeFn, path } func countLdbFilesInPath(path string) int { @@ -79,27 +56,22 @@ func countLdbFilesInPath(path string) int { return len(files) } -func dirSize(t *testing.T, path string) int64 { - t.Helper() - +func dbSize(path string) (int64, error) { var size int64 err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { if err != nil { - t.Fail() + return err } - if !info.IsDir() { + if info != nil && !info.IsDir() && strings.Contains(info.Name(), ".ldb") { size += info.Size() } return err }) - if err != nil { - t.Log(err) - } - return size + return size, err } func writeBlock(t *testing.T, s *storagev2.Storage, b *types.FullBlock) { @@ -171,13 +143,16 @@ func TestStorage(t *testing.T) { } func TestWriteReadFullBlockInParallel(t *testing.T) { - s, _, path := newStorageP(t) - defer s.Close() + s, cleanUpFn, path := newStorage(t) + defer func() { + s.Close() + cleanUpFn() + }() var wg sync.WaitGroup blockCount := 100 - ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) + ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2) signchan := make(chan os.Signal, 1) signal.Notify(signchan, syscall.SIGINT) @@ -208,8 +183,9 @@ insertloop: } } - size := dirSize(t, path) + size, err := dbSize(path) + require.NoError(t, err) t.Logf("\tldb file count: %d", countLdbFilesInPath(path)) - t.Logf("\tdir size %d MBs", size/(1*opt.MiB)) + t.Logf("\tdb size %d MBs", size/(1*opt.MiB)) wg.Wait() } diff --git a/blockchain/storagev2/mdbx/mdbx_perf_test.go b/blockchain/storagev2/mdbx/mdbx_perf_test.go index a611cbdbb4..642be6f5cd 100644 --- a/blockchain/storagev2/mdbx/mdbx_perf_test.go +++ b/blockchain/storagev2/mdbx/mdbx_perf_test.go @@ -1,93 +1,46 @@ package mdbx import ( - "math/rand" "os" "testing" - "time" "github.com/0xPolygon/polygon-edge/blockchain/storagev2" "github.com/hashicorp/go-hclog" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -func openStorage(t *testing.T, p string) (*storagev2.Storage, func(), string) { - t.Helper() +func openStorage(b *testing.B, p string) (*storagev2.Storage, func(), string) { + b.Helper() s, err := NewMdbxStorage(p, hclog.NewNullLogger()) - require.NoError(t, err) + require.NoError(b, err) closeFn := func() { - require.NoError(t, s.Close()) + require.NoError(b, s.Close()) if err := s.Close(); err != nil { - t.Fatal(err) + b.Fatal(err) } - require.NoError(t, os.RemoveAll(p)) + require.NoError(b, os.RemoveAll(p)) } return s, closeFn, p } -func TestWriteBlockPerf(t *testing.T) { - t.SkipNow() +func Benchmark(b *testing.B) { + b.StopTimer() - s, _, path := openStorage(t, "/tmp/mdbx-test") - defer s.Close() + s, cleanUpFn, path := openStorage(b, "/tmp/mdbx-test-perf") + defer func() { + s.Close() + cleanUpFn() + }() - var watchTime int64 + blockCount := 1000 + storagev2.BenchmarkStorage(b, blockCount, s, 75, 65) // CI times - count := 10000 - b := storagev2.CreateBlock(t) - - for i := 1; i <= count; i++ { - storagev2.UpdateBlock(t, uint64(i), b) - batchWriter := storagev2.PrepareBatch(t, s, b) - - tn := time.Now().UTC() - - require.NoError(t, batchWriter.WriteBatch()) - - d := time.Since(tn) - watchTime += d.Milliseconds() - } - - time.Sleep(time.Second) - - size := dbSize(t, path) - t.Logf("\tdb size %d MB", size/(1024*1024)) - t.Logf("\ttotal WriteBatch %d ms", watchTime) -} - -func TestReadBlockPerf(t *testing.T) { - t.SkipNow() - - s, _, _ := openStorage(t, "/tmp/mdbx-test") - defer s.Close() - - var watchTime int64 - - count := 1000 - for i := 1; i <= count; i++ { - n := uint64(1 + rand.Intn(10000)) - - tn := time.Now().UTC() - h, ok := s.ReadCanonicalHash(n) - _, err1 := s.ReadBody(n, h) - _, err3 := s.ReadHeader(n, h) - _, err4 := s.ReadReceipts(n, h) - b, err5 := s.ReadBlockLookup(h) - d := time.Since(tn) - - watchTime += d.Milliseconds() - - if !ok || err1 != nil || err3 != nil || err4 != nil || err5 != nil { - t.Logf("\terror") - } - - assert.Equal(t, n, b) - } - t.Logf("\ttotal read %d ms", watchTime) + size, err := dbSize(path) + require.NoError(b, err) + b.Logf("\tdb size %d MB", size/1048576) } diff --git a/blockchain/storagev2/mdbx/mdbx_test.go b/blockchain/storagev2/mdbx/mdbx_test.go index e790e134fa..488308da6c 100644 --- a/blockchain/storagev2/mdbx/mdbx_test.go +++ b/blockchain/storagev2/mdbx/mdbx_test.go @@ -16,10 +16,10 @@ import ( "github.com/stretchr/testify/require" ) -func newStorage(t *testing.T) (*storagev2.Storage, func()) { +func newStorage(t *testing.T) (*storagev2.Storage, func(), string) { t.Helper() - path, err := os.MkdirTemp("/tmp", "minimal_storage") + path, err := os.MkdirTemp("/tmp", "mdbx") if err != nil { t.Fatal(err) } @@ -39,36 +39,10 @@ func newStorage(t *testing.T) (*storagev2.Storage, func()) { } } - return s, closeFn + return s, closeFn, path } -func newStorageP(t *testing.T) (*storagev2.Storage, func(), string) { - t.Helper() - - p, err := os.MkdirTemp("", "mdbx-test") - require.NoError(t, err) - - require.NoError(t, os.MkdirAll(p, 0755)) - - s, err := NewMdbxStorage(p, hclog.NewNullLogger()) - require.NoError(t, err) - - closeFn := func() { - require.NoError(t, s.Close()) - - if err := s.Close(); err != nil { - t.Fatal(err) - } - - require.NoError(t, os.RemoveAll(p)) - } - - return s, closeFn, p -} - -func dbSize(t *testing.T, path string) int64 { - t.Helper() - +func dbSize(path string) (int64, error) { var size int64 err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { @@ -82,9 +56,8 @@ func dbSize(t *testing.T, path string) int64 { return nil }) - require.NoError(t, err) - return size + return size, err } func TestStorage(t *testing.T) { @@ -92,8 +65,11 @@ func TestStorage(t *testing.T) { } func TestWriteFullBlock(t *testing.T) { - s, _, path := newStorageP(t) - defer s.Close() + s, cleanUpFn, path := newStorage(t) + defer func() { + s.Close() + cleanUpFn() + }() count := 100 ctx, cancel := context.WithTimeout(context.Background(), time.Minute*45) @@ -130,9 +106,11 @@ insertloop: batchWriter.PutCanonicalHash(uint64(i), b.Block.Hash()) require.NoError(t, batchWriter.WriteBatch()) - size := dbSize(t, path) t.Logf("writing block %d", i) - t.Logf("\tdir size %d MBs", size/1_000_000) } } + + size, err := dbSize(path) + require.NoError(t, err) + t.Logf("\tdb size %d MBs", size/1048576) } diff --git a/blockchain/storagev2/storage_write.go b/blockchain/storagev2/storage_write.go index e76c607a91..0cd84ce75f 100644 --- a/blockchain/storagev2/storage_write.go +++ b/blockchain/storagev2/storage_write.go @@ -101,5 +101,7 @@ func (w *Writer) getBatch(t uint8) Batch { } func getKey(n uint64, h types.Hash) []byte { - return append(append(make([]byte, 0, 40), common.EncodeUint64ToBytes(n)...), h.Bytes()...) + a, b := common.EncodeUint64ToBytes(n), h.Bytes() + + return append(append(make([]byte, 0, len(a)+len(b)), a...), b...) } diff --git a/blockchain/storagev2/testing.go b/blockchain/storagev2/testing.go index 2ce4cef19f..c606bd9f1d 100644 --- a/blockchain/storagev2/testing.go +++ b/blockchain/storagev2/testing.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/require" ) -type PlaceholderStorage func(t *testing.T) (*Storage, func()) +type PlaceholderStorage func(t *testing.T) (*Storage, func(), string) var ( addr1 = types.StringToAddress("1") @@ -57,7 +57,7 @@ func TestStorage(t *testing.T, m PlaceholderStorage) { func testCanonicalChain(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() var cases = []struct { @@ -107,7 +107,7 @@ func testCanonicalChain(t *testing.T, m PlaceholderStorage) { func testDifficulty(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() var cases = []struct { @@ -151,7 +151,7 @@ func testDifficulty(t *testing.T, m PlaceholderStorage) { func testHead(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() for i := uint64(0); i < 5; i++ { @@ -188,7 +188,7 @@ func testHead(t *testing.T, m PlaceholderStorage) { func testForks(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() var cases = []struct { @@ -217,7 +217,7 @@ func testForks(t *testing.T, m PlaceholderStorage) { func testHeader(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() header := &types.Header{ @@ -247,7 +247,7 @@ func testHeader(t *testing.T, m PlaceholderStorage) { func testBody(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() header := &types.Header{ @@ -321,7 +321,7 @@ func testBody(t *testing.T, m PlaceholderStorage) { func testReceipts(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() batch := s.NewWriter() @@ -391,7 +391,7 @@ func testReceipts(t *testing.T, m PlaceholderStorage) { func testWriteCanonicalHeader(t *testing.T, m PlaceholderStorage) { t.Helper() - s, closeFn := m(t) + s, closeFn, _ := m(t) defer closeFn() h := &types.Header{ diff --git a/blockchain/storagev2/testing_perf.go b/blockchain/storagev2/testing_perf.go index 9926274887..b482d58d9c 100644 --- a/blockchain/storagev2/testing_perf.go +++ b/blockchain/storagev2/testing_perf.go @@ -1,8 +1,9 @@ package storagev2 import ( - "crypto/rand" + cryptoRand "crypto/rand" "math/big" + mathRand "math/rand" "testing" "github.com/0xPolygon/polygon-edge/types" @@ -11,18 +12,18 @@ import ( const letterBytes = "abcdef0123456789" -func randStringBytes(t *testing.T, n int) string { - t.Helper() +func randStringBytes(b *testing.B, n int) string { + b.Helper() - b := make([]byte, n) - _, err := rand.Reader.Read(b) - require.NoError(t, err) + retVal := make([]byte, n) + _, err := cryptoRand.Reader.Read(retVal) + require.NoError(b, err) - return string(b) + return string(retVal) } -func createTxs(t *testing.T, startNonce, count int, from types.Address, to *types.Address) []*types.Transaction { - t.Helper() +func createTxs(b *testing.B, startNonce, count int, from types.Address, to *types.Address) []*types.Transaction { + b.Helper() txs := make([]*types.Transaction, count) @@ -43,21 +44,21 @@ func createTxs(t *testing.T, startNonce, count int, from types.Address, to *type return txs } -func CreateBlock(t *testing.T) *types.FullBlock { - t.Helper() +func createBlock(b *testing.B) *types.FullBlock { + b.Helper() transactionsCount := 2500 status := types.ReceiptSuccess addr1 := types.StringToAddress("17878aa") addr2 := types.StringToAddress("2bf5653") - b := &types.FullBlock{ + fb := &types.FullBlock{ Block: &types.Block{ Header: &types.Header{ Number: 0, ExtraData: make([]byte, 32), Hash: types.ZeroHash, }, - Transactions: createTxs(t, 0, transactionsCount, addr1, &addr2), + Transactions: createTxs(b, 0, transactionsCount, addr1, &addr2), // Uncles: blockchain.NewTestHeaders(10), }, Receipts: make([]*types.Receipt, transactionsCount), @@ -73,9 +74,9 @@ func CreateBlock(t *testing.T) *types.FullBlock { } } - for i := 0; i < len(b.Block.Transactions); i++ { - b.Receipts[i] = &types.Receipt{ - TxHash: b.Block.Transactions[i].Hash(), + for i := 0; i < len(fb.Block.Transactions); i++ { + fb.Receipts[i] = &types.Receipt{ + TxHash: fb.Block.Transactions[i].Hash(), Root: types.StringToHash("mockhashstring"), TransactionType: types.LegacyTxType, GasUsed: uint64(100000), @@ -87,51 +88,106 @@ func CreateBlock(t *testing.T) *types.FullBlock { } for i := 0; i < 5; i++ { - b.Receipts[i].LogsBloom = types.CreateBloom(b.Receipts) + fb.Receipts[i].LogsBloom = types.CreateBloom(fb.Receipts) } - return b + return fb } -func UpdateBlock(t *testing.T, num uint64, b *types.FullBlock) *types.FullBlock { - t.Helper() +func updateBlock(b *testing.B, num uint64, fb *types.FullBlock) *types.FullBlock { + b.Helper() var addr types.Address - b.Block.Header.Number = num - b.Block.Header.ParentHash = types.StringToHash(randStringBytes(t, 12)) + fb.Block.Header.Number = num + fb.Block.Header.ParentHash = types.StringToHash(randStringBytes(b, 12)) - for i := range b.Block.Transactions { - addr = types.StringToAddress(randStringBytes(t, 8)) - b.Block.Transactions[i].SetTo(&addr) - b.Block.Transactions[i].ComputeHash() - b.Receipts[i].TxHash = b.Block.Transactions[i].Hash() + for i := range fb.Block.Transactions { + addr = types.StringToAddress(randStringBytes(b, 8)) + fb.Block.Transactions[i].SetTo(&addr) + fb.Block.Transactions[i].ComputeHash() + fb.Receipts[i].TxHash = fb.Block.Transactions[i].Hash() } - b.Block.Header.ComputeHash() + fb.Block.Header.ComputeHash() - return b + return fb } -func PrepareBatch(t *testing.T, s *Storage, b *types.FullBlock) *Writer { - t.Helper() +func prepareBatch(b *testing.B, s *Storage, fb *types.FullBlock) *Writer { + b.Helper() batchWriter := s.NewWriter() // Lookup 'sorted' - batchWriter.PutHeadHash(b.Block.Header.Hash) - batchWriter.PutHeadNumber(b.Block.Number()) - batchWriter.PutBlockLookup(b.Block.Hash(), b.Block.Number()) + batchWriter.PutHeadHash(fb.Block.Header.Hash) + batchWriter.PutHeadNumber(fb.Block.Number()) + batchWriter.PutBlockLookup(fb.Block.Hash(), fb.Block.Number()) - for _, tx := range b.Block.Transactions { - batchWriter.PutTxLookup(tx.Hash(), b.Block.Number()) + for _, tx := range fb.Block.Transactions { + batchWriter.PutTxLookup(tx.Hash(), fb.Block.Number()) } // Main DB sorted - batchWriter.PutBody(b.Block.Number(), b.Block.Hash(), b.Block.Body()) - batchWriter.PutCanonicalHash(b.Block.Number(), b.Block.Hash()) - batchWriter.PutHeader(b.Block.Header) - batchWriter.PutReceipts(b.Block.Number(), b.Block.Hash(), b.Receipts) + batchWriter.PutBody(fb.Block.Number(), fb.Block.Hash(), fb.Block.Body()) + batchWriter.PutCanonicalHash(fb.Block.Number(), fb.Block.Hash()) + batchWriter.PutHeader(fb.Block.Header) + batchWriter.PutReceipts(fb.Block.Number(), fb.Block.Hash(), fb.Receipts) return batchWriter } + +func testWriteBlockPerf(b *testing.B, blockCount int, s *Storage, time float64) { + b.Helper() + fb := createBlock(b) + + for i := 1; i <= blockCount; i++ { + updateBlock(b, uint64(i), fb) + + b.StartTimer() + batchWriter := prepareBatch(b, s, fb) + require.NoError(b, batchWriter.WriteBatch()) + b.StopTimer() + } + + b.Logf("\ttotal write time %f s", b.Elapsed().Seconds()) + require.LessOrEqual(b, b.Elapsed().Seconds(), time) +} + +func testReadBlockPerf(b *testing.B, blockCount int, s *Storage, time float64) { + b.Helper() + + for i := 1; i <= blockCount; i++ { + n := uint64(1 + mathRand.Intn(blockCount)) //nolint:gosec + + b.StartTimer() + + h, ok := s.ReadCanonicalHash(n) + _, err1 := s.ReadBody(n, h) + _, err3 := s.ReadHeader(n, h) + _, err4 := s.ReadReceipts(n, h) + bn, err5 := s.ReadBlockLookup(h) + + b.StopTimer() + + if !ok || err1 != nil || err3 != nil || err4 != nil || err5 != nil { + b.Logf("\terror") + } + + require.Equal(b, n, bn) + } + + b.Logf("\ttotal read time %f s", b.Elapsed().Seconds()) + require.LessOrEqual(b, b.Elapsed().Seconds(), time) +} + +func BenchmarkStorage(t *testing.B, blockCount int, s *Storage, writeTime float64, readTime float64) { + t.Helper() + + t.Run("testWriteBlockPerf", func(t *testing.B) { + testWriteBlockPerf(t, blockCount, s, writeTime) + }) + t.Run("testReadBlockPerf", func(t *testing.B) { + testReadBlockPerf(t, blockCount, s, readTime) + }) +} From 0e50904a0513b36c32fd2464b974ce259dbb8a54 Mon Sep 17 00:00:00 2001 From: Oliver Bundalo Date: Fri, 5 Apr 2024 15:08:12 +0200 Subject: [PATCH 2/2] Fix for CI benchmark times --- blockchain/storagev2/leveldb/leveldb_perf_test.go | 2 +- blockchain/storagev2/mdbx/mdbx_perf_test.go | 2 +- blockchain/storagev2/memory/memory_test.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/blockchain/storagev2/leveldb/leveldb_perf_test.go b/blockchain/storagev2/leveldb/leveldb_perf_test.go index 8f16a2d546..b8a23e411e 100644 --- a/blockchain/storagev2/leveldb/leveldb_perf_test.go +++ b/blockchain/storagev2/leveldb/leveldb_perf_test.go @@ -39,7 +39,7 @@ func Benchmark(b *testing.B) { }() blockCount := 1000 - storagev2.BenchmarkStorage(b, blockCount, s, 47, 33) // CI times + storagev2.BenchmarkStorage(b, blockCount, s, 25, 15) // CI times size, err := dbSize(path) require.NoError(b, err) diff --git a/blockchain/storagev2/mdbx/mdbx_perf_test.go b/blockchain/storagev2/mdbx/mdbx_perf_test.go index 642be6f5cd..8d0d972d25 100644 --- a/blockchain/storagev2/mdbx/mdbx_perf_test.go +++ b/blockchain/storagev2/mdbx/mdbx_perf_test.go @@ -38,7 +38,7 @@ func Benchmark(b *testing.B) { }() blockCount := 1000 - storagev2.BenchmarkStorage(b, blockCount, s, 75, 65) // CI times + storagev2.BenchmarkStorage(b, blockCount, s, 40, 18) // CI times size, err := dbSize(path) require.NoError(b, err) diff --git a/blockchain/storagev2/memory/memory_test.go b/blockchain/storagev2/memory/memory_test.go index f3ef02d618..024b1888bd 100644 --- a/blockchain/storagev2/memory/memory_test.go +++ b/blockchain/storagev2/memory/memory_test.go @@ -9,7 +9,7 @@ import ( func TestStorage(t *testing.T) { t.Helper() - f := func(t *testing.T) (*storagev2.Storage, func()) { + f := func(t *testing.T) (*storagev2.Storage, func(), string) { t.Helper() s, err := NewMemoryStorage() @@ -17,10 +17,10 @@ func TestStorage(t *testing.T) { if err != nil { t.Logf("\t Error opening MemoryDB -> %s", err.Error()) - return nil, func() {} + return nil, func() {}, "" } - return s, func() {} + return s, func() {}, "" } storagev2.TestStorage(t, f) }