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.

94 lines
1.8 KiB

  1. package bench
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "strings"
  7. "time"
  8. monitor "github.com/tendermint/tools/tm-monitor"
  9. )
  10. var version = "0.1.0.pre"
  11. func main() {
  12. var listenAddr string
  13. var connections, 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. transacters := make([]*Transacter, len(endpoints))
  34. for _, e := range strings.Split(endpoints, ",") {
  35. t := &transacter{e, txsRate}
  36. if err := t.Start(); err != nil {
  37. fmt.Println(err.Error())
  38. os.Exit(1)
  39. }
  40. append(transacters, t)
  41. }
  42. select {
  43. case time.After(duration * time.Second):
  44. for _, t := range transacters {
  45. t.Stop()
  46. }
  47. collectAndPrintResults(m)
  48. m.Stop()
  49. }
  50. cmn.TrapSignal(func() {
  51. for _, t := range transacters {
  52. t.Stop()
  53. }
  54. collectAndPrintResults(m)
  55. m.Stop()
  56. })
  57. }
  58. func startMonitor(endpoints string) *monitor.Monitor {
  59. m := monitor.NewMonitor()
  60. for _, e := range strings.Split(endpoints, ",") {
  61. if err := m.Monitor(monitor.NewNode(e)); err != nil {
  62. fmt.Println(err.Error())
  63. os.Exit(1)
  64. }
  65. }
  66. if err := m.Start(); err != nil {
  67. fmt.Println(err.Error())
  68. os.Exit(1)
  69. }
  70. return m
  71. }
  72. func collectAndPrintResults(m *Monitor) {
  73. fmt.Printf("%d", m.Network.Height)
  74. }