Skip to content

Commit

Permalink
Merge pull request #1579 from anyproto/go-3985-make-performance-repor…
Browse files Browse the repository at this point in the history
…t-on-the-stand

GO-3985 Try to add perf tests
  • Loading branch information
fat-fellow authored Sep 24, 2024
2 parents 5025c5d + 0027fb5 commit eead3e2
Show file tree
Hide file tree
Showing 7 changed files with 788 additions and 20 deletions.
30 changes: 30 additions & 0 deletions .github/staging_fake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
networkId: N9DU6hLkTAbvcpji3TCKPPd3UQWKGyzUxGmgJEyvhByqAjfD
nodes:
- peerId: FAKE_PEER_ID1
addresses:
- lol1-any-sync-node1.somefakesite.com:6666
- lol1-any-sync-node1.somefakesite.com:6667
- quic://lol1.somefakesite.com:8888
types:
- tree
- peerId: FAKE_PEER_ID2
addresses:
- lol1-file13.somefakesite.com:6666
- lol1-file13.somefakesite.com:6667
- quic://lol1-file13.somefakesite.com:8888
types:
- file
- peerId: FAKE_PEER_ID3
addresses:
- lol1-coord1.somefakesite.com:6666
- lol1-coord1.somefakesite.com:6667
- quic://lol1-coord1.somefakesite.com:8888
types:
- coordinator
- peerId: FAKE_PEER_ID4
addresses:
- lol1-cons1.somefakesite.com:6666
- lol1-cons1.somefakesite.com:6667
- quic://lol1-cons1.somefakesite.com:8888
types:
- consensus
37 changes: 19 additions & 18 deletions .github/workflows/perftests.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#https://linear.app/anytype/issue/GO-3985/make-performance-report-on-the-stand
on:
workflow_dispatch:
inputs:
Expand All @@ -8,7 +9,7 @@ on:
perf-test:
description: 'Run perf test times'
required: true
default: '0'
default: '100'
schedule:
- cron: '0 0 * * *' # every day at midnight
filters:
Expand All @@ -22,7 +23,7 @@ permissions:
contents: 'write'


