forked from emqx/emqtt-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emqtt_bench_pub
executable file
·66 lines (61 loc) · 2.25 KB
/
emqtt_bench_pub
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
#! /usr/bin/env escript
%% -*- erlang -*-
%%! -pa ./ebin -pa deps/emqttc/ebin -pa deps/getopt/ebin -pa deps/gen_logger/ebin -pa deps/goldrush/ebin -pa deps/lager/ebin -smp true +K true +A 16 +P 200000 -env ERL_MAX_PORTS 100000 -env ERTS_MAX_PORTS 100000
-define(OPTS, [
{help, undefined, "help", boolean,
"help information"},
{host, $h, "host", {string, "localhost"},
"mqtt server hostname or IP address"},
{port, $p, "port", {integer, 1883},
"mqtt server port number"},
{count, $c, "count", {integer, 200},
"max count of clients"},
{interval, $i, "interval", {integer, 10},
"interval of connecting to the broker"},
{interval_of_msg, $I, "interval_of_msg", {integer, 1000},
"interval of publishing message(ms)"},
{username, $u, "username", string,
"username for connecting to server"},
{password, $P, "password", string,
"password for connecting to server"},
{topic, $t, "topic", string,
"topic subscribe, support %u, %c, %i variables"},
{size, $s, "size", {integer, 256},
"payload size"},
{qos, $q, "qos", {integer, 0},
"subscribe qos"},
{retain, $r, "retain", {boolean, false},
"retain message"},
{keepalive, $k, "keepalive", {integer, 300},
"keep alive in seconds"},
{clean, $C, "clean", {boolean, true},
"clean session"},
{ifaddr, undefined, "ifaddr", string,
"local ipaddress or interface address"}
]).
main(Argv) ->
{ok, {Opts, _Args}} = getopt:parse(?OPTS, Argv),
case proplists:get_value(help, Opts) of
true ->
usage(),
halt(0);
_ ->
ok
end,
require([count, topic], Opts),
emqtt_benchmark:main(pub, Opts).
require(Keys, Opts) ->
lists:foreach(fun(Opt) ->
case lists:keyfind(Opt, 1, Opts) of
false ->
io:format("Error: '~s' required~n", [Opt]),
usage(),
halt(1);
_ ->
ok
end
end, Keys).
usage() ->
ScriptPath = escript:script_name(),
Script = filename:basename(ScriptPath),
getopt:usage(?OPTS, Script).