|
@@ -469,20 +469,18 @@ websocket_handle({Frame, _}, State) ->
|
|
|
websocket_info({call, From, Req}, State) ->
|
|
websocket_info({call, From, Req}, State) ->
|
|
|
handle_call(From, Req, State);
|
|
handle_call(From, Req, State);
|
|
|
websocket_info({cast, rate_limit}, State) ->
|
|
websocket_info({cast, rate_limit}, State) ->
|
|
|
- Stats = #{
|
|
|
|
|
- cnt => emqx_pd:reset_counter(incoming_pubs),
|
|
|
|
|
- oct => emqx_pd:reset_counter(incoming_bytes)
|
|
|
|
|
- },
|
|
|
|
|
- NState = postpone({check_gc, Stats}, State),
|
|
|
|
|
- return(ensure_rate_limit(Stats, NState));
|
|
|
|
|
|
|
+ Cnt = emqx_pd:reset_counter(incoming_pubs),
|
|
|
|
|
+ Oct = emqx_pd:reset_counter(incoming_bytes),
|
|
|
|
|
+ NState = postpone({check_gc, Cnt, Oct}, State),
|
|
|
|
|
+ return(ensure_rate_limit(NState));
|
|
|
websocket_info({cast, Msg}, State) ->
|
|
websocket_info({cast, Msg}, State) ->
|
|
|
handle_info(Msg, State);
|
|
handle_info(Msg, State);
|
|
|
websocket_info({incoming, Packet}, State) ->
|
|
websocket_info({incoming, Packet}, State) ->
|
|
|
handle_incoming(Packet, State);
|
|
handle_incoming(Packet, State);
|
|
|
websocket_info({outgoing, Packets}, State) ->
|
|
websocket_info({outgoing, Packets}, State) ->
|
|
|
return(enqueue(Packets, State));
|
|
return(enqueue(Packets, State));
|
|
|
-websocket_info({check_gc, Stats}, State) ->
|
|
|
|
|
- return(check_oom(run_gc(Stats, State)));
|
|
|
|
|
|
|
+websocket_info({check_gc, Cnt, Oct}, State) ->
|
|
|
|
|
+ return(check_oom(run_gc(Cnt, Oct, State)));
|
|
|
websocket_info(
|
|
websocket_info(
|
|
|
Deliver = {deliver, _Topic, _Msg},
|
|
Deliver = {deliver, _Topic, _Msg},
|
|
|
State = #state{active_n = ActiveN}
|
|
State = #state{active_n = ActiveN}
|
|
@@ -601,15 +599,15 @@ handle_timeout(TRef, TMsg, State) ->
|
|
|
%% Ensure rate limit
|
|
%% Ensure rate limit
|
|
|
%%--------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
|
|
-ensure_rate_limit(_Stats, State) ->
|
|
|
|
|
|
|
+ensure_rate_limit(State) ->
|
|
|
State.
|
|
State.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------
|
|
|
%% Run GC, Check OOM
|
|
%% Run GC, Check OOM
|
|
|
%%--------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
|
|
-run_gc(Stats, State = #state{gc_state = GcSt}) ->
|
|
|
|
|
- case ?ENABLED(GcSt) andalso emqx_gc:run(Stats, GcSt) of
|
|
|
|
|
|
|
+run_gc(Cnt, Oct, State = #state{gc_state = GcSt}) ->
|
|
|
|
|
+ case ?ENABLED(GcSt) andalso emqx_gc:run(Cnt, Oct, GcSt) of
|
|
|
false -> State;
|
|
false -> State;
|
|
|
{_IsGC, GcSt1} -> State#state{gc_state = GcSt1}
|
|
{_IsGC, GcSt1} -> State#state{gc_state = GcSt1}
|
|
|
end.
|
|
end.
|
|
@@ -694,11 +692,9 @@ handle_outgoing(Packets, State = #state{active_n = ActiveN, piggyback = Piggybac
|
|
|
NState =
|
|
NState =
|
|
|
case emqx_pd:get_counter(outgoing_pubs) > ActiveN of
|
|
case emqx_pd:get_counter(outgoing_pubs) > ActiveN of
|
|
|
true ->
|
|
true ->
|
|
|
- Stats = #{
|
|
|
|
|
- cnt => emqx_pd:reset_counter(outgoing_pubs),
|
|
|
|
|
- oct => emqx_pd:reset_counter(outgoing_bytes)
|
|
|
|
|
- },
|
|
|
|
|
- postpone({check_gc, Stats}, State);
|
|
|
|
|
|
|
+ Cnt = emqx_pd:reset_counter(outgoing_pubs),
|
|
|
|
|
+ Oct = emqx_pd:reset_counter(outgoing_bytes),
|
|
|
|
|
+ postpone({check_gc, Cnt, Oct}, State);
|
|
|
false ->
|
|
false ->
|
|
|
State
|
|
State
|
|
|
end,
|
|
end,
|