prysm-pulse/slasher/db/kv/benchmark_test.go
Ivan Martinez ec6309a928
Cleanup flat spans implementation (#6150)
* Flat spanner improvements

* Fix tests, add more to ES type

* Move types to detection/types

* Fix

* Fix comments

* Fixes

* Use SlotTickerWithOffset for StreamIndexedAttestations (#5999)

* Change streamindexed to slot ticker with offset
* Make 2/3rds
* Add test
* Merge branch 'master' of github.com:prysmaticlabs/prysm into ticker-offset
* Add check for offset
* Merge branch 'master' of github.com:prysmaticlabs/prysm into ticker-offset
* Fix test
* Merge refs/heads/master into ticker-offset

* Fix long running E2E after v0.12 changes (#6008)

* Fix deposits in long run e2e

* Fix participation

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>

* Small fixes for slasher  (#6021)

* Small fixes for slasher

* Remove useless log

* Fix test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>

* Add voluntary exit processing to E2E (#6016)

* Add voluntary exit to E2E

* Fix long urnning e2e

* Fix for comments

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>

* Change slashing pool to use spec code  (#6030)

* Change slashing pool to use more spec code

* Fix test

* Undo unneeded changes

* Make sure to catch regression

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>

* Fix long-running E2E (#6047)

* Fixes for long running E2E
* Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-e2e
* Move metrics check up
* Merge refs/heads/master into fix-e2e

* E2E Improvements (#6091)

* Some fixes
* Merge branch 'master' into e2e-fixes
* Add another small delay
* Merge branch 'e2e-fixes' of github.com:prysmaticlabs/prysm into e2e-fixes
* Remove genesis test, make normal e2e run longer
* Gaz
* more fixes
* Merge branch 'master' into e2e-fixes
* Merge refs/heads/master into e2e-fixes
* Fix comment
* Merge refs/heads/master into e2e-fixes

* Begin changing tests

* Start work on tests

* Redo tests for EpochStore

* Add test for highest index

* Fixes

* Gaz

* Fix

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-06-11 14:17:44 -04:00

129 lines
3.5 KiB
Go

package kv
import (
"context"
"flag"
"testing"
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
"github.com/urfave/cli/v2"
)
const (
benchmarkValidator = 300000
)
func BenchmarkStore_SaveEpochSpans(b *testing.B) {
ctx := context.Background()
sigBytes := [2]byte{}
app := cli.App{}
set := flag.NewFlagSet("test", 0)
db := setupDB(b, cli.NewContext(&app, set, nil))
es := &types.EpochStore{}
es, err := es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := db.SaveEpochSpans(ctx, uint64(i%54000), es)
if err != nil {
b.Fatalf("Save validator span map failed: %v", err)
}
}
}
func BenchmarkStore_EpochSpans(b *testing.B) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
db := setupDB(b, cli.NewContext(&app, set, nil))
ctx := context.Background()
sigBytes := [2]byte{}
es := &types.EpochStore{}
es, err := es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
}
b.Log(len(es.Bytes()))
for i := 0; i < 200; i++ {
err := db.SaveEpochSpans(ctx, uint64(i), es)
if err != nil {
b.Fatalf("Save validator span map failed: %v", err)
}
}
b.Log(db.db.Info())
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := db.EpochSpans(ctx, uint64(i%200))
if err != nil {
b.Fatalf("Read validator span map failed: %v", err)
}
}
}
func BenchmarkStore_GetValidatorSpan(b *testing.B) {
sigBytes := [2]byte{}
es := &types.EpochStore{}
es, err := es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: uint16(i), MaxSpan: uint16(benchmarkValidator - i), SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
}
b.Log(len(es.Bytes()))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := es.GetValidatorSpan(uint64(i % benchmarkValidator))
if err != nil {
b.Fatalf("Read validator span map failed: %v", err)
}
}
}
func BenchmarkStore_SetValidatorSpan(b *testing.B) {
sigBytes := [2]byte{}
var err error
es := &types.EpochStore{}
es, err = es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: uint16(i), MaxSpan: uint16(benchmarkValidator - i), SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Error(err)
}
}
b.Log(len(es.Bytes()))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
es, err = es.SetValidatorSpan(uint64(i%benchmarkValidator), types.Span{MinSpan: uint16(i), MaxSpan: uint16(benchmarkValidator - i), SigBytes: sigBytes, HasAttested: true})
if err != nil {
b.Fatalf("Read validator span map failed: %v", err)
}
}
}