Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add degradation tests into CI #1331

Open
wants to merge 35 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1569672
init commit
AKorpusenko Feb 20, 2024
919fca8
added degradation tests and benching scripts
AKorpusenko Feb 28, 2024
9dc6356
Merge branch 'stage' of github.com:bloxapp/ssv into feat/add-degradat…
AKorpusenko Feb 28, 2024
a0841c3
added config for deltas secifying
AKorpusenko Feb 28, 2024
f951faa
minor fixes
AKorpusenko Feb 28, 2024
3b6366f
added workflow
AKorpusenko Feb 28, 2024
13cf9bc
workflow fix
AKorpusenko Feb 28, 2024
39b9793
added make to ci
AKorpusenko Feb 28, 2024
1a447fd
fixed makefile degradation-test
AKorpusenko Feb 28, 2024
6175cec
added logging the benchstat to workflow
AKorpusenko Feb 28, 2024
2ae158d
added benchstat
AKorpusenko Feb 28, 2024
b82fae5
added default behavior
AKorpusenko Feb 29, 2024
e527a78
added readme, minor changes, update benchmarks script
AKorpusenko Mar 1, 2024
c3c7aa8
Merge branch 'stage' of github.com:bloxapp/ssv into feat/add-degradat…
AKorpusenko Mar 11, 2024
2a8bf6a
minor pr review comments fixes
AKorpusenko Mar 11, 2024
49d6528
Merge branch 'feat/add-degradation-tests-into-ci' of github.com:bloxa…
AKorpusenko Mar 27, 2024
3081814
Merge branch 'stage' of github.com:bloxapp/ssv into feat/add-degradat…
AKorpusenko Mar 27, 2024
77f5b70
added -format csv to benchstat. added basic test
AKorpusenko Mar 27, 2024
60d5757
added manual button update the benchmarks
AKorpusenko Mar 28, 2024
22ec9e8
update workflows
AKorpusenko Mar 28, 2024
c81ae4e
added manual benchmarks update
AKorpusenko Mar 30, 2024
7a8c12d
added benchstat script some tests. Removed outdated code and improved…
AKorpusenko Mar 30, 2024
f31259b
updated README.md for degradation-tester
AKorpusenko Apr 1, 2024
03ed165
Merge branch 'stage' of github.com:bloxapp/ssv into feat/add-degradat…
AKorpusenko Apr 1, 2024
f9794d9
Merge branch 'stage' of github.com:bloxapp/ssv into feat/add-degradat…
AKorpusenko Apr 1, 2024
888a7f8
updated to support current op keys incapsulation
AKorpusenko Apr 1, 2024
1515b4d
Merge branch 'stage' of github.com:bloxapp/ssv into feat/add-degradat…
AKorpusenko Apr 3, 2024
2b5ec08
changed trigger of manual benchmarks updating
AKorpusenko Apr 3, 2024
b114c82
skip b/op section. changed default alloc/op thereshold
AKorpusenko Apr 4, 2024
895ab32
Merge branch 'stage' of github.com:bloxapp/ssv into feat/add-degradat…
AKorpusenko Apr 9, 2024
11cef51
added new benchmarking tests
AKorpusenko Apr 9, 2024
f352802
updated message validation benchmark
AKorpusenko Apr 9, 2024
2f6b37f
updated benchmarks
AKorpusenko Apr 10, 2024
b822d9c
fixed degradation test script
AKorpusenko Apr 11, 2024
14b6064
added compact mode
AKorpusenko Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/degradation-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Benchmarks Degradation Test

on:
push:
branches:
- "**"

jobs:
performance-degradation-check:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Setup make
run: sudo apt-get update && sudo apt-get install make

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20.x"

- name: Tidy up dependencies
run: go mod tidy

- name: Install yq
run: sudo snap install yq

- name: Install benchstat
run: go install golang.org/x/perf/cmd/benchstat@latest

- name: Build degradation tester tool
run: |
cd ./scripts/degradation-tester
go install .

- name: Run degradation-test
run: |
make degradation-test
env:
GO111MODULE: on
37 changes: 37 additions & 0 deletions .github/workflows/manual-benchmarks-update-.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Manual Benchmarks Update

on: workflow_dispatch

jobs:
optional-benchmark-update:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # Ensures the PR's head is checked out

- name: Setup make
run: sudo apt-get update && sudo apt-get install make

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20.x"

- name: Tidy up dependencies
run: go mod tidy

- name: Update benchmarks
if: github.event_name == 'workflow_dispatch'
run: make update-benchmarks

