Skip to content

Commit

Permalink
Remove stopwatch dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbundalo committed Feb 26, 2024
1 parent 428f425 commit 8609468
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 54 deletions.
20 changes: 8 additions & 12 deletions blockchain/storage/leveldb/leveldb_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/0xPolygon/polygon-edge/blockchain"
"github.com/0xPolygon/polygon-edge/blockchain/storage"
"github.com/0xPolygon/polygon-edge/types"
"github.com/bradhe/stopwatch"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -156,9 +155,6 @@ func updateBlock(t *testing.T, num uint64, b *types.FullBlock) *types.FullBlock
b.Block.Transactions[i].ComputeHash()
b.Receipts[i].TxHash = b.Block.Transactions[i].Hash()
}
// big := new(big.Int)
// big.SetInt64(int64(num))
// b.Block.Header.Hash = types.BytesToHash(big.Bytes())

b.Block.Header.ComputeHash()

Expand Down Expand Up @@ -193,7 +189,7 @@ func TestWriteBlockPerf(t *testing.T) {
s, _, path := openStorage(t, "/tmp/leveldbV1-test")
defer s.Close()

var watchTime int
var watchTime int64

count := 10000
b := createBlock(t)
Expand All @@ -202,14 +198,14 @@ func TestWriteBlockPerf(t *testing.T) {
updateBlock(t, uint64(i), b)
batchWriter := prepareBatch(t, s, b)

watch := stopwatch.Start()
tn := time.Now().UTC()

if err := batchWriter.WriteBatch(); err != nil {
require.NoError(t, err)
}

watch.Stop()
watchTime = watchTime + int(watch.Milliseconds())
d := time.Since(tn)
watchTime = watchTime + d.Milliseconds()
}

time.Sleep(time.Second)
Expand All @@ -225,20 +221,20 @@ func TestReadBlockPerf(t *testing.T) {
s, _, _ := openStorage(t, "/tmp/leveldbV1-test")
defer s.Close()

var watchTime int
var watchTime int64

count := 1000
for i := 1; i <= count; i++ {
n := uint64(1 + rand.Intn(10000))

watch := stopwatch.Start()
tn := time.Now().UTC()
h, ok := s.ReadCanonicalHash(n)
_, err2 := s.ReadBody(h)
_, err3 := s.ReadHeader(h)
_, err4 := s.ReadReceipts(h)
d := time.Since(tn)

watch.Stop()
watchTime = watchTime + int(watch.Milliseconds())
watchTime = watchTime + d.Milliseconds()

if !ok || err2 != nil || err3 != nil || err4 != nil {
t.Logf("\terror")
Expand Down
20 changes: 8 additions & 12 deletions blockchain/storagev2/leveldb/leveldb_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/0xPolygon/polygon-edge/blockchain"
"github.com/0xPolygon/polygon-edge/blockchain/storagev2"
"github.com/0xPolygon/polygon-edge/types"
"github.com/bradhe/stopwatch"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -157,9 +156,6 @@ func updateBlock(t *testing.T, num uint64, b *types.FullBlock) *types.FullBlock
b.Block.Transactions[i].ComputeHash()
b.Receipts[i].TxHash = b.Block.Transactions[i].Hash()
}
// big := new(big.Int)
// big.SetInt64(int64(num))
// b.Block.Header.Hash = types.BytesToHash(big.Bytes())

b.Block.Header.ComputeHash()

Expand Down Expand Up @@ -195,7 +191,7 @@ func TestWriteBlockPerf(t *testing.T) {
s, _, path := openStorage(t, "/tmp/leveldbV2-test")
defer s.Close()

var watchTime int
var watchTime int64

count := 10000
b := createBlock(t)
Expand All @@ -204,14 +200,14 @@ func TestWriteBlockPerf(t *testing.T) {
updateBlock(t, uint64(i), b)
batchWriter := prepareBatch(t, s, b)

watch := stopwatch.Start()
tn := time.Now().UTC()

if err := batchWriter.WriteBatch(); err != nil {
require.NoError(t, err)
}

watch.Stop()
watchTime = watchTime + int(watch.Milliseconds())
d := time.Since(tn)
watchTime = watchTime + d.Milliseconds()
}

time.Sleep(time.Second)
Expand All @@ -227,21 +223,21 @@ func TestReadBlockPerf(t *testing.T) {
s, _, _ := openStorage(t, "/tmp/leveldbV2-test")
defer s.Close()

var watchTime int
var watchTime int64

count := 1000
for i := 1; i <= count; i++ {
n := uint64(1 + rand.Intn(10000))

watch := stopwatch.Start()
tn := time.Now().UTC()
_, err1 := s.ReadBody(n)
h, ok := s.ReadCanonicalHash(n)
_, err3 := s.ReadHeader(n)
_, err4 := s.ReadReceipts(n)
b, err5 := s.ReadBlockLookup(h)
d := time.Since(tn)

watch.Stop()
watchTime = watchTime + int(watch.Milliseconds())
watchTime = watchTime + d.Milliseconds()

if err1 != nil || !ok || err3 != nil || err4 != nil || err5 != nil {
t.Logf("\terror")
Expand Down
16 changes: 1 addition & 15 deletions blockchain/storagev2/mdbx/mdbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,8 @@ import (
)

type MdbxOpts struct {
// must be in the range from 12.5% (almost empty) to 50% (half empty)
// which corresponds to the range from 8192 and to 32768 in units respectively

// log log.Logger
// roTxsLimiter *semaphore.Weighted
// bucketsCfg TableCfgFunc
path string
// syncPeriod time.Duration
// mapSize datasize.ByteSize
// growthStep datasize.ByteSize
// shrinkThreshold int
path string
flags uint
// pageSize uint64
// dirtySpace uint64 // if exeed this space, modified pages will `spill` to disk
// mergeThreshold uint64
// verbosity kv.DBVerbosityLvl
}

// MdbxDB is the mdbx implementation of the kv storage
Expand Down
20 changes: 8 additions & 12 deletions blockchain/storagev2/mdbx/mdbx_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/0xPolygon/polygon-edge/blockchain"
"github.com/0xPolygon/polygon-edge/blockchain/storagev2"
"github.com/0xPolygon/polygon-edge/types"
"github.com/bradhe/stopwatch"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -132,9 +131,6 @@ func updateBlock(t *testing.T, num uint64, b *types.FullBlock) *types.FullBlock
b.Block.Transactions[i].ComputeHash()
b.Receipts[i].TxHash = b.Block.Transactions[i].Hash()
}
// big := new(big.Int)
// big.SetInt64(int64(num))
// b.Block.Header.Hash = types.BytesToHash(big.Bytes())

b.Block.Header.ComputeHash()

Expand Down Expand Up @@ -170,7 +166,7 @@ func TestWriteBlockPerf(t *testing.T) {
s, _, path := openStorage(t, "/tmp/mdbx-test")
defer s.Close()

var watchTime int
var watchTime int64

count := 10000
b := createBlock(t)
Expand All @@ -179,14 +175,14 @@ func TestWriteBlockPerf(t *testing.T) {
updateBlock(t, uint64(i), b)
batchWriter := prepareBatch(t, s, b)

watch := stopwatch.Start()
tn := time.Now().UTC()

if err := batchWriter.WriteBatch(); err != nil {
require.NoError(t, err)
}

watch.Stop()
watchTime = watchTime + int(watch.Milliseconds())
d := time.Since(tn)
watchTime = watchTime + d.Milliseconds()
}

time.Sleep(time.Second)
Expand All @@ -202,21 +198,21 @@ func TestReadBlockPerf(t *testing.T) {
s, _, _ := openStorage(t, "/tmp/mdbx-test")
defer s.Close()

var watchTime int
var watchTime int64

count := 1000
for i := 1; i <= count; i++ {
n := uint64(1 + rand.Intn(10000))

watch := stopwatch.Start()
tn := time.Now().UTC()
_, err1 := s.ReadBody(n)
h, ok := s.ReadCanonicalHash(n)
_, err3 := s.ReadHeader(n)
_, err4 := s.ReadReceipts(n)
b, err5 := s.ReadBlockLookup(h)
d := time.Since(tn)

watch.Stop()
watchTime = watchTime + int(watch.Milliseconds())
watchTime = watchTime + d.Milliseconds()

if err1 != nil || !ok || err3 != nil || err4 != nil || err5 != nil {
t.Logf("\terror")
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/Ethernal-Tech/merkle-tree v0.0.0-20231213143318-4db9da419e04
github.com/armon/go-metrics v0.4.1
github.com/aws/aws-sdk-go v1.50.8
github.com/bradhe/stopwatch v0.0.0-20190618212248-a58cccc508ea
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/docker/docker v24.0.9+incompatible
github.com/docker/go-connections v0.5.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/bradhe/stopwatch v0.0.0-20190618212248-a58cccc508ea h1:+GIgqdjrcKMHK1JqC1Bb9arFtNOGX/SWCkueobreyQU=
github.com/bradhe/stopwatch v0.0.0-20190618212248-a58cccc508ea/go.mod h1:P/j2DSP/kCOakHBACzMqmOdrTEieqdSiB3U9fqk7qgc=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y=
Expand Down

0 comments on commit 8609468

Please sign in to comment.