Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "flag"
  5. "os"
  6. "time"
  7.  
  8. "github.com/coding-yogi/goperf/log"
  9. "github.com/coding-yogi/goperf/tests"
  10. )
  11.  
  12. func main() {
  13.  
  14. tc := flag.Int("threads", 10, "Thread Count")
  15. rut := flag.Int("rampup", 30, "Ramp up time in seconds")
  16. et := flag.Int("etime", 1, "Execution time in minutes")
  17. flag.Parse()
  18.  
  19. //Check if execution time is more than ramp up time
  20. if *et*60 < *rut {
  21. log.Fatalln("Total execution time needs to be more than ramp up time")
  22. }
  23.  
  24. waitTime := *rut / *tc
  25.  
  26. log.Printf("Execution will happen with %d users with a ramp up time of %d seconds for %d minutes\n", *tc, *rut, *et)
  27.  
  28. tchan := make(chan int)
  29. go func(c chan<- int) {
  30. for ti := 1 ; ti <= *tc ; ti++ {
  31. log.Printf("Thread Count %d", ti)
  32. c <- ti
  33. time.Sleep(time.Duration(waitTime) * time.Second)
  34. }
  35. }(tchan)
  36.  
  37. timeout := time.After(time.Duration(*et*60) * time.Second)
  38.  
  39. for {
  40. select { //Select blocks the flow until one of the channels receives a message
  41. case <-timeout: //receives a msg when execution duration is over
  42. log.Printf("Execution completed")
  43. return
  44. case ts := <-tchan: //receives a message when a new user thread has to be initiated
  45. log.Printf("Thread No %d started", ts)
  46. go func(t int) {
  47. //This is the place where you add all your tests
  48. //In my case they were making rpc calls over rabbitmq with random inputs
  49. //They keep running till the end of execution
  50. for {
  51. tests.Test1(t) //sample test
  52. tests.Test2(t)
  53. }
  54. }(ts)
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement