-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
239 lines (231 loc) · 5.79 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package main
import (
"os"
"github.com/antlinker/mqttgroup/collect"
"github.com/antlinker/mqttgroup/publish"
"github.com/antlinker/alog"
"github.com/antlinker/mqttgroup/clear"
"github.com/antlinker/mqttgroup/generate"
"github.com/codegangsta/cli"
)
func main() {
alog.RegisterAlog("conf/log.yaml")
app := cli.NewApp()
app.Name = "mqttgroup"
app.Author = "Lyric"
app.Version = "0.1.0"
app.Usage = "MQTT群组聊天测试"
app.Commands = append(app.Commands, cli.Command{
Name: "generate",
Aliases: []string{"gen"},
Usage: "生成群组并且分配群成员",
Flags: []cli.Flag{
cli.IntFlag{
Name: "groupnum, gn",
Value: 200,
Usage: "群组数量",
},
cli.IntFlag{
Name: "grouplimit, gcln",
Value: 200,
Usage: "组成员数量限制",
},
cli.IntFlag{
Name: "clientnum, cn",
Value: 1000,
Usage: "组成员数量",
},
cli.IntFlag{
Name: "clientlimit, cgln",
Value: 50,
Usage: "组成员所拥有的组数量限制",
},
cli.StringFlag{
Name: "mongo, mgo",
Value: "mongodb://127.0.0.1:27017",
Usage: "MongoDB连接url",
},
},
Action: func(ctx *cli.Context) {
cfg := generate.Config{
GroupNum: ctx.Int("groupnum"),
GroupClientLimitNum: ctx.Int("grouplimit"),
ClientNum: ctx.Int("clientnum"),
ClientGroupLimitNum: ctx.Int("clientlimit"),
MongoUrl: ctx.String("mongo"),
}
generate.Gen(cfg)
},
})
app.Commands = append(app.Commands, cli.Command{
Name: "publish",
Aliases: []string{"pub"},
Usage: "发布消息",
Flags: []cli.Flag{
cli.IntFlag{
Name: "ExecNum, en",
Value: 10,
Usage: "执行次数",
},
cli.IntFlag{
Name: "Interval, i",
Value: 5,
Usage: "发布间隔(单位:秒)",
},
cli.IntFlag{
Name: "UserInterval, ui",
Value: 1,
Usage: "组成员发包间隔(单位:毫秒)",
},
cli.IntFlag{
Name: "UserGroupInterval, ugi",
Value: 0,
Usage: "组成员针对组的发包间隔(单位:毫秒)",
},
cli.IntFlag{
Name: "AutoReconnect, ar",
Value: 1,
Usage: "客户端断开连接后执行自动重连(默认为1,0表示不重连)",
},
cli.IntFlag{
Name: "DisconnectScale, ds",
Value: 0,
Usage: "发送完成之后,需要断开客户端的比例",
},
cli.BoolFlag{
Name: "IsStore, s",
Usage: "是否执行持久化存储",
},
cli.IntFlag{
Name: "SendPacketStoreNum, spsn",
Value: 200,
Usage: "发包一次性写入数据量",
},
cli.IntFlag{
Name: "SendPacketBucketNum, spbn",
Value: 100,
Usage: "发包临时存储使用容器的数量",
},
cli.IntFlag{
Name: "ReceivePacketStoreNum, rpsn",
Value: 1000,
Usage: "接包一次性写入数据量",
},
cli.IntFlag{
Name: "ReceivePacketBucketNum, rpbn",
Value: 100,
Usage: "接包临时存储使用容器的数量",
},
cli.StringFlag{
Name: "Network, net",
Value: "tcp",
Usage: "MQTT Network",
},
cli.StringFlag{
Name: "Address, addr",
Value: "127.0.0.1:1883",
Usage: "MQTT Address",
},
cli.StringFlag{
Name: "UserName, name",
Value: "",
Usage: "MQTT UserName",
},
cli.StringFlag{
Name: "Password, pwd",
Value: "",
Usage: "MQTT Password",
},
cli.IntFlag{
Name: "QOS, qos",
Value: 1,
Usage: "MQTT QOS",
},
cli.IntFlag{
Name: "KeepAlive, alive",
Value: 30,
Usage: "MQTT KeepAlive",
},
cli.BoolFlag{
Name: "CleanSession, cs",
Usage: "MQTT CleanSession",
},
cli.StringFlag{
Name: "mongo, mgo",
Value: "mongodb://127.0.0.1:27017",
Usage: "MongoDB连接url",
},
},
Action: func(ctx *cli.Context) {
cfg := &publish.Config{
ExecNum: ctx.Int("ExecNum"),
Interval: ctx.Int("Interval"),
UserInterval: ctx.Int("UserInterval"),
UserGroupInterval: ctx.Int("UserGroupInterval"),
SendPacketStoreNum: ctx.Int("SendPacketStoreNum"),
SendPacketBucketNum: ctx.Int("SendPacketBucketNum"),
ReceivePacketStoreNum: ctx.Int("ReceivePacketStoreNum"),
ReceivePacketBucketNum: ctx.Int("ReceivePacketBucketNum"),
IsStore: ctx.Bool("IsStore"),
Network: ctx.String("Network"),
Address: ctx.String("Address"),
Qos: byte(ctx.Int("QOS")),
UserName: ctx.String("UserName"),
Password: ctx.String("Password"),
CleanSession: ctx.Bool("CleanSession"),
KeepAlive: ctx.Int("KeepAlive"),
MongoUrl: ctx.String("mongo"),
}
if ctx.Int("AutoReconnect") == 1 {
cfg.AutoReconnect = true
}
publish.Pub(cfg)
},
})
app.Commands = append(app.Commands, cli.Command{
Name: "clear",
Aliases: []string{"c"},
Usage: "清除数据",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "generate, gen",
Usage: "清除群组及用户基础数据",
},
cli.BoolFlag{
Name: "publish, pub",
Usage: "清除发布及接收的包数据",
},
cli.StringFlag{
Name: "mongo, mgo",
Value: "mongodb://127.0.0.1:27017",
Usage: "MongoDB连接url",
},
},
Action: func(ctx *cli.Context) {
cfg := clear.Config{
Gen: ctx.Bool("generate"),
Pub: ctx.Bool("publish"),
MongoUrl: ctx.String("mongo"),
}
clear.Clear(cfg)
},
})
app.Commands = append(app.Commands, cli.Command{
Name: "collect",
Usage: "汇总接收的包数据",
Flags: []cli.Flag{
cli.StringFlag{
Name: "Mongo, mgo",
Value: "mongodb://127.0.0.1:27017",
Usage: "MongoDB连接url",
},
},
Action: func(ctx *cli.Context) {
cfg := collect.Config{
MongoUrl: ctx.String("Mongo"),
}
collect.ExecCollect(cfg)
},
})
app.Run(os.Args)
}