name: Build
name: Perf tests
jobs:
build:
runs-on: 'ARM64'
Expand All @@ -35,13 +36,6 @@ jobs:
echo $(go env GOPATH)/bin >> $GITHUB_PATH
- name: Checkout
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Set env vars
env:
UNSPLASH_KEY: ${{ secrets.UNSPLASH_KEY }}
Expand Down Expand Up @@ -83,19 +77,26 @@ jobs:
if [[ "${{ github.event_name }}" == "schedule" ]]; then
RUN_COUNT=100
fi
echo $PERF_CONFIG_STAGING > config.json
mv .github/staging_fake.yml staging_fake.yml
PERF_CONFIG=$PWD/config.json
cd cmd/perfstand/account_create
CGO_ENABLED="1" go run main.go $PERF_CONFIG $RUN_COUNT
cd ../account_select
CGO_ENABLED="1" go run main.go $PERF_CONFIG $RUN_COUNT
cd ../../..
echo $PERF_CONFIG_LOCAL > ./config.json
cd cmd/perfstand/account_create
CGO_ENABLED="1" go run main.go $RUN_COUNT
CGO_ENABLED="1" go run main.go $PERF_CONFIG $RUN_COUNT
cd ../account_select
CGO_ENABLED="1" go run main.go $RUN_COUNT
CGO_ENABLED="1" go run main.go $PERF_CONFIG $RUN_COUNT
env:
TEST_MNEMONIC: ${{ secrets.TEST_MNEMONIC_30000 }}
CH_API_KEY: ${{ secrets.CH_API_KEY }}
ACCOUNT_HASH: ${{ secrets.ACCOUNT_HASH_30000 }}
ACCOUNT_SPACE: ${{ secrets.ACCOUNT_SPACE_30000 }}
ROOT_FOLDER: ${{ secrets.ROOT_FOLDER }}
PERF_CONFIG_STAGING: ${{ secrets.PERF_CONFIG_STAGING }}
PERF_CONFIG_LOCAL: ${{ secrets.PERF_CONFIG_LOCAL }}
CH_API_KEY: ${{ secrets.CH_PERF_API_KEY }}
- name: Archive perf tests results
uses: actions/upload-artifact@v4
with:
name: pprofs
name: traces
path: |
*.pprof
*.log
14 changes: 13 additions & 1 deletion .run/Run.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@
<configuration default="false" name="Run" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="anytype-heart" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-tags &quot;nomutexdeadlockdetector noauth nographviz&quot;" />
<go_parameters value="-tags &quot;nomutexdeadlockdetector noauth nographviz&quot; -ldflags=&quot;-extldflags=-Wl,-ld_classic&quot;" />
<envs>
<env name="ANYDEBUG" value=":6061" />
<env name="ANYPROF" value=":6060" />
<env name="ANYTYPE_GATEWAY_ADDR" value="127.0.0.1:31006" />
<env name="ANYTYPE_GRPC_ADDR" value="127.0.0.1:31007" />
<env name="ANYTYPE_GRPCWEB_ADDR" value="127.0.0.1:31008" />
<env name="CC" value="/usr/bin/cc" />
<env name="CXX" value="/usr/bin/c++" />
</envs>
<EXTENSION ID="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
<option name="IS_SUBST" value="false" />
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
<option name="IS_IGNORE_MISSING_FILES" value="false" />
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
</ENTRIES>
</EXTENSION>
<kind value="PACKAGE" />
<package value="github.com/anyproto/anytype-heart/cmd/grpcserver" />
<directory value="$PROJECT_DIR$" />
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ protos-java:
build-server: setup-network-config
@echo 'Building anytype-heart server...'
@$(eval FLAGS += $$(shell govvv -flags -pkg github.com/anyproto/anytype-heart/util/vcs))
@$(eval TAGS := nosigar nowatchdog)
@$(eval TAGS := $(TAGS) nosigar nowatchdog)
ifdef ANY_SYNC_NETWORK
@$(eval TAGS := $(TAGS) envnetworkcustom)
endif
Expand Down
110 changes: 110 additions & 0 deletions cmd/perfstand/account_create/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package main

import (
"encoding/json"
"fmt"
"os"
"os/exec"

"go.uber.org/atomic"

"github.com/anyproto/anytype-heart/cmd/perfstand/internal"
)

const AccountCreate = "AccountCreate"

type input struct {
*internal.BasicInput
}

type wallet struct {
Mnemonic string `json:"mnemonic"`
}

func NewInput() *input {
res := new(input)
res.BasicInput = new(internal.BasicInput)
return res
}

func NewResults(networkMode string) internal.PerfResult {
return internal.PerfResult{
AccountCreate: {MethodName: AccountCreate, NetworkMode: networkMode},
}
}

func main() {
prep := NewInput()
err := internal.Prepare(prep, nil)
if err != nil {
fmt.Println("Error preparing the environment:", err)
os.Exit(1)
}

res := NewResults(prep.NetworkMode)
for i := 0; i < prep.Times; i++ {
err = iterate(prep, res)
if err != nil {
fmt.Println("Error making iteration:", err)
os.Exit(1)
}
}
err = internal.After(res)
if err != nil {
fmt.Println("Error after the test:", err)
os.Exit(1)
}
}

func iterate(prep *input, result internal.PerfResult) error {
workspace, err := os.MkdirTemp("", "workspace")
prep.Workspace = workspace
if err != nil {
return err
}
defer os.RemoveAll(workspace)
fmt.Println("Created temporary directory:", workspace)

var currentOperation atomic.String
done := make(chan struct{})
wait := make(chan map[string][]byte)

err = internal.StartWithTracing(&currentOperation, done, wait)
if err != nil {
return err
}

err = internal.ExecuteCommand(internal.GrpcMetricsSetParameters())
if err != nil {
return err
}

walletStr, err := exec.Command("bash", "-c", internal.GrpcWalletCreate(workspace)).Output()

Check failure on line 82 in cmd/perfstand/account_create/main.go

View workflow job for this annotation

GitHub Actions / lint

G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)
if err != nil {
return err
}

var wallet wallet
err = json.Unmarshal(walletStr, &wallet)
if err != nil {
return err
}

