-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1579 from anyproto/go-3985-make-performance-repor…
…t-on-the-stand GO-3985 Try to add perf tests
- Loading branch information
Showing
7 changed files
with
788 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(¤tOperation, 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() | ||
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, ¤tOperation, 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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
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(¤tOperation, 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, ¤tOperation, 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} | ||
} |
Oops, something went wrong.