mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-08 21:43:07 +02:00
Guard agains erlang:system_info(logical_processors) not always returning number
This commit is contained in:
parent
f4959c8b28
commit
6fd4315a0c
|
@ -99,10 +99,7 @@ worker_name(Pool, N) ->
|
||||||
-spec pool_size(binary()) -> pos_integer().
|
-spec pool_size(binary()) -> pos_integer().
|
||||||
pool_size(Host) ->
|
pool_size(Host) ->
|
||||||
case ejabberd_option:extauth_pool_size(Host) of
|
case ejabberd_option:extauth_pool_size(Host) of
|
||||||
undefined ->
|
undefined -> misc:logical_processors();
|
||||||
try erlang:system_info(logical_processors)
|
|
||||||
catch _:_ -> 1
|
|
||||||
end;
|
|
||||||
Size ->
|
Size ->
|
||||||
Size
|
Size
|
||||||
end.
|
end.
|
||||||
|
|
14
src/misc.erl
14
src/misc.erl
|
@ -42,7 +42,8 @@
|
||||||
is_mucsub_message/1, best_match/2, pmap/2, peach/2, format_exception/4,
|
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,
|
get_my_ipv4_address/0, get_my_ipv6_address/0, parse_ip_mask/1,
|
||||||
crypto_hmac/3, crypto_hmac/4, uri_parse/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
|
%% Deprecated functions
|
||||||
-export([decode_base64/1, encode_base64/1]).
|
-export([decode_base64/1, encode_base64/1]).
|
||||||
|
@ -451,9 +452,16 @@ best_match(Pattern, Opts) ->
|
||||||
end, #{}, Opts),
|
end, #{}, Opts),
|
||||||
element(2, lists:min(Ds)).
|
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].
|
-spec pmap(fun((T1) -> T2), [T1]) -> [T2].
|
||||||
pmap(Fun, [_,_|_] = List) ->
|
pmap(Fun, [_,_|_] = List) ->
|
||||||
case erlang:system_info(logical_processors) of
|
case logical_processors() of
|
||||||
1 -> lists:map(Fun, List);
|
1 -> lists:map(Fun, List);
|
||||||
_ ->
|
_ ->
|
||||||
Self = self(),
|
Self = self(),
|
||||||
|
@ -477,7 +485,7 @@ pmap(Fun, List) ->
|
||||||
|
|
||||||
-spec peach(fun((T) -> any()), [T]) -> ok.
|
-spec peach(fun((T) -> any()), [T]) -> ok.
|
||||||
peach(Fun, [_,_|_] = List) ->
|
peach(Fun, [_,_|_] = List) ->
|
||||||
case erlang:system_info(logical_processors) of
|
case logical_processors() of
|
||||||
1 -> lists:foreach(Fun, List);
|
1 -> lists:foreach(Fun, List);
|
||||||
_ ->
|
_ ->
|
||||||
Self = self(),
|
Self = self(),
|
||||||
|
|
|
@ -166,7 +166,7 @@ reload(ServerHost, NewOpts, OldOpts) ->
|
||||||
fun(I) ->
|
fun(I) ->
|
||||||
?GEN_SERVER:cast(procname(ServerHost, I),
|
?GEN_SERVER:cast(procname(ServerHost, I),
|
||||||
{reload, AddHosts, DelHosts, NewHosts})
|
{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),
|
load_permanent_rooms(AddHosts, ServerHost, NewOpts),
|
||||||
shutdown_rooms(ServerHost, DelHosts, OldRMod),
|
shutdown_rooms(ServerHost, DelHosts, OldRMod),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
|
@ -193,7 +193,7 @@ procname(Host, I) when is_integer(I) ->
|
||||||
<<(atom_to_binary(?MODULE, latin1))/binary, "_", Host/binary,
|
<<(atom_to_binary(?MODULE, latin1))/binary, "_", Host/binary,
|
||||||
"_", (integer_to_binary(I))/binary>>, utf8);
|
"_", (integer_to_binary(I))/binary>>, utf8);
|
||||||
procname(Host, RoomHost) ->
|
procname(Host, RoomHost) ->
|
||||||
Cores = erlang:system_info(logical_processors),
|
Cores = misc:logical_processors(),
|
||||||
I = erlang:phash2(RoomHost, Cores) + 1,
|
I = erlang:phash2(RoomHost, Cores) + 1,
|
||||||
procname(Host, I).
|
procname(Host, I).
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ procname(Host) ->
|
||||||
%%% Supervisor callbacks
|
%%% Supervisor callbacks
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
init([Host]) ->
|
init([Host]) ->
|
||||||
Cores = erlang:system_info(logical_processors),
|
Cores = misc:logical_processors(),
|
||||||
Specs = lists:foldl(
|
Specs = lists:foldl(
|
||||||
fun(I, Acc) ->
|
fun(I, Acc) ->
|
||||||
[#{id => mod_muc:procname(Host, I),
|
[#{id => mod_muc:procname(Host, I),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user