- name: Update repo
uses: EndBug/[email protected]
with:
# limit the scope of the commit with the benchmarks dir path only
add: "scripts/degradation-tester/benchmarks"
default_author: github_actor
pathspec_error_handling: exitImmediately
message: "benchmarks updated"

10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ unit-test:
@echo "Running unit tests"
@go test -tags blst_enabled -timeout 20m -race -covermode=atomic -coverprofile=coverage.out -p 1 `go list ./... | grep -ve "spectest\|integration\|ssv/scripts/"`

.PHONY: degradation-test
degradation-test:
@echo "Running degradation tests"
@bash ./scripts/degradation-tester/degradation-check.sh

.PHONY: update-benchmarks
update-benchmarks:
@echo "Updating benchmarks"
@bash ./scripts/degradation-tester/update-benchmarks.sh

.PHONY: spec-test
spec-test:
@echo "Running spec tests"
Expand Down
113 changes: 113 additions & 0 deletions message/validation/rsa_benchmark_test.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test/benchmark needs to be updated after #1274 and #1358

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package validation

import (
eth2apiv1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/bloxapp/ssv/networkconfig"
"github.com/bloxapp/ssv/operator/keys"
"github.com/bloxapp/ssv/operator/storage"
beaconprotocol "github.com/bloxapp/ssv/protocol/v2/blockchain/beacon"
ssvtypes "github.com/bloxapp/ssv/protocol/v2/types"
"github.com/bloxapp/ssv/storage/basedb"
"github.com/bloxapp/ssv/storage/kv"
"go.uber.org/zap/zaptest"
"testing"

specqbft "github.com/bloxapp/ssv-spec/qbft"
spectypes "github.com/bloxapp/ssv-spec/types"
spectestingutils "github.com/bloxapp/ssv-spec/types/testingutils"
"github.com/bloxapp/ssv/network/commons"
registrystorage "github.com/bloxapp/ssv/registry/storage"
"github.com/ethereum/go-ethereum/common"
pubsub "github.com/libp2p/go-libp2p-pubsub"
pspb "github.com/libp2p/go-libp2p-pubsub/pb"
"github.com/stretchr/testify/require"
)

func BenchmarkVerifyRSASignature(b *testing.B) {
logger := zaptest.NewLogger(b)
db, err := kv.NewInMemory(logger, basedb.Options{})
require.NoError(b, err)

ns, err := storage.NewNodeStorage(logger, db)
require.NoError(b, err)

const validatorIndex = 123
const operatorID = spectypes.OperatorID(1)

ks := spectestingutils.Testing4SharesSet()
share := &ssvtypes.SSVShare{
Share: *spectestingutils.TestingShare(ks),
Metadata: ssvtypes.Metadata{
BeaconMetadata: &beaconprotocol.ValidatorMetadata{
Status: eth2apiv1.ValidatorStateActiveOngoing,
Index: validatorIndex,
},
Liquidated: false,
},
}
err = ns.Shares().Save(nil, share)
require.NoError(b, err)

netCfg := networkconfig.TestNetwork

roleAttester := spectypes.BNRoleAttester

slot := netCfg.Beacon.FirstSlotAtEpoch(123456789)

validSignedMessage := spectestingutils.TestingProposalMessageWithHeight(ks.Shares[1], 1, specqbft.Height(slot))

encoded, err := validSignedMessage.Encode()
require.NoError(b, err)

message := &spectypes.SSVMessage{
MsgType: spectypes.SSVConsensusMsgType,
MsgID: spectypes.NewMsgID(netCfg.Domain, share.ValidatorPubKey, roleAttester),
Data: encoded,
}

encodedMsg, err := commons.EncodeNetworkMsg(message)
require.NoError(b, err)

privKey, err := keys.GeneratePrivateKey()
require.NoError(b, err)

pubKey, err := privKey.Public().Base64()
require.NoError(b, err)

od := &registrystorage.OperatorData{
ID: operatorID,
PublicKey: pubKey,
OwnerAddress: common.Address{},
}

found, err := ns.SaveOperatorData(nil, od)
require.NoError(b, err)
require.False(b, found)

signature, err := privKey.Sign(encodedMsg)
require.NoError(b, err)

encodedMsg = commons.EncodeSignedSSVMessage(encodedMsg, operatorID, signature)

topicID := commons.ValidatorTopicID(message.GetID().GetPubKey())
pMsg := &pubsub.Message{
Message: &pspb.Message{
Topic: &topicID[0],
Data: encodedMsg,
},
}

mv := NewMessageValidator(netCfg, WithNodeStorage(ns)).(*messageValidator)

messageData := pMsg.GetData()
decMessageData, operatorIDX, signature, err := commons.DecodeSignedSSVMessage(messageData)
require.NoError(b, err)

messageData = decMessageData

b.ResetTimer()
for i := 0; i < b.N; i++ {
err := mv.verifySignature(messageData, operatorIDX, signature)
require.NoError(b, err)
}
}
91 changes: 91 additions & 0 deletions scripts/degradation-tester/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Degradation Tester

