Guard agains erlang:system_info(logical_processors) not always returning number

This commit is contained in:
Paweł Chmielowski 2022-04-28 09:51:40 +02:00
parent f4959c8b28
commit 6fd4315a0c
4 changed files with 15 additions and 10 deletions

View File

@ -99,10 +99,7 @@ worker_name(Pool, N) ->
-spec pool_size(binary()) -> pos_integer().
pool_size(Host) ->
case ejabberd_option:extauth_pool_size(Host) of
undefined ->
try erlang:system_info(logical_processors)
catch _:_ -> 1
end;
undefined -> misc:logical_processors();
Size ->
Size
end.

View File

@ -42,7 +42,8 @@
is_mucsub_message/1, best_match/2, pmap/2, peach/2, format_exception/4,
get_my_ipv4_address/0, get_my_ipv6_address/0, parse_ip_mask/1,
crypto_hmac/3, crypto_hmac/4, uri_parse/1,
match_ip_mask/3, format_hosts_list/1, format_cycle/1, delete_dir/1]).
match_ip_mask/3, format_hosts_list/1, format_cycle/1, delete_dir/1,
logical_processors/0]).
%% Deprecated functions
-export([decode_base64/1, encode_base64/1]).
@ -451,9 +452,16 @@ best_match(Pattern, Opts) ->
end, #{}, Opts),
element(2, lists:min(Ds)).
-spec logical_processors() -> non_neg_integer().
logical_processors() ->
case erlang:system_info(logical_processors) of
unknown -> 1;
V -> V
end.
-spec pmap(fun((T1) -> T2), [T1]) -> [T2].
pmap(Fun, [_,_|_] = List) ->
case erlang:system_info(logical_processors) of
case logical_processors() of
1 -> lists:map(Fun, List);
_ ->
Self = self(),
@ -477,7 +485,7 @@ pmap(Fun, List) ->
-spec peach(fun((T) -> any()), [T]) -> ok.
peach(Fun, [_,_|_] = List) ->
case erlang:system_info(logical_processors) of
case logical_processors() of
1 -> lists:foreach(Fun, List);
_ ->
Self = self(),

View File

@ -166,7 +166,7 @@ reload(ServerHost, NewOpts, OldOpts) ->
fun(I) ->
?GEN_SERVER:cast(procname(ServerHost, I),
{reload, AddHosts, DelHosts, NewHosts})
end, lists:seq(1, erlang:system_info(logical_processors))),
end, lists:seq(1, misc:logical_processors())),
load_permanent_rooms(AddHosts, ServerHost, NewOpts),
shutdown_rooms(ServerHost, DelHosts, OldRMod),
lists:foreach(
@ -193,7 +193,7 @@ procname(Host, I) when is_integer(I) ->
<<(atom_to_binary(?MODULE, latin1))/binary, "_", Host/binary,
"_", (integer_to_binary(I))/binary>>, utf8);
procname(Host, RoomHost) ->
Cores = erlang:system_info(logical_processors),
Cores = misc:logical_processors(),
I = erlang:phash2(RoomHost, Cores) + 1,
procname(Host, I).

View File

@ -51,7 +51,7 @@ procname(Host) ->
%%% Supervisor callbacks
%%%===================================================================
init([Host]) ->
Cores = erlang:system_info(logical_processors),
Cores = misc:logical_processors(),
Specs = lists:foldl(
fun(I, Acc) ->
[#{id => mod_muc:procname(Host, I),