tmbench: Fix iterating through the blocks, update readme
This commit is contained in:
parent
e79b642d8d
commit
7eb2674e2b
|
@ -11,9 +11,10 @@ For example, the following:
|
||||||
will output:
|
will output:
|
||||||
|
|
||||||
Stats Avg Stdev Max
|
Stats Avg Stdev Max
|
||||||
Block latency 6.18ms 3.19ms 14ms
|
Txs/sec 833 427 1326
|
||||||
Blocks/sec 0.828 0.378 1
|
Blocks/sec 0.900 0.300 1
|
||||||
Txs/sec 963 493 1811
|
|
||||||
|
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
|
## Quick Start
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -85,8 +86,8 @@ Examples:
|
||||||
|
|
||||||
client := tmrpc.NewHTTP(endpoints[0], "/websocket")
|
client := tmrpc.NewHTTP(endpoints[0], "/websocket")
|
||||||
|
|
||||||
minHeight := latestBlockHeight(client)
|
initialHeight := latestBlockHeight(client)
|
||||||
logger.Info("Latest block height", "h", minHeight)
|
logger.Info("Latest block height", "h", initialHeight)
|
||||||
|
|
||||||
// record time start
|
// record time start
|
||||||
timeStart := time.Now()
|
timeStart := time.Now()
|
||||||
|
@ -102,7 +103,7 @@ Examples:
|
||||||
timeStop := time.Now()
|
timeStop := time.Now()
|
||||||
logger.Info("Time stopped", "t", timeStop)
|
logger.Info("Time stopped", "t", timeStop)
|
||||||
|
|
||||||
stats := calculateStatistics(client, minHeight, timeStart, timeStop, duration)
|
stats := calculateStatistics(client, initialHeight, timeStart, timeStop, duration)
|
||||||
|
|
||||||
printStatistics(stats, outputFormat)
|
printStatistics(stats, outputFormat)
|
||||||
|
|
||||||
|
@ -119,6 +120,8 @@ func latestBlockHeight(client tmrpc.Client) int64 {
|
||||||
return status.SyncInfo.LatestBlockHeight
|
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 {
|
func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeStop time.Time, duration int) *statistics {
|
||||||
stats := &statistics{
|
stats := &statistics{
|
||||||
BlocksThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)),
|
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
|
// get blocks between minHeight and last height
|
||||||
|
// This returns max(minHeight,(last_height - 20)) to last_height
|
||||||
info, err := client.BlockchainInfo(minHeight, 0)
|
info, err := client.BlockchainInfo(minHeight, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
maxHeight := info.LastHeight
|
lastHeight := info.LastHeight
|
||||||
diff := maxHeight - minHeight
|
diff := lastHeight - minHeight
|
||||||
|
|
||||||
blockMetas := info.BlockMetas
|
blockMetas := info.BlockMetas
|
||||||
offset := len(blockMetas)
|
offset := len(blockMetas)
|
||||||
for len(blockMetas) < int(diff) {
|
for len(blockMetas) < int(diff) {
|
||||||
// get blocks between minHeight and last height
|
// 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 {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -156,29 +160,23 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt
|
||||||
numTxsPerSec[i] = 0
|
numTxsPerSec[i] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// iterates from max height to min height
|
||||||
for _, blockMeta := range blockMetas {
|
for _, blockMeta := range blockMetas {
|
||||||
// check if block was created after timeStart
|
// check if block was created after timeStart
|
||||||
if blockMeta.Header.Time.Before(timeStart) {
|
if blockMeta.Header.Time.Before(timeStart) {
|
||||||
continue
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if block was created before timeStop
|
// check if block was created before timeStop
|
||||||
if blockMeta.Header.Time.After(timeStop) {
|
if blockMeta.Header.Time.After(timeStop) {
|
||||||
break
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sec := secondsSinceTimeStart(timeStart, blockMeta.Header.Time)
|
sec := secondsSinceTimeStart(timeStart, blockMeta.Header.Time)
|
||||||
|
|
||||||
// increase number of blocks for that second
|
// increase number of blocks for that second
|
||||||
if _, ok := numBlocksPerSec[sec]; !ok {
|
|
||||||
numBlocksPerSec[sec] = 0
|
|
||||||
}
|
|
||||||
numBlocksPerSec[sec]++
|
numBlocksPerSec[sec]++
|
||||||
|
|
||||||
// increase number of txs for that second
|
// increase number of txs for that second
|
||||||
if _, ok := numTxsPerSec[sec]; !ok {
|
|
||||||
numTxsPerSec[sec] = 0
|
|
||||||
}
|
|
||||||
numTxsPerSec[sec] += blockMeta.Header.NumTxs
|
numTxsPerSec[sec] += blockMeta.Header.NumTxs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,14 +188,11 @@ func calculateStatistics(client tmrpc.Client, minHeight int64, timeStart, timeSt
|
||||||
stats.TxsThroughput.Update(n)
|
stats.TxsThroughput.Update(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("blocks", numBlocksPerSec)
|
|
||||||
fmt.Println("txs", numTxsPerSec)
|
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
func secondsSinceTimeStart(timeStart, timePassed time.Time) int64 {
|
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 {
|
func startTransacters(endpoints []string, connections, txsRate int, broadcastTxMethod string) []*transacter {
|
||||||
|
|
|
@ -176,6 +176,9 @@ func (t *transacter) sendLoop(connIndex int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
timeToSend := time.Now().Sub(startTime)
|
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)
|
logger.Info(fmt.Sprintf("sent %d transactions", t.Rate), "took", timeToSend)
|
||||||
case <-pingsTicker.C:
|
case <-pingsTicker.C:
|
||||||
// go-rpc server closes the connection in the absence of pings
|
// go-rpc server closes the connection in the absence of pings
|
||||||
|
|
Loading…
Reference in New Issue