From d099d0b53cc5288f29ea9d8bd64f05899c73da42 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 13 Mar 2017 15:36:58 +0800 Subject: [PATCH 1/6] Add emqttd_gc:maybe_force_gc/3 API and tune the min hibernate interval --- src/emqttd_client.erl | 7 ++++--- src/emqttd_gc.erl | 7 +++++-- src/emqttd_ws_client.erl | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/emqttd_client.erl b/src/emqttd_client.erl index f8794cd92..88f14c2d6 100644 --- a/src/emqttd_client.erl +++ b/src/emqttd_client.erl @@ -127,7 +127,7 @@ do_init(Conn, Env, Peername) -> force_gc_count = ForceGcCount}), IdleTimout = get_value(client_idle_timeout, Env, 30000), gen_server2:enter_loop(?MODULE, [], State, self(), IdleTimout, - {backoff, 1000, 1000, 10000}). + {backoff, 2000, 2000, 20000}). send_fun(Conn, Peername) -> Self = self(), @@ -377,6 +377,7 @@ shutdown(Reason, State) -> stop(Reason, State) -> {stop, Reason, State}. -gc(State) -> - emqttd_gc:maybe_force_gc(#client_state.force_gc_count, State). +gc(State = #client_state{connection = Conn}) -> + Cb = fun() -> Conn:gc() end, + emqttd_gc:maybe_force_gc(#client_state.force_gc_count, State, Cb). diff --git a/src/emqttd_gc.erl b/src/emqttd_gc.erl index 04cdbf2d5..75545a77f 100644 --- a/src/emqttd_gc.erl +++ b/src/emqttd_gc.erl @@ -20,7 +20,8 @@ -author("Feng Lee "). --export([conn_max_gc_count/0, reset_conn_gc_count/2, maybe_force_gc/2]). +-export([conn_max_gc_count/0, reset_conn_gc_count/2, maybe_force_gc/2, + maybe_force_gc/3]). -spec(conn_max_gc_count() -> integer()). conn_max_gc_count() -> @@ -38,9 +39,11 @@ reset_conn_gc_count(Pos, State) -> end. maybe_force_gc(Pos, State) -> + maybe_force_gc(Pos, State, fun() -> ok end). +maybe_force_gc(Pos, State, Cb) -> case element(Pos, State) of undefined -> State; - I when I =< 0 -> garbage_collect(), + I when I =< 0 -> Cb(), garbage_collect(), reset_conn_gc_count(Pos, State); I -> setelement(Pos, State, I - 1) end. diff --git a/src/emqttd_ws_client.erl b/src/emqttd_ws_client.erl index 4fb57b6ad..4beb7bc40 100644 --- a/src/emqttd_ws_client.erl +++ b/src/emqttd_ws_client.erl @@ -104,7 +104,7 @@ init([Env, WsPid, Req, ReplyChannel]) -> proto_state = ProtoState, enable_stats = EnableStats, force_gc_count = ForceGcCount}, - IdleTimeout, {backoff, 1000, 1000, 10000}, ?MODULE}. + IdleTimeout, {backoff, 2000, 2000, 20000}, ?MODULE}. prioritise_call(Msg, _From, _Len, _State) -> case Msg of info -> 10; stats -> 10; state -> 10; _ -> 5 end. From 82bb7766ac0e3400487e528c9677a4197588b408 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 13 Mar 2017 15:55:00 +0800 Subject: [PATCH 2/6] Add env, maintainers, licenses properties --- src/emqttd.app.src | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/emqttd.app.src b/src/emqttd.app.src index c86af2a0a..3f0c2984c 100644 --- a/src/emqttd.app.src +++ b/src/emqttd.app.src @@ -1,8 +1,12 @@ {application, emqttd, [ - {description, "Erlang MQTT Broker"}, - {vsn, "2.1.0"}, - {modules, []}, - {registered, [emqttd_sup]}, - {applications, [kernel,stdlib,gproc,lager,esockd,mochiweb,lager_syslog]}, - {mod, {emqttd_app, []}} + {description, "Erlang MQTT Broker"}, + {vsn, "2.1.0"}, + {modules, []}, + {registered, [emqttd_sup]}, + {applications, [kernel,stdlib,gproc,lager,esockd,mochiweb,lager_syslog,pbkdf2]}, + {env, []}, + {mod, {emqttd_app, []}} + {maintainers, ["Feng Lee "]}, + {licenses, ["MIT"]}, + {links, [{"Github", "https://github.com/emqtt/emqttd"}]} ]}. From 1de9496b4ea5a26771ec261698c144aed9920c9a Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 13 Mar 2017 16:01:48 +0800 Subject: [PATCH 3/6] Upgrade Erlang/OTP to R19+ --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4cef5371..15834e620 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: erlang otp_release: - - 18.0 - - 18.1 - - 18.2.1 - - 18.3 + - 19.0 + - 19.1 + - 19.2 script: - make From 2e6e97b0064afc7e7b7e71fea759d81b1e127e19 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 13 Mar 2017 16:30:41 +0800 Subject: [PATCH 4/6] Fix the syntax error --- src/emqttd.app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emqttd.app.src b/src/emqttd.app.src index 3f0c2984c..d03a4d952 100644 --- a/src/emqttd.app.src +++ b/src/emqttd.app.src @@ -5,7 +5,7 @@ {registered, [emqttd_sup]}, {applications, [kernel,stdlib,gproc,lager,esockd,mochiweb,lager_syslog,pbkdf2]}, {env, []}, - {mod, {emqttd_app, []}} + {mod, {emqttd_app, []}}, {maintainers, ["Feng Lee "]}, {licenses, ["MIT"]}, {links, [{"Github", "https://github.com/emqtt/emqttd"}]} From b5446ceb4de715962bf50fa4f714f4f54265a815 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 13 Mar 2017 16:35:36 +0800 Subject: [PATCH 5/6] Change the 'ssl' to 'sslopts' --- test/emqttd_SUITE_data/emqttd.schema | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/emqttd_SUITE_data/emqttd.schema b/test/emqttd_SUITE_data/emqttd.schema index 156bc4874..530984383 100644 --- a/test/emqttd_SUITE_data/emqttd.schema +++ b/test/emqttd_SUITE_data/emqttd.schema @@ -710,7 +710,7 @@ end}. ConnOpts = Filter([{rate_limit, cuttlefish:conf_get(Key ++ ".rate_limit", Conf, undefined)}]), Opts = [{connopts, ConnOpts}, {sockopts, TcpOpts(Key)} | LisOpts(Key)], [{Name, Port, case Name =:= ssl orelse Name =:= https of - true -> [{ssl, SslOpts(Key)} | Opts]; + true -> [{sslopts, SslOpts(Key)} | Opts]; false -> Opts end}] end From ecbc1cf56b489665a125ec68e6e30180cdeccaaa Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 13 Mar 2017 16:51:46 +0800 Subject: [PATCH 6/6] Format the 'dep_' lines --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b35c84f88..cf1234a02 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,13 @@ NO_AUTOPATCH = cuttlefish DEPS = gproc lager esockd mochiweb lager_syslog pbkdf2 -dep_gproc = git https://github.com/uwiger/gproc -dep_getopt = git https://github.com/jcomellas/getopt v0.8.2 -dep_lager = git https://github.com/basho/lager master -dep_esockd = git https://github.com/emqtt/esockd emq20 -dep_mochiweb = git https://github.com/emqtt/mochiweb -dep_lager_syslog = git https://github.com/basho/lager_syslog -dep_pbkdf2 = git https://github.com/comtihon/erlang-pbkdf2.git 2.0.0 +dep_gproc = git https://github.com/uwiger/gproc +dep_getopt = git https://github.com/jcomellas/getopt v0.8.2 +dep_lager = git https://github.com/basho/lager master +dep_esockd = git https://github.com/emqtt/esockd emq20 +dep_mochiweb = git https://github.com/emqtt/mochiweb +dep_lager_syslog = git https://github.com/basho/lager_syslog +dep_pbkdf2 = git https://github.com/comtihon/erlang-pbkdf2.git 2.0.0 ERLC_OPTS += +'{parse_transform, lager_transform}'