Merge pull request #1905 from emqx/Fix-for-mqtt-sn

Fix the init_proc_mng_policy bug
This commit is contained in:
turtleDeng 2018-11-05 22:30:51 +08:00 committed by GitHub
commit 0a337cbcb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 14 deletions

View File

@ -165,7 +165,8 @@ init_limiter({Rate, Burst}) ->
esockd_rate_limit:new(Rate, Burst). esockd_rate_limit:new(Rate, Burst).
send_fun(Transport, Socket, Peername) -> send_fun(Transport, Socket, Peername) ->
fun(Data) -> fun(Packet, Options) ->
Data = emqx_frame:serialize(Packet, Options),
try Transport:async_send(Socket, Data) of try Transport:async_send(Socket, Data) of
ok -> ok ->
?LOG(debug, "SEND ~p", [iolist_to_binary(Data)], #state{peername = Peername}), ?LOG(debug, "SEND ~p", [iolist_to_binary(Data)], #state{peername = Peername}),
@ -408,4 +409,3 @@ maybe_gc(#state{}, {publish, _PacketId, #message{payload = Payload}}) ->
ok = emqx_gc:inc(1, Oct); ok = emqx_gc:inc(1, Oct);
maybe_gc(_, _) -> maybe_gc(_, _) ->
ok. ok.

View File

@ -634,4 +634,3 @@ fixqos(?PUBREL, 0) -> 1;
fixqos(?SUBSCRIBE, 0) -> 1; fixqos(?SUBSCRIBE, 0) -> 1;
fixqos(?UNSUBSCRIBE, 0) -> 1; fixqos(?UNSUBSCRIBE, 0) -> 1;
fixqos(_Type, QoS) -> QoS. fixqos(_Type, QoS) -> QoS.

View File

@ -62,9 +62,11 @@ proc_stats(Pid) ->
-define(DISABLED, 0). -define(DISABLED, 0).
init_proc_mng_policy(undefined) -> ok;
init_proc_mng_policy(Zone) -> init_proc_mng_policy(Zone) ->
#{max_heap_size := MaxHeapSizeInBytes} = ShutdownPolicy = #{max_heap_size := MaxHeapSizeInBytes}
emqx_zone:get_env(Zone, force_shutdown_policy), = ShutdownPolicy
= emqx_zone:get_env(Zone, force_shutdown_policy),
MaxHeapSize = MaxHeapSizeInBytes div erlang:system_info(wordsize), MaxHeapSize = MaxHeapSizeInBytes div erlang:system_info(wordsize),
_ = erlang:process_flag(max_heap_size, MaxHeapSize), % zero is discarded _ = erlang:process_flag(max_heap_size, MaxHeapSize), % zero is discarded
erlang:put(force_shutdown_policy, ShutdownPolicy), erlang:put(force_shutdown_policy, ShutdownPolicy),
@ -106,4 +108,3 @@ is_enabled(Max) -> is_integer(Max) andalso Max > ?DISABLED.
proc_info(Key) -> proc_info(Key) ->
{Key, Value} = erlang:process_info(self(), Key), {Key, Value} = erlang:process_info(self(), Key),
Value. Value.

View File

@ -586,13 +586,10 @@ deliver({disconnect, _ReasonCode}, PState) ->
-spec(send(emqx_mqtt_types:packet(), state()) -> {ok, state()} | {error, term()}). -spec(send(emqx_mqtt_types:packet(), state()) -> {ok, state()} | {error, term()}).
send(Packet = ?PACKET(Type), PState = #pstate{proto_ver = Ver, sendfun = SendFun}) -> send(Packet = ?PACKET(Type), PState = #pstate{proto_ver = Ver, sendfun = SendFun}) ->
trace(send, Packet, PState), trace(send, Packet, PState),
case SendFun(emqx_frame:serialize(Packet, #{version => Ver})) of case SendFun(Packet, #{version => Ver}) of
ok -> ok ->
emqx_metrics:sent(Packet), emqx_metrics:sent(Packet),
{ok, inc_stats(send, Type, PState)}; {ok, inc_stats(send, Type, PState)};
{binary, _Data} ->
emqx_metrics:sent(Packet),
{ok, inc_stats(send, Type, PState)};
{error, Reason} -> {error, Reason} ->
{error, Reason} {error, Reason}
end. end.

View File

@ -144,12 +144,14 @@ websocket_init(#state{request = Req, options = Options}) ->
idle_timeout = IdleTimout}}. idle_timeout = IdleTimout}}.
send_fun(WsPid) -> send_fun(WsPid) ->
fun(Data) -> fun(Packet, Options) ->
Data = emqx_frame:serialize(Packet, Options),
BinSize = iolist_size(Data), BinSize = iolist_size(Data),
emqx_metrics:inc('bytes/sent', BinSize), emqx_metrics:inc('bytes/sent', BinSize),
put(send_oct, get(send_oct) + BinSize), put(send_oct, get(send_oct) + BinSize),
put(send_cnt, get(send_cnt) + 1), put(send_cnt, get(send_cnt) + 1),
WsPid ! {binary, iolist_to_binary(Data)} WsPid ! {binary, iolist_to_binary(Data)},
ok
end. end.
stat_fun() -> stat_fun() ->
@ -299,4 +301,3 @@ stop(Error, State) ->
wsock_stats() -> wsock_stats() ->
[{Key, get(Key)} || Key <- ?SOCK_STATS]. [{Key, get(Key)} || Key <- ?SOCK_STATS].