forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (69 loc) · 1.58 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"encoding/json"
"flag"
"log"
"time"
"github.com/bugVanisher/grequester"
"github.com/myzhan/boomer"
)
var verbose = false
// change to your own service and method
var service = "helloworld.Greeter"
var method = "SayHello"
var timeout uint = 3000
var poolsize = 200
var (
addr string
reqJSONStr string
client *grequester.Requester
req *HelloRequest
)
func rpcReq() {
startTime := time.Now()
// make the request
request := &HelloRequest{}
request.Name = req.Name
// init the response
resp := new(HelloReply)
err := client.Call(request, resp)
elapsed := time.Since(startTime)
if err != nil {
if verbose {
log.Printf("%v\n", err)
}
boomer.RecordFailure("rpc", "error", 0.0, err.Error())
} else {
// make your assertion
boomer.RecordSuccess("rpc", "succ",
elapsed.Nanoseconds()/int64(time.Millisecond), int64(len(resp.String())))
if verbose {
if err != nil {
log.Printf("%v\n", err)
} else {
log.Printf("Resp Length: %d\n", len(resp.String()))
log.Println(resp.String())
}
}
}
}
func main() {
flag.StringVar(&addr, "a", "", "ip:port")
flag.StringVar(&reqJSONStr, "r", "{}", "request message in json form")
flag.Parse()
log.Printf(reqJSONStr)
// json unserialize, input different parameters
err := json.Unmarshal([]byte(reqJSONStr), &req)
if nil != err {
log.Printf("json unmarshal error")
return
}
// init requester
client = grequester.NewRequester(addr, service, method, timeout, poolsize)
task := &boomer.Task{
Name: "rpcReq",
Weight: 10,
Fn: rpcReq,
}
boomer.Run(task)
}