From 52d3eca67c30aed1fa63ac6148a92ccc5269d736 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 8 May 2018 16:23:00 +0400 Subject: [PATCH 1/3] check if block was created after timeStart --- tm-bench/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tm-bench/main.go b/tm-bench/main.go index 6bbe4f22..02b7f716 100644 --- a/tm-bench/main.go +++ b/tm-bench/main.go @@ -135,6 +135,11 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt numBlocksPerSec := make(map[int64]int64) numTxsPerSec := make(map[int64]int64) for _, blockMeta := range info.BlockMetas { + // check if block was created after timeStart + if blockMeta.Header.Time.Before(timeStart) { + continue + } + // check if block was created before timeStop if blockMeta.Header.Time.After(timeStop) { break From 80e6e0fa050949fdd7bdc2c1960a942ebb7eae59 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 8 May 2018 16:23:29 +0400 Subject: [PATCH 2/3] only call Sleep if it took us less than 1 sec. to generate txs --- tm-bench/transacter.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tm-bench/transacter.go b/tm-bench/transacter.go index d5316d9f..89a18b5f 100644 --- a/tm-bench/transacter.go +++ b/tm-bench/transacter.go @@ -168,7 +168,7 @@ func (t *transacter) sendLoop(connIndex int) { Params: rawParamsJSON, }) if err != nil { - fmt.Printf("%v. Try reducing the connections count and increasing the rate.\n", errors.Wrap(err, "txs send failed")) + fmt.Fprintf(os.Stderr, "%v. Try reducing the connections count and increasing the rate.\n", errors.Wrap(err, "txs send failed")) os.Exit(1) } @@ -176,7 +176,9 @@ func (t *transacter) sendLoop(connIndex int) { } timeToSend := time.Now().Sub(startTime) - time.Sleep(time.Second - timeToSend) + 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 a28fdfd3a8d712871f2a91bf8af05c9f3f844d2e Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 10 May 2018 17:08:49 +0400 Subject: [PATCH 3/3] fix stats calculation --- tm-bench/main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tm-bench/main.go b/tm-bench/main.go index 02b7f716..844c14df 100644 --- a/tm-bench/main.go +++ b/tm-bench/main.go @@ -102,7 +102,7 @@ Examples: timeStop := time.Now() logger.Info("Time stopped", "t", timeStop) - stats := calculateStatistics(client, minHeight, timeStart, timeStop) + stats := calculateStatistics(client, minHeight, timeStart, timeStop, duration) printStatistics(stats, outputFormat) @@ -119,7 +119,7 @@ func latestBlockHeight(client tmrpc.Client) int64 { return status.SyncInfo.LatestBlockHeight } -func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeStop time.Time) *statistics { +func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeStop time.Time, duration int) *statistics { stats := &statistics{ BlocksThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)), TxsThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)), @@ -134,6 +134,12 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt 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 + numTxsPerSec[i] = 0 + } + for _, blockMeta := range info.BlockMetas { // check if block was created after timeStart if blockMeta.Header.Time.Before(timeStart) {