Last active
October 10, 2023 10:51
-
-
Save coding-yogi/eeae4fcbe58736eedcd69be25944e8df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"os" | |
"time" | |
"github.com/coding-yogi/goperf/log" | |
"github.com/coding-yogi/goperf/tests" | |
) | |
func main() { | |
tc := flag.Int("threads", 10, "Thread Count") | |
rut := flag.Int("rampup", 30, "Ramp up time in seconds") | |
et := flag.Int("etime", 1, "Execution time in minutes") | |
flag.Parse() | |
//Check if execution time is more than ramp up time | |
if *et*60 < *rut { | |
log.Fatalln("Total execution time needs to be more than ramp up time") | |
} | |
waitTime := *rut / *tc | |
log.Printf("Execution will happen with %d users with a ramp up time of %d seconds for %d minutes\n", *tc, *rut, *et) | |
tchan := make(chan int) | |
go func(c chan<- int) { | |
for ti := 1 ; ti <= *tc ; ti++ { | |
log.Printf("Thread Count %d", ti) | |
c <- ti | |
time.Sleep(time.Duration(waitTime) * time.Second) | |
} | |
}(tchan) | |
timeout := time.After(time.Duration(*et*60) * time.Second) | |
for { | |
select { //Select blocks the flow until one of the channels receives a message | |
case <-timeout: //receives a msg when execution duration is over | |
log.Printf("Execution completed") | |
return | |
case ts := <-tchan: //receives a message when a new user thread has to be initiated | |
log.Printf("Thread No %d started", ts) | |
go func(t int) { | |
//This is the place where you add all your tests | |
//In my case they were making rpc calls over rabbitmq with random inputs | |
//They keep running till the end of execution | |
for { | |
tests.Test1(t) //sample test | |
tests.Test2(t) | |
} | |
}(ts) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment