Skip to content

Commit

Permalink
test: add the loadtime tool (Backport #9342) (#9358)
Browse files Browse the repository at this point in the history
* test: add the loadtime tool (#9342)

This pull request adds the loadtime tool. This tool leverages the tm-load-test framework. Using the framework means that the only real logic that needs to be written is the logic for Tx generation. The framework does the rest.

The tool writes a set of metadata into the transaction, including the current transaction rate, number of connections, specified size of the transaction, and the current time.

* lint

Co-authored-by: William Banfield <[email protected]>
  • Loading branch information
tnasu and williambanfield committed Jul 20, 2023
1 parent 00c3919 commit 5a07abd
Show file tree
Hide file tree
Showing 11 changed files with 879 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.d
profile\.out
test/app/grpc_client
test/loadtime/build
test/e2e/build
test/e2e/networks/*/
test/logs
test/maverick/maverick
test/p2p/data/
vendor
test/fuzz/**/corpus
test/fuzz/**/crashers
test/fuzz/**/suppressions
Expand Down
11 changes: 8 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/ory/dockertest v3.3.5+incompatible
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/rs/cors v1.9.0
github.com/sasha-s/go-deadlock v0.3.1
github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa
Expand Down Expand Up @@ -66,6 +66,11 @@ require (
github.com/Antonboom/errname v0.1.10 // indirect
github.com/Antonboom/nilnil v0.1.5 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/informalsystems/tm-load-test v1.0.0
google.golang.org/protobuf v1.31.0
)

require (
github.com/DataDog/zstd v1.4.1 // indirect
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.3.0 // indirect
Expand Down Expand Up @@ -190,7 +195,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mbilski/exhaustivestruct v1.2.0 // indirect
github.com/mgechev/revive v1.3.2 // indirect
github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
Expand Down Expand Up @@ -223,6 +228,7 @@ require (
github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
github.com/sashamelentyev/usestdlibvars v1.23.0 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/securego/gosec/v2 v2.16.0 // indirect
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
Expand Down Expand Up @@ -272,7 +278,6 @@ require (
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
honnef.co/go/tools v0.4.3 // indirect
Expand Down
483 changes: 479 additions & 4 deletions go.sum

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions test/loadtime/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
GOMOD="github.com/Finschia/ostracon/test/loadtime"
OUTPUT?=build/loadtime

build:
go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) .
.PHONY: build

check-proto-gen-deps:
ifeq (,$(shell which protoc))
$(error "protoc is required for Protobuf generation. See instructions for your platform on how to install it.")
endif
ifeq (,$(shell which protoc-gen-go))
$(error "protoc-gen-go is required for Protobuf generation. See instructions for your platform on how to install it.")
endif
.PHONY: check-proto-gen-deps

check-proto-format-deps:
ifeq (,$(shell which clang-format))
$(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.")
endif
.PHONY: check-proto-format-deps

proto-format: check-proto-format-deps
@echo "Formatting Protobuf files"
@find . -name '*.proto' -exec clang-format -i {} \;
.PHONY: proto-format

proto-gen: check-proto-gen-deps
@echo "Generating Protobuf files"
@find . -name '*.proto' -exec protoc \
--go_out=paths=source_relative:. {} \;
.PHONY: proto-gen
3 changes: 3 additions & 0 deletions test/loadtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# loadtime

Basically, see the [Tendermint v0.34 loadtime](https://github.com/tendermint/tendermint/blob/v0.34.x/test/loadtime/README.md).
11 changes: 11 additions & 0 deletions test/loadtime/basic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -euo pipefail

# A basic invocation of the loadtime tool.

./build/loadtime \
-c 1 -T 10 -r 1000 -s 1024 \
--broadcast-tx-method sync \
--endpoints ws://localhost:26657/websocket

89 changes: 89 additions & 0 deletions test/loadtime/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package main

import (
"crypto/rand"
"fmt"

"github.com/Finschia/ostracon/test/loadtime/payload"
"github.com/informalsystems/tm-load-test/pkg/loadtest"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)

// Ensure all of the interfaces are correctly satisfied.
var (
_ loadtest.ClientFactory = (*ClientFactory)(nil)
_ loadtest.Client = (*TxGenerator)(nil)
)

// ClientFactory implements the loadtest.ClientFactory interface.
type ClientFactory struct{}

// TxGenerator is responsible for generating transactions.
// TxGenerator holds the set of information that will be used to generate
// each transaction.
type TxGenerator struct {
conns uint64
rate uint64
size uint64
payloadSizeBytes uint64
}

func main() {
if err := loadtest.RegisterClientFactory("loadtime-client", &ClientFactory{}); err != nil {
panic(err)
}
loadtest.Run(&loadtest.CLIConfig{
AppName: "loadtime",
AppShortDesc: "Generate timestamped transaction load.",
AppLongDesc: "loadtime generates transaction load for the purpose of measuring the end-to-end latency of a transaction from submission to execution in a Tendermint network.", //nolint:lll
DefaultClientFactory: "loadtime-client",
})
}

func (f *ClientFactory) ValidateConfig(cfg loadtest.Config) error {
psb, err := payload.CalculateUnpaddedSizeBytes()
if err != nil {
return err
}

if psb > cfg.Size {
return fmt.Errorf("payload size exceeds configured size")
}
return nil
}

func (f *ClientFactory) NewClient(cfg loadtest.Config) (loadtest.Client, error) {
psb, err := payload.CalculateUnpaddedSizeBytes()
if err != nil {
return nil, err
}
return &TxGenerator{
conns: uint64(cfg.Connections),
rate: uint64(cfg.Rate),
size: uint64(cfg.Size),
payloadSizeBytes: uint64(psb),
}, nil
}

func (c *TxGenerator) GenerateTx() ([]byte, error) {
p := &payload.Payload{
Time: timestamppb.Now(),
Connections: c.conns,
Rate: c.rate,
Size: c.size,
Padding: make([]byte, c.size-c.payloadSizeBytes),
}
_, err := rand.Read(p.Padding)
if err != nil {
return nil, err
}
b, err := proto.Marshal(p)
if err != nil {
return nil, err
}

// prepend a single key so that the kv store only ever stores a single
// transaction instead of storing all tx and ballooning in size.
return append([]byte("a="), b...), nil
}
190 changes: 190 additions & 0 deletions test/loadtime/payload/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5a07abd

Please sign in to comment.