grpcurlCommands := []internal.Command{
{internal.GrpcWalletCreateSession(wallet.Mnemonic), ""},
accountCreate(prep),
}

err = internal.CollectMeasurements(grpcurlCommands, &currentOperation, result, done, wait)
if err != nil {
return err
}
return nil
}

func accountCreate(prep *input) internal.Command {
if prep.NetworkMode != internal.NetworkLocal {
return internal.Command{Command: internal.GrpcAccountCreate(prep.Workspace, "2", prep.NodesConfig), Name: AccountCreate}
}
return internal.Command{Command: internal.GrpcAccountCreate(prep.Workspace, "1", ""), Name: AccountCreate}
}
103 changes: 103 additions & 0 deletions cmd/perfstand/account_select/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package main

import (
"fmt"
"os"
"path/filepath"

"go.uber.org/atomic"

"github.com/anyproto/anytype-heart/cmd/perfstand/internal"
)

const AccountSelect = "AccountSelect"
const WorkspaceOpen = "WorkspaceOpen"
const WorkspaceCreate = "WorkspaceCreate"

type input struct {
*internal.BasicInput
RootPath string `json:"root_path"`
AccHash string `json:"acc_hash"`
Mnemonic string `json:"mnemonic"`
Space string `json:"space"`
}

func NewInput() *input {
res := new(input)
res.BasicInput = new(internal.BasicInput)
return res
}

func NewResults(networkMode string) internal.PerfResult {
return internal.PerfResult{
AccountSelect: {MethodName: AccountSelect, NetworkMode: networkMode},
WorkspaceOpen: {MethodName: WorkspaceOpen, NetworkMode: networkMode},
WorkspaceCreate: {MethodName: WorkspaceCreate, NetworkMode: networkMode},
}
}

func main() {
prep := NewInput()
err := internal.Prepare(prep, extractAcc)
if err != nil {
fmt.Println("Error preparing the environment:", err)
os.Exit(1)
}
defer os.RemoveAll(prep.Workspace)

res := NewResults(prep.NetworkMode)
for i := 0; i < prep.Times; i++ {
err = iterate(prep, res)
if err != nil {
fmt.Println("Error making iteration:", err)
os.Exit(1)

Check failure on line 53 in cmd/perfstand/account_select/main.go

View workflow job for this annotation

GitHub Actions / lint

exitAfterDefer: os.Exit will exit, and `defer os.RemoveAll(prep.Workspace)` will not run (gocritic)
}
}
err = internal.After(res)
if err != nil {
fmt.Println("Error after the test:", err)
os.Exit(1)
}
}

func extractAcc(input *input) error {
err := internal.UnpackZip(filepath.Join(input.RootPath, input.AccHash+".zip"), input.Workspace)
if err != nil {
return err
}
fmt.Println("Unpacked files to:", input.Workspace)
return nil
}

func iterate(prep *input, result internal.PerfResult) error {
var currentOperation atomic.String
done := make(chan struct{})
wait := make(chan map[string][]byte)

err := internal.StartWithTracing(&currentOperation, done, wait)
if err != nil {
return err
}

grpcurlCommands := []internal.Command{
{internal.GrpcMetricsSetParameters(), ""},
{internal.GrpcWalletRecover(prep.Workspace, prep.Mnemonic), ""},
{internal.GrpcWalletCreateSession(prep.Mnemonic), ""},
accountSelect(prep),
{internal.GrpcWorkspaceOpen(prep.Space), WorkspaceOpen},
{internal.GrpcWorkspaceCreate(), WorkspaceCreate},
}

err = internal.CollectMeasurements(grpcurlCommands, &currentOperation, result, done, wait)
if err != nil {
return err
}
return nil
}

func accountSelect(prep *input) internal.Command {
if prep.NetworkMode != internal.NetworkLocal {
return internal.Command{Command: internal.GrpcAccountSelect(prep.AccHash, prep.Workspace, "2", prep.NodesConfig), Name: AccountSelect}
}
return internal.Command{Command: internal.GrpcAccountSelect(prep.AccHash, prep.Workspace, "1", ""), Name: AccountSelect}
}
Loading

0 comments on commit eead3e2

Please sign in to comment.