-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (53 loc) · 1.19 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
package main
import (
"flag"
"fmt"
"github.com/spf13/cast"
"github.com/zhixunjie/im-fun/benchmarks/client/tcp/operation"
"github.com/zhixunjie/im-fun/pkg/logging"
"math/rand"
"runtime"
"time"
)
var (
addr string
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
rand.Seed(time.Now().UTC().UnixNano())
// get params
var start, num int64
flag.Int64Var(&start, "start", 0, "用户ID的开始值")
flag.Int64Var(&num, "num", 0, "启动X个客户端")
flag.StringVar(&addr, "addr", "", "服务端地址")
flag.Parse()
// check params
if addr == "" {
fmt.Printf("没有指定参数 addr")
return
}
if start == 0 || num == 0 {
fmt.Printf("start或num参数等于0")
return
}
// start to run
go operation.DashBoard()
var i int64
for i = start; i < start+num; i++ {
go func(userId uint64) {
for {
// 切分QPS
sec := rand.Intn(120)
logging.Infof("userId=%v try to connect server after %v second", userId, sec)
time.Sleep(time.Duration(sec) * time.Second)
// start
operation.Start(userId, addr)
// restart after some second
time.Sleep(time.Duration(rand.Intn(10)) * time.Second)
}
}(cast.ToUint64(i))
}
// signal
var exit chan bool
<-exit
}