github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/test/loadtime/cmd/load/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/badrootd/nibiru-cometbft/test/loadtime/payload" 7 "github.com/google/uuid" 8 "github.com/informalsystems/tm-load-test/pkg/loadtest" 9 ) 10 11 // Ensure all of the interfaces are correctly satisfied. 12 var ( 13 _ loadtest.ClientFactory = (*ClientFactory)(nil) 14 _ loadtest.Client = (*TxGenerator)(nil) 15 ) 16 17 // ClientFactory implements the loadtest.ClientFactory interface. 18 type ClientFactory struct { 19 ID []byte 20 } 21 22 // TxGenerator is responsible for generating transactions. 23 // TxGenerator holds the set of information that will be used to generate 24 // each transaction. 25 type TxGenerator struct { 26 id []byte 27 conns uint64 28 rate uint64 29 size uint64 30 } 31 32 func main() { 33 u := [16]byte(uuid.New()) // generate run ID on startup 34 if err := loadtest.RegisterClientFactory("loadtime-client", &ClientFactory{ID: u[:]}); err != nil { 35 panic(err) 36 } 37 loadtest.Run(&loadtest.CLIConfig{ 38 AppName: "loadtime", 39 AppShortDesc: "Generate timestamped transaction load.", 40 AppLongDesc: "loadtime generates transaction load for the purpose of measuring the end-to-end latency of a transaction from submission to execution in a CometBFT network.", 41 DefaultClientFactory: "loadtime-client", 42 }) 43 } 44 45 func (f *ClientFactory) ValidateConfig(cfg loadtest.Config) error { 46 psb, err := payload.MaxUnpaddedSize() 47 if err != nil { 48 return err 49 } 50 if psb > cfg.Size { 51 return fmt.Errorf("payload size exceeds configured size") 52 } 53 return nil 54 } 55 56 func (f *ClientFactory) NewClient(cfg loadtest.Config) (loadtest.Client, error) { 57 return &TxGenerator{ 58 id: f.ID, 59 conns: uint64(cfg.Connections), 60 rate: uint64(cfg.Rate), 61 size: uint64(cfg.Size), 62 }, nil 63 } 64 65 func (c *TxGenerator) GenerateTx() ([]byte, error) { 66 return payload.NewBytes(&payload.Payload{ 67 Connections: c.conns, 68 Rate: c.rate, 69 Size: c.size, 70 Id: c.id, 71 }) 72 }