From e79b642d8d0007c175d7effbaedfc8591bcb045d Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 4 Jun 2018 12:37:37 -0700 Subject: [PATCH 1/3] wip fixes --- tm-bench/main.go | 21 ++++++++++++++++++++- tm-bench/transacter.go | 3 --- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tm-bench/main.go b/tm-bench/main.go index 8369c632..4e080291 100644 --- a/tm-bench/main.go +++ b/tm-bench/main.go @@ -132,6 +132,22 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt os.Exit(1) } + maxHeight := info.LastHeight + diff := maxHeight - minHeight + + blockMetas := info.BlockMetas + offset := len(blockMetas) + for len(blockMetas) < int(diff) { + // get blocks between minHeight and last height + info, err := client.BlockchainInfo(minHeight+int64(offset), 0) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + blockMetas = append(blockMetas, info.BlockMetas...) + offset = len(blockMetas) + } + numBlocksPerSec := make(map[int64]int64) numTxsPerSec := make(map[int64]int64) // because during some seconds blocks won't be created... @@ -140,7 +156,7 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt numTxsPerSec[i] = 0 } - for _, blockMeta := range info.BlockMetas { + for _, blockMeta := range blockMetas { // check if block was created after timeStart if blockMeta.Header.Time.Before(timeStart) { continue @@ -174,6 +190,9 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt stats.TxsThroughput.Update(n) } + fmt.Println("blocks", numBlocksPerSec) + fmt.Println("txs", numTxsPerSec) + return stats } diff --git a/tm-bench/transacter.go b/tm-bench/transacter.go index 89a18b5f..dd46c772 100644 --- a/tm-bench/transacter.go +++ b/tm-bench/transacter.go @@ -176,9 +176,6 @@ func (t *transacter) sendLoop(connIndex int) { } timeToSend := time.Now().Sub(startTime) - if timeToSend < 1*time.Second { - time.Sleep(time.Second - timeToSend) - } logger.Info(fmt.Sprintf("sent %d transactions", t.Rate), "took", timeToSend) case <-pingsTicker.C: // go-rpc server closes the connection in the absence of pings From 7eb2674e2b7d45fd0b60cbac4e948517fbb0ae8d Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Fri, 22 Jun 2018 16:16:27 -0700 Subject: [PATCH 2/3] tmbench: Fix iterating through the blocks, update readme --- tm-bench/README.md | 7 ++++--- tm-bench/main.go | 33 ++++++++++++++------------------- tm-bench/transacter.go | 3 +++ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/tm-bench/README.md b/tm-bench/README.md index 17e32b5c..897c4377 100644 --- a/tm-bench/README.md +++ b/tm-bench/README.md @@ -11,9 +11,10 @@ For example, the following: will output: Stats Avg Stdev Max - Block latency 6.18ms 3.19ms 14ms - Blocks/sec 0.828 0.378 1 - Txs/sec 963 493 1811 + Txs/sec 833 427 1326 + Blocks/sec 0.900 0.300 1 + +These stats are derived by sending transactions at the specified rate for the specified time. After the specified time, it iterates over all of the blocks that were created in that time. The average and stddev per second are computed based off of that, by grouping the data by second. ## Quick Start diff --git a/tm-bench/main.go b/tm-bench/main.go index 4e080291..8a224fda 100644 --- a/tm-bench/main.go +++ b/tm-bench/main.go @@ -4,6 +4,7 @@ import ( "encoding/json" "flag" "fmt" + "math" "os" "strings" "time" @@ -85,8 +86,8 @@ Examples: client := tmrpc.NewHTTP(endpoints[0], "/websocket") - minHeight := latestBlockHeight(client) - logger.Info("Latest block height", "h", minHeight) + initialHeight := latestBlockHeight(client) + logger.Info("Latest block height", "h", initialHeight) // record time start timeStart := time.Now() @@ -102,7 +103,7 @@ Examples: timeStop := time.Now() logger.Info("Time stopped", "t", timeStop) - stats := calculateStatistics(client, minHeight, timeStart, timeStop, duration) + stats := calculateStatistics(client, initialHeight, timeStart, timeStop, duration) printStatistics(stats, outputFormat) @@ -119,6 +120,8 @@ func latestBlockHeight(client tmrpc.Client) int64 { return status.SyncInfo.LatestBlockHeight } +// Calculates the tx / second, and blocks / second based off of the number the transactions +// and number of blocks that occured from the start block, and the end time. func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeStop time.Time, duration int) *statistics { stats := &statistics{ BlocksThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)), @@ -126,20 +129,21 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt } // get blocks between minHeight and last height + // This returns max(minHeight,(last_height - 20)) to last_height info, err := client.BlockchainInfo(minHeight, 0) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } - maxHeight := info.LastHeight - diff := maxHeight - minHeight + lastHeight := info.LastHeight + diff := lastHeight - minHeight blockMetas := info.BlockMetas offset := len(blockMetas) for len(blockMetas) < int(diff) { // get blocks between minHeight and last height - info, err := client.BlockchainInfo(minHeight+int64(offset), 0) + info, err := client.BlockchainInfo(minHeight, lastHeight-int64(offset)) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) @@ -156,29 +160,23 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt numTxsPerSec[i] = 0 } + // iterates from max height to min height for _, blockMeta := range blockMetas { // check if block was created after timeStart if blockMeta.Header.Time.Before(timeStart) { - continue + break } // check if block was created before timeStop if blockMeta.Header.Time.After(timeStop) { - break + continue } - sec := secondsSinceTimeStart(timeStart, blockMeta.Header.Time) // increase number of blocks for that second - if _, ok := numBlocksPerSec[sec]; !ok { - numBlocksPerSec[sec] = 0 - } numBlocksPerSec[sec]++ // increase number of txs for that second - if _, ok := numTxsPerSec[sec]; !ok { - numTxsPerSec[sec] = 0 - } numTxsPerSec[sec] += blockMeta.Header.NumTxs } @@ -190,14 +188,11 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt stats.TxsThroughput.Update(n) } - fmt.Println("blocks", numBlocksPerSec) - fmt.Println("txs", numTxsPerSec) - return stats } func secondsSinceTimeStart(timeStart, timePassed time.Time) int64 { - return int64(timePassed.Sub(timeStart).Seconds()) + return int64(math.Round(timePassed.Sub(timeStart).Seconds())) } func startTransacters(endpoints []string, connections, txsRate int, broadcastTxMethod string) []*transacter { diff --git a/tm-bench/transacter.go b/tm-bench/transacter.go index dd46c772..89a18b5f 100644 --- a/tm-bench/transacter.go +++ b/tm-bench/transacter.go @@ -176,6 +176,9 @@ func (t *transacter) sendLoop(connIndex int) { } timeToSend := time.Now().Sub(startTime) + if timeToSend < 1*time.Second { + time.Sleep(time.Second - timeToSend) + } logger.Info(fmt.Sprintf("sent %d transactions", t.Rate), "took", timeToSend) case <-pingsTicker.C: // go-rpc server closes the connection in the absence of pings From 65b479dd65201ff3fc2afabf15aab7d4331cd05b Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Sat, 23 Jun 2018 01:57:50 +0200 Subject: [PATCH 3/3] tm-bench: Improve code shape * return error so main controls exit states * formatting * order imports --- tm-bench/README.md | 5 ++- tm-bench/main.go | 90 +++++++++++++++++++++++++++++------------- tm-bench/transacter.go | 2 +- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/tm-bench/README.md b/tm-bench/README.md index 897c4377..07c733ba 100644 --- a/tm-bench/README.md +++ b/tm-bench/README.md @@ -14,7 +14,10 @@ will output: Txs/sec 833 427 1326 Blocks/sec 0.900 0.300 1 -These stats are derived by sending transactions at the specified rate for the specified time. After the specified time, it iterates over all of the blocks that were created in that time. The average and stddev per second are computed based off of that, by grouping the data by second. +These stats are derived by sending transactions at the specified rate for the +specified time. After the specified time, it iterates over all of the blocks +that were created in that time. The average and stddev per second are computed +based off of that, by grouping the data by second. ## Quick Start diff --git a/tm-bench/main.go b/tm-bench/main.go index 8a224fda..534d065e 100644 --- a/tm-bench/main.go +++ b/tm-bench/main.go @@ -7,14 +7,13 @@ import ( "math" "os" "strings" + "text/tabwriter" "time" "github.com/go-kit/kit/log/term" metrics "github.com/rcrowley/go-metrics" - - "text/tabwriter" - tmrpc "github.com/tendermint/tendermint/rpc/client" + "github.com/tendermint/tmlibs/log" ) @@ -77,33 +76,54 @@ Examples: fmt.Printf("Running %ds test @ %s\n", duration, flag.Arg(0)) } - if broadcastTxMethod != "async" && broadcastTxMethod != "sync" && broadcastTxMethod != "commit" { - fmt.Fprintln(os.Stderr, "broadcast-tx-method should be either 'sync', 'async' or 'commit'.") + if broadcastTxMethod != "async" && + broadcastTxMethod != "sync" && + broadcastTxMethod != "commit" { + fmt.Fprintln( + os.Stderr, + "broadcast-tx-method should be either 'sync', 'async' or 'commit'.", + ) os.Exit(1) } - endpoints := strings.Split(flag.Arg(0), ",") - - client := tmrpc.NewHTTP(endpoints[0], "/websocket") - - initialHeight := latestBlockHeight(client) + var ( + endpoints = strings.Split(flag.Arg(0), ",") + client = tmrpc.NewHTTP(endpoints[0], "/websocket") + initialHeight = latestBlockHeight(client) + ) logger.Info("Latest block height", "h", initialHeight) // record time start timeStart := time.Now() logger.Info("Time started", "t", timeStart) - transacters := startTransacters(endpoints, connections, txsRate, "broadcast_tx_"+broadcastTxMethod) + transacters := startTransacters( + endpoints, + connections, + txsRate, + "broadcast_tx_"+broadcastTxMethod, + ) select { case <-time.After(time.Duration(duration) * time.Second): for _, t := range transacters { t.Stop() } + timeStop := time.Now() logger.Info("Time stopped", "t", timeStop) - stats := calculateStatistics(client, initialHeight, timeStart, timeStop, duration) + stats, err := calculateStatistics( + client, + initialHeight, + timeStart, + timeStop, + duration, + ) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } printStatistics(stats, outputFormat) @@ -120,9 +140,15 @@ func latestBlockHeight(client tmrpc.Client) int64 { return status.SyncInfo.LatestBlockHeight } -// Calculates the tx / second, and blocks / second based off of the number the transactions -// and number of blocks that occured from the start block, and the end time. -func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeStop time.Time, duration int) *statistics { +// calculateStatistics calculates the tx / second, and blocks / second based +// off of the number the transactions and number of blocks that occurred from +// the start block, and the end time. +func calculateStatistics( + client tmrpc.Client, + minHeight int64, + timeStart, timeStop time.Time, + duration int, +) (*statistics, error) { stats := &statistics{ BlocksThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)), TxsThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)), @@ -132,28 +158,31 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt // This returns max(minHeight,(last_height - 20)) to last_height info, err := client.BlockchainInfo(minHeight, 0) if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) + return nil, err } - lastHeight := info.LastHeight - diff := lastHeight - minHeight + var ( + blockMetas = info.BlockMetas + lastHeight = info.LastHeight + diff = lastHeight - minHeight + offset = len(blockMetas) + ) - blockMetas := info.BlockMetas - offset := len(blockMetas) - for len(blockMetas) < int(diff) { + for offset < int(diff) { // get blocks between minHeight and last height info, err := client.BlockchainInfo(minHeight, lastHeight-int64(offset)) if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) + return nil, err } blockMetas = append(blockMetas, info.BlockMetas...) offset = len(blockMetas) } - numBlocksPerSec := make(map[int64]int64) - numTxsPerSec := make(map[int64]int64) + var ( + numBlocksPerSec = make(map[int64]int64) + numTxsPerSec = make(map[int64]int64) + ) + // because during some seconds blocks won't be created... for i := int64(0); i < int64(duration); i++ { numBlocksPerSec[i] = 0 @@ -188,14 +217,19 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt stats.TxsThroughput.Update(n) } - return stats + return stats, nil } func secondsSinceTimeStart(timeStart, timePassed time.Time) int64 { return int64(math.Round(timePassed.Sub(timeStart).Seconds())) } -func startTransacters(endpoints []string, connections, txsRate int, broadcastTxMethod string) []*transacter { +func startTransacters( + endpoints []string, + connections, + txsRate int, + broadcastTxMethod string, +) []*transacter { transacters := make([]*transacter, len(endpoints)) for i, e := range endpoints { diff --git a/tm-bench/transacter.go b/tm-bench/transacter.go index 89a18b5f..a73abf4f 100644 --- a/tm-bench/transacter.go +++ b/tm-bench/transacter.go @@ -16,8 +16,8 @@ import ( "github.com/gorilla/websocket" "github.com/pkg/errors" - rpctypes "github.com/tendermint/tendermint/rpc/lib/types" + "github.com/tendermint/tmlibs/log" )