Browse Source

[tm-bench] give user ability to change rpc function (#91)

Closes #17
pull/1943/head
Anton Kaliaev 7 years ago
committed by GitHub
parent
commit
ab9881471a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 18 deletions
  1. +11
    -5
      tm-bench/main.go
  2. +15
    -13
      tm-bench/transacter.go

+ 11
- 5
tm-bench/main.go View File

@ -29,19 +29,20 @@ type statistics struct {
func main() { func main() {
var duration, txsRate, connections int var duration, txsRate, connections int
var verbose bool var verbose bool
var outputFormat string
var outputFormat, broadcastTxMethod string
flag.IntVar(&connections, "c", 1, "Connections to keep open per endpoint") 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(&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(&txsRate, "r", 1000, "Txs per second to send in a connection")
flag.StringVar(&outputFormat, "output-format", "plain", "Output format: plain or json") 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") flag.BoolVar(&verbose, "v", false, "Verbose output")
flag.Usage = func() { flag.Usage = func() {
fmt.Println(`Tendermint blockchain benchmarking tool. fmt.Println(`Tendermint blockchain benchmarking tool.
Usage: Usage:
tm-bench [-c 1] [-T 10] [-r 1000] [endpoints] [-output-format <plain|json>]
tm-bench [-c 1] [-T 10] [-r 1000] [endpoints] [-output-format <plain|json> [-broadcast-tx-method <async|sync|commit>]]
Examples: Examples:
tm-bench localhost:46657`) tm-bench localhost:46657`)
@ -75,6 +76,11 @@ Examples:
fmt.Printf("Running %ds test @ %s\n", duration, flag.Arg(0)) 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'.")
os.Exit(1)
}
endpoints := strings.Split(flag.Arg(0), ",") endpoints := strings.Split(flag.Arg(0), ",")
client := tmrpc.NewHTTP(endpoints[0], "/websocket") client := tmrpc.NewHTTP(endpoints[0], "/websocket")
@ -86,7 +92,7 @@ Examples:
timeStart := time.Now() timeStart := time.Now()
logger.Info("Time started", "t", timeStart) logger.Info("Time started", "t", timeStart)
transacters := startTransacters(endpoints, connections, txsRate)
transacters := startTransacters(endpoints, connections, txsRate, "broadcast_tx_"+broadcastTxMethod)
select { select {
case <-time.After(time.Duration(duration) * time.Second): case <-time.After(time.Duration(duration) * time.Second):
@ -164,11 +170,11 @@ func secondsSinceTimeStart(timeStart, timePassed time.Time) int64 {
return int64(timePassed.Sub(timeStart).Seconds()) return int64(timePassed.Sub(timeStart).Seconds())
} }
func startTransacters(endpoints []string, connections int, txsRate int) []*transacter {
func startTransacters(endpoints []string, connections, txsRate int, broadcastTxMethod string) []*transacter {
transacters := make([]*transacter, len(endpoints)) transacters := make([]*transacter, len(endpoints))
for i, e := range endpoints { for i, e := range endpoints {
t := newTransacter(e, connections, txsRate)
t := newTransacter(e, connections, txsRate, broadcastTxMethod)
t.SetLogger(logger) t.SetLogger(logger)
if err := t.Start(); err != nil { if err := t.Start(); err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)


+ 15
- 13
tm-bench/transacter.go View File

@ -31,9 +31,10 @@ const (
) )
type transacter struct { type transacter struct {
Target string
Rate int
Connections int
Target string
Rate int
Connections int
BroadcastTxMethod string
conns []*websocket.Conn conns []*websocket.Conn
wg sync.WaitGroup wg sync.WaitGroup
@ -42,13 +43,14 @@ type transacter struct {
logger log.Logger logger log.Logger
} }
func newTransacter(target string, connections int, rate int) *transacter {
func newTransacter(target string, connections, rate int, broadcastTxMethod string) *transacter {
return &transacter{ return &transacter{
Target: target,
Rate: rate,
Connections: connections,
conns: make([]*websocket.Conn, connections),
logger: log.NewNopLogger(),
Target: target,
Rate: rate,
Connections: connections,
BroadcastTxMethod: broadcastTxMethod,
conns: make([]*websocket.Conn, connections),
logger: log.NewNopLogger(),
} }
} }
@ -151,19 +153,19 @@ func (t *transacter) sendLoop(connIndex int) {
for i := 0; i < t.Rate; i++ { for i := 0; i < t.Rate; i++ {
// each transaction embeds connection index, tx number and hash of the hostname // each transaction embeds connection index, tx number and hash of the hostname
tx := generateTx(connIndex, txNumber, hostnameHash) tx := generateTx(connIndex, txNumber, hostnameHash)
paramsJson, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
if err != nil { if err != nil {
fmt.Printf("failed to encode params: %v\n", err) fmt.Printf("failed to encode params: %v\n", err)
os.Exit(1) os.Exit(1)
} }
rawParamsJson := json.RawMessage(paramsJson)
rawParamsJSON := json.RawMessage(paramsJSON)
c.SetWriteDeadline(time.Now().Add(sendTimeout)) c.SetWriteDeadline(time.Now().Add(sendTimeout))
err = c.WriteJSON(rpctypes.RPCRequest{ err = c.WriteJSON(rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",
ID: "tm-bench", ID: "tm-bench",
Method: "broadcast_tx_async",
Params: rawParamsJson,
Method: t.BroadcastTxMethod,
Params: rawParamsJSON,
}) })
if err != nil { if err != nil {
fmt.Printf("%v. Try reducing the connections count and increasing the rate.\n", errors.Wrap(err, "txs send failed")) fmt.Printf("%v. Try reducing the connections count and increasing the rate.\n", errors.Wrap(err, "txs send failed"))


Loading…
Cancel
Save