forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (45 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"log"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/myzhan/boomer"
)
func foo() {
start := time.Now()
time.Sleep(100 * time.Millisecond)
elapsed := time.Since(start)
// Report your test result as a success, if you write it in python, it will looks like this
// events.request_success.fire(request_type="http", name="foo", response_time=100, response_length=10)
globalBoomer.RecordSuccess("http", "foo", elapsed.Nanoseconds()/int64(time.Millisecond), int64(10))
}
func waitForQuit() {
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
<-c
globalBoomer.Quit()
wg.Done()
}()
wg.Wait()
}
var globalBoomer = boomer.NewBoomer("127.0.0.1", 5557)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
task1 := &boomer.Task{
Name: "foo",
Weight: 10,
Fn: foo,
}
ratelimiter := boomer.NewStableRateLimiter(100, time.Second)
log.Println("the max rps is limited to 100/s.")
globalBoomer.SetRateLimiter(ratelimiter)
globalBoomer.Run(task1)
waitForQuit()
log.Println("shut down")
}