### Continuous Benchmarking

Degradation Tester is a tool for detecting performance degradation. It allows to compare current benchmark results against previous ones to identify potential performance issues.
It's important to use the same environment and CPU for testing. We use the Github Actions workflow for the benchmarks, which currently uses the `AMD EPYC 7763 64-Core Processor`.

### Approving Performance Changes

If you've made changes that affect performance, whether they are improvements or degradations, it's essential to regenerate the benchmarks and replace the existing files in the `benchmarks` directory. This ensures that future comparisons accurately reflect the impact of your changes and maintains the integrity of the performance testing process.

To regenerate and update the benchmarks, use the `update-benchmarks` command in the Makefile. To update the benchmarks in the repo using Github Actions, you should use the manually triggered workflow for your Pull Request named **Manual Benchmarks Update**.

To run the workflow:
- Open the PR
- Go to Actions
- Choose `Manual Benchmarks Update` from the list of available actions
- Click `Run workflow` and choose your branch from the dropdown menu

The workflow is located in `.github/workflows/manual-benchmarks-update-.yml`.

## Configuration

To use the tool, you need to set up a YAML configuration file. Here is an example configuration:

```yaml
DefaultOpDelta: 4.0
DefaultAllocDelta: 0
Packages:
- Path: "./message/validation"
Tests:
- Name: "VerifyRSASignature"
OpDelta: 3.0
- Path: "./protocol/v2/types"
Tests:
- Name: "VerifyBLS"
OpDelta: 6.0
- Name: "VerifyPKCS1v15"
OpDelta: 4.0
- Name: "VerifyPKCS1v15FastHash"
OpDelta: 6.0
- Name: "VerifyPSS"
OpDelta: 5.0
```

- `DefaultOpDelta` and `DefaultAllocDelta` specify the default performance change thresholds (in percentages) that are allowed for all tests unless specific values are provided.
- `Path` refers to the directory containing the tests.
- `Tests` is a list of tests with names and permissible performance change thresholds.

## Local Usage

### Dependecies

- `yq`
- `benchstat`

### Installation

Install the benchmarks degradation checker tool:

`cd scripts/degradation-tester/ && go install .`

### Running Degradation Tests

To run the degradation tests, execute:

```bash
make degradation-test
```

### Updating Benchmarks

To replace the benchmarks with your local ones, execute:

```bash
make update-benchmarks
```

## Usage with GitHub Actions

`.github/workflows/degradation-test.yml` containing a workflow for automatically running degradation tests as part of the CI/CD process

`.github/workflows/manual-benchmarks-update-.yml`. containing a workflow for updating the benchmarks with manual triggering

## Scripts

The `./scripts/degradation-tester` directory contains the following scripts:

- `degradation-check.sh` - running degradation tests. Runs benchmarks, saves the new results, compares benchmarking results per all listed packages in `config.yaml`

- `update-benchmarks.sh` - A script for updating benchmarks
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
goos: linux
goarch: amd64
pkg: github.com/bloxapp/ssv/message/validation
cpu: AMD EPYC 7763 64-Core Processor
BenchmarkVerifyRSASignature-4 4729 256788 ns/op 1364 B/op 7 allocs/op
BenchmarkVerifyRSASignature-4 4712 254533 ns/op 1469 B/op 8 allocs/op
BenchmarkVerifyRSASignature-4 4722 254782 ns/op 1577 B/op 8 allocs/op
BenchmarkVerifyRSASignature-4 4735 255405 ns/op 1685 B/op 9 allocs/op
BenchmarkVerifyRSASignature-4 4573 258438 ns/op 1804 B/op 9 allocs/op
BenchmarkVerifyRSASignature-4 4694 265556 ns/op 1940 B/op 10 allocs/op
BenchmarkVerifyRSASignature-4 4491 259423 ns/op 2034 B/op 10 allocs/op
BenchmarkVerifyRSASignature-4 4677 255195 ns/op 2129 B/op 10 allocs/op
BenchmarkVerifyRSASignature-4 4364 256322 ns/op 2246 B/op 11 allocs/op
BenchmarkVerifyRSASignature-4 4694 255884 ns/op 2350 B/op 11 allocs/op
PASS
ok github.com/bloxapp/ssv/message/validation 35.074s
Loading
Loading