From b7925cd34f8f76f72407784194031d0ac5cd9bc7 Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Fri, 22 Jun 2018 18:22:30 -0700 Subject: [PATCH] tmbench: Make tx size configurable * Make the parameter for tx size in bytes -s , w/ default value 250 --- tm-bench/README.md | 4 +++- tm-bench/main.go | 7 +++++-- tm-bench/transacter.go | 11 +++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tm-bench/README.md b/tm-bench/README.md index 07c733ba..75be76ff 100644 --- a/tm-bench/README.md +++ b/tm-bench/README.md @@ -34,7 +34,7 @@ with the last command being in a seperate window. ## Usage - tm-bench [-c 1] [-T 10] [-r 1000] [endpoints] + tm-bench [-c 1] [-T 10] [-r 1000] [-s 250] [endpoints] Examples: tm-bench localhost:26657 @@ -45,6 +45,8 @@ with the last command being in a seperate window. Connections to keep open per endpoint (default 1) -r int Txs per second to send in a connection (default 1000) + -s int + Size per tx in bytes -v Verbose output ## Development diff --git a/tm-bench/main.go b/tm-bench/main.go index 534d065e..f124e9bf 100644 --- a/tm-bench/main.go +++ b/tm-bench/main.go @@ -27,13 +27,14 @@ type statistics struct { } func main() { - var duration, txsRate, connections int + var duration, txsRate, connections, txSize int var verbose bool var outputFormat, broadcastTxMethod string flag.IntVar(&connections, "c", 1, "Connections to keep open per endpoint") flag.IntVar(&duration, "T", 10, "Exit after the specified amount of time in seconds") flag.IntVar(&txsRate, "r", 1000, "Txs per second to send in a connection") + flag.IntVar(&txSize, "s", 250, "The size of a transaction in bytes.") flag.StringVar(&outputFormat, "output-format", "plain", "Output format: plain or json") flag.StringVar(&broadcastTxMethod, "broadcast-tx-method", "async", "Broadcast method: async (no guarantees; fastest), sync (ensures tx is checked) or commit (ensures tx is checked and committed; slowest)") flag.BoolVar(&verbose, "v", false, "Verbose output") @@ -101,6 +102,7 @@ Examples: endpoints, connections, txsRate, + txSize, "broadcast_tx_"+broadcastTxMethod, ) @@ -228,12 +230,13 @@ func startTransacters( endpoints []string, connections, txsRate int, + txSize int, broadcastTxMethod string, ) []*transacter { transacters := make([]*transacter, len(endpoints)) for i, e := range endpoints { - t := newTransacter(e, connections, txsRate, broadcastTxMethod) + t := newTransacter(e, connections, txsRate, txSize, broadcastTxMethod) t.SetLogger(logger) if err := t.Start(); err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/tm-bench/transacter.go b/tm-bench/transacter.go index a73abf4f..dd14a04c 100644 --- a/tm-bench/transacter.go +++ b/tm-bench/transacter.go @@ -25,14 +25,12 @@ const ( sendTimeout = 10 * time.Second // see https://github.com/tendermint/go-rpc/blob/develop/server/handlers.go#L313 pingPeriod = (30 * 9 / 10) * time.Second - - // the size of a transaction in bytes. - txSize = 250 ) type transacter struct { Target string Rate int + Size int Connections int BroadcastTxMethod string @@ -43,10 +41,11 @@ type transacter struct { logger log.Logger } -func newTransacter(target string, connections, rate int, broadcastTxMethod string) *transacter { +func newTransacter(target string, connections, rate int, size int, broadcastTxMethod string) *transacter { return &transacter{ Target: target, Rate: rate, + Size: size, Connections: connections, BroadcastTxMethod: broadcastTxMethod, conns: make([]*websocket.Conn, connections), @@ -152,7 +151,7 @@ func (t *transacter) sendLoop(connIndex int) { for i := 0; i < t.Rate; i++ { // each transaction embeds connection index, tx number and hash of the hostname - tx := generateTx(connIndex, txNumber, hostnameHash) + tx := generateTx(connIndex, txNumber, t.Size, hostnameHash) paramsJSON, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)}) if err != nil { fmt.Printf("failed to encode params: %v\n", err) @@ -207,7 +206,7 @@ func connect(host string) (*websocket.Conn, *http.Response, error) { return websocket.DefaultDialer.Dial(u.String(), nil) } -func generateTx(connIndex int, txNumber int, hostnameHash [md5.Size]byte) []byte { +func generateTx(connIndex int, txNumber int, txSize int, hostnameHash [md5.Size]byte) []byte { tx := make([]byte, txSize) binary.PutUvarint(tx[:8], uint64(connIndex))