mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-21 06:36:19 +00:00
* test: add the loadtime report tool (#9351)
This pull request adds the report tool and modifies the loadtime libraries to better support its use.
(cherry picked from commit 8655080a0f)
* add nolint
Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
Co-authored-by: William Banfield <wbanfield@gmail.com>
This commit is contained in:
co-authored by
William Banfield
William Banfield
parent
f573d3d2a6
commit
71a8fcfb16
@@ -0,0 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/informalsystems/tm-load-test/pkg/loadtest"
|
||||
"github.com/tendermint/tendermint/test/loadtime/payload"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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.MaxUnpaddedSize()
|
||||
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) {
|
||||
return &TxGenerator{
|
||||
conns: uint64(cfg.Connections),
|
||||
rate: uint64(cfg.Rate),
|
||||
size: uint64(cfg.Size),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *TxGenerator) GenerateTx() ([]byte, error) {
|
||||
return payload.NewBytes(&payload.Payload{
|
||||
Connections: c.conns,
|
||||
Rate: c.rate,
|
||||
Size: c.size,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/store"
|
||||
"github.com/tendermint/tendermint/test/loadtime/report"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
)
|
||||
|
||||
var (
|
||||
db = flag.String("database-type", "goleveldb", "the type of database holding the blockstore")
|
||||
dir = flag.String("data-dir", "", "path to the directory containing the tendermint databases")
|
||||
csvOut = flag.String("csv", "", "dump the extracted latencies as raw csv for use in additional tooling")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *db == "" {
|
||||
log.Fatalf("must specify a database-type")
|
||||
}
|
||||
if *dir == "" {
|
||||
log.Fatalf("must specify a data-dir")
|
||||
}
|
||||
d := strings.TrimPrefix(*dir, "~/")
|
||||
if d != *dir {
|
||||
h, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = h + "/" + d
|
||||
}
|
||||
_, err := os.Stat(d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dbType := dbm.BackendType(*db)
|
||||
db, err := dbm.NewDB("blockstore", dbType, d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s := store.NewBlockStore(db)
|
||||
defer s.Close()
|
||||
r, err := report.GenerateFromBlockStore(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if *csvOut != "" {
|
||||
cf, err := os.Create(*csvOut)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w := csv.NewWriter(cf)
|
||||
err = w.WriteAll(toRecords(r.All))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf(""+
|
||||
"Total Valid Tx: %d\n"+
|
||||
"Total Invalid Tx: %d\n"+
|
||||
"Total Negative Latencies: %d\n"+
|
||||
"Minimum Latency: %s\n"+
|
||||
"Maximum Latency: %s\n"+
|
||||
"Average Latency: %s\n"+
|
||||
"Standard Deviation: %s\n", len(r.All), r.ErrorCount, r.NegativeCount, r.Min, r.Max, r.Avg, r.StdDev)
|
||||
}
|
||||
|
||||
func toRecords(l []time.Duration) [][]string {
|
||||
res := make([][]string, len(l)+1)
|
||||
|
||||
res[0] = make([]string, 1)
|
||||
res[0][0] = "duration_ns"
|
||||
for i, v := range l {
|
||||
res[1+i] = []string{strconv.FormatInt(int64(v), 10)}
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user