Add emqttd_gc:maybe_force_gc/3 API and tune the min hibernate interval

This commit is contained in:
Feng Lee 2017-03-13 15:36:58 +08:00
parent 6557dbe967
commit d099d0b53c
3 changed files with 10 additions and 6 deletions

View File

@ -127,7 +127,7 @@ do_init(Conn, Env, Peername) ->
force_gc_count = ForceGcCount}), force_gc_count = ForceGcCount}),
IdleTimout = get_value(client_idle_timeout, Env, 30000), IdleTimout = get_value(client_idle_timeout, Env, 30000),
gen_server2:enter_loop(?MODULE, [], State, self(), IdleTimout, gen_server2:enter_loop(?MODULE, [], State, self(), IdleTimout,
{backoff, 1000, 1000, 10000}). {backoff, 2000, 2000, 20000}).
send_fun(Conn, Peername) -> send_fun(Conn, Peername) ->
Self = self(), Self = self(),
@ -377,6 +377,7 @@ shutdown(Reason, State) ->
stop(Reason, State) -> stop(Reason, State) ->
{stop, Reason, State}. {stop, Reason, State}.
gc(State) -> gc(State = #client_state{connection = Conn}) ->
emqttd_gc:maybe_force_gc(#client_state.force_gc_count, State). Cb = fun() -> Conn:gc() end,
emqttd_gc:maybe_force_gc(#client_state.force_gc_count, State, Cb).

View File

@ -20,7 +20,8 @@
-author("Feng Lee <feng@emqtt.io>"). -author("Feng Lee <feng@emqtt.io>").
-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()). -spec(conn_max_gc_count() -> integer()).
conn_max_gc_count() -> conn_max_gc_count() ->
@ -38,9 +39,11 @@ reset_conn_gc_count(Pos, State) ->
end. end.
maybe_force_gc(Pos, State) -> maybe_force_gc(Pos, State) ->
maybe_force_gc(Pos, State, fun() -> ok end).
maybe_force_gc(Pos, State, Cb) ->
case element(Pos, State) of case element(Pos, State) of
undefined -> State; undefined -> State;
I when I =< 0 -> garbage_collect(), I when I =< 0 -> Cb(), garbage_collect(),
reset_conn_gc_count(Pos, State); reset_conn_gc_count(Pos, State);
I -> setelement(Pos, State, I - 1) I -> setelement(Pos, State, I - 1)
end. end.

View File

@ -104,7 +104,7 @@ init([Env, WsPid, Req, ReplyChannel]) ->
proto_state = ProtoState, proto_state = ProtoState,
enable_stats = EnableStats, enable_stats = EnableStats,
force_gc_count = ForceGcCount}, force_gc_count = ForceGcCount},
IdleTimeout, {backoff, 1000, 1000, 10000}, ?MODULE}. IdleTimeout, {backoff, 2000, 2000, 20000}, ?MODULE}.
prioritise_call(Msg, _From, _Len, _State) -> prioritise_call(Msg, _From, _Len, _State) ->
case Msg of info -> 10; stats -> 10; state -> 10; _ -> 5 end. case Msg of info -> 10; stats -> 10; state -> 10; _ -> 5 end.