Adapt max-heap-size to Arch-32 systems

The erlang:process_flag(max_heap_size, MaxHeapSize) can only set a MaxHeapSize of `small integer`, which is smaller than 2^59 on 64-bit systems, and 2^27 on 32-bit systems.
This commit is contained in:
terry-xiaoyu 2019-05-07 15:24:45 +08:00 committed by Shawn
parent b4c659fb54
commit a1eb7ca7d2
3 changed files with 33 additions and 9 deletions

View File

@ -556,7 +556,11 @@ zone.external.force_gc_policy = 1000|1MB
## of queued MQTT messages of QoS 1 and 2.
##
## Numbers delimited by `|'. Zero or negative is to disable.
zone.external.force_shutdown_policy = 10000|1024MB
##
## Default:
## - 8000|800MB on ARCH_64 system
## - 1000|100MB on ARCH_32 sytem
## zone.external.force_shutdown_policy = 8000|800MB
## Maximum MQTT packet size allowed.
##

View File

@ -850,7 +850,7 @@ end}.
%% of queued MQTT messages of QoS 1 and 2.
%% Zero or negative is to disable.
{mapping, "zone.$name.force_shutdown_policy", "emqx.zones", [
{default, "0 | 0MB"},
{default, "default"},
{datatype, string}
]}.
@ -899,15 +899,34 @@ end}.
count => list_to_integer(Count)}
end,
{force_gc_policy, GcPolicy};
("force_shutdown_policy", "default") ->
{DefaultLen, DefaultSiz} =
case erlang:system_info(wordsize) of
8 -> % arch_64
{8000, cuttlefish_bytesize:parse("800MB")};
4 -> % arch_32
{1000, cuttlefish_bytesize:parse("100MB")}
end,
{force_shutdown_policy, #{message_queue_len => DefaultLen,
max_heap_size => DefaultSiz}};
("force_shutdown_policy", Val) ->
[Len, Siz] = string:tokens(Val, "| "),
ShutdownPolicy = case cuttlefish_bytesize:parse(Siz) of
{error, Reason} ->
error(Reason);
Siz1 ->
#{message_queue_len => list_to_integer(Len),
max_heap_size => Siz1}
end,
MaxSiz = case erlang:system_info(wordsize) of
8 -> % arch_64
(1 bsl 59) - 1;
4 -> % arch_32
(1 bsl 27) - 1
end,
ShutdownPolicy =
case cuttlefish_bytesize:parse(Siz) of
{error, Reason} ->
error(Reason);
Siz1 when Siz1 > MaxSiz ->
cuttlefish:invalid(io_lib:format("force_shutdown_policy: heap-size ~s is too large", [Siz]));
Siz1 ->
#{message_queue_len => list_to_integer(Len),
max_heap_size => Siz1}
end,
{force_shutdown_policy, ShutdownPolicy};
("mqueue_priorities", Val) ->
case Val of

View File

@ -160,6 +160,7 @@ websocket_init(#state{request = Req, options = Options}) ->
EnableStats = emqx_zone:get_env(Zone, enable_stats, true),
IdleTimout = emqx_zone:get_env(Zone, idle_timeout, 30000),
emqx_logger:set_metadata_peername(esockd_net:format(Peername)),
ok = emqx_misc:init_proc_mng_policy(Zone),
{ok, #state{peername = Peername,
sockname = Sockname,
parse_state = ParserState,