Browse Source

tools: Refactor tm-bench (#2570)

* specify time unit for FlushThrottleTimeout in TestP2PConfig
Refs #2555
* [tm-bench] refactor code
https://github.com/tendermint/tendermint/pull/2405#pullrequestreview-157166387
pull/2576/head
Anton Kaliaev 6 years ago
committed by Alexander Simmerl
parent
commit
35b671214c
2 changed files with 16 additions and 21 deletions
  1. +1
    -1
      config/config.go
  2. +15
    -20
      tools/tm-bench/main.go

+ 1
- 1
config/config.go View File

@ -405,7 +405,7 @@ func DefaultP2PConfig() *P2PConfig {
func TestP2PConfig() *P2PConfig {
cfg := DefaultP2PConfig()
cfg.ListenAddress = "tcp://0.0.0.0:36656"
cfg.FlushThrottleTimeout = 10
cfg.FlushThrottleTimeout = 10 * time.Millisecond
cfg.AllowDuplicateIP = true
return cfg
}


+ 15
- 20
tools/tm-bench/main.go View File

@ -4,16 +4,16 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"
"github.com/go-kit/kit/log/term"
"github.com/tendermint/tendermint/libs/log"
tmrpc "github.com/tendermint/tendermint/rpc/client"
"os/signal"
"syscall"
)
var logger = log.NewNopLogger()
@ -53,8 +53,7 @@ Examples:
if verbose {
if outputFormat == "json" {
fmt.Fprintln(os.Stderr, "Verbose mode not supported with json output.")
os.Exit(1)
printErrorAndExit("Verbose mode not supported with json output.")
}
// Color errors red
colorFn := func(keyvals ...interface{}) term.FgBgColor {
@ -71,21 +70,13 @@ Examples:
}
if txSize < 40 {
fmt.Fprintln(
os.Stderr,
"The size of a transaction must be greater than or equal to 40.",
)
os.Exit(1)
printErrorAndExit("The size of a transaction must be greater than or equal to 40.")
}
if broadcastTxMethod != "async" &&
broadcastTxMethod != "sync" &&
broadcastTxMethod != "commit" {
fmt.Fprintln(
os.Stderr,
"broadcast-tx-method should be either 'sync', 'async' or 'commit'.",
)
os.Exit(1)
printErrorAndExit("broadcast-tx-method should be either 'sync', 'async' or 'commit'.")
}
var (
@ -103,10 +94,10 @@ Examples:
"broadcast_tx_"+broadcastTxMethod,
)
//catch Interrupt and quit tm-bench
// Quit when interrupted or received SIGTERM.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
for sig := range c {
fmt.Printf("captured %v, exiting...\n", sig)
for _, t := range transacters {
@ -116,7 +107,7 @@ Examples:
}
}()
// Wait until transacters have begun until we get the start time
// Wait until transacters have begun until we get the start time.
timeStart := time.Now()
logger.Info("Time last transacter started", "t", timeStart)
@ -143,8 +134,7 @@ Examples:
durationInt,
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
printErrorAndExit(err.Error())
}
printStatistics(stats, outputFormat)
@ -196,3 +186,8 @@ func startTransacters(
return transacters
}
func printErrorAndExit(err string) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

Loading…
Cancel
Save