You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.8 KiB

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "strings"
  7. "time"
  8. "github.com/tendermint/tools/tm-monitor/monitor"
  9. )
  10. var version = "0.1.0.pre"
  11. func main() {
  12. var listenAddr string
  13. var duration, txsRate int
  14. flag.StringVar(&listenAddr, "listen-addr", "tcp://0.0.0.0:46670", "HTTP and Websocket server listen address")
  15. flag.IntVar(&duration, "T", 10, "Exit after the specified amount of time in seconds")
  16. flag.IntVar(&txsRate, "r", 1000, "Txs per second to send in a connection")
  17. flag.Usage = func() {
  18. fmt.Println(`Tendermint bench.
  19. Usage:
  20. tm-bench [-listen-addr="tcp://0.0.0.0:46670"] [-T 10] [-r 1000] [endpoints]
  21. Examples:
  22. tm-bench localhost:46657`)
  23. fmt.Println("Flags:")
  24. flag.PrintDefaults()
  25. }
  26. flag.Parse()
  27. if flag.NArg() == 0 {
  28. flag.Usage()
  29. os.Exit(1)
  30. }
  31. fmt.Printf("Running %ds test @ %s\n", duration, flag.Arg(0))
  32. m := startMonitor(flag.Arg(0))
  33. endpoints := strings.Split(flag.Arg(0), ",")
  34. transacters := make([]*transacter, len(endpoints))
  35. for i, e := range endpoints {
  36. t := newTransacter(e, txsRate)
  37. if err := t.Start(); err != nil {
  38. panic(err)
  39. }
  40. transacters[i] = t
  41. }
  42. select {
  43. case <-time.After(time.Duration(duration) * time.Second):
  44. for _, t := range transacters {
  45. t.Stop()
  46. }
  47. collectAndPrintResults(m)
  48. m.Stop()
  49. }
  50. }
  51. func startMonitor(endpoints string) *monitor.Monitor {
  52. m := monitor.NewMonitor()
  53. for _, e := range strings.Split(endpoints, ",") {
  54. if err := m.Monitor(monitor.NewNode(e)); err != nil {
  55. panic(err)
  56. }
  57. }
  58. if err := m.Start(); err != nil {
  59. panic(err)
  60. }
  61. return m
  62. }
  63. func collectAndPrintResults(m *monitor.Monitor) {
  64. n := m.Network
  65. fmt.Println("===")
  66. fmt.Printf("Avg block time: %.3f ms\n", n.AvgBlockTime)
  67. fmt.Printf("Avg tx throughput: %.0f per sec\n", n.AvgTxThroughput)
  68. fmt.Printf("Avg block latency: %.3f ms\n", n.AvgBlockLatency)
  69. fmt.Println("===")
  70. }