Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

perf(gateway): sample the process scan without sorting every pid

Hampus7837698d805a
diff --git a/fluxer_gateway/src/gateway/gateway_periodic_gc.erl b/fluxer_gateway/src/gateway/gateway_periodic_gc.erl
index 017bd09b6..ce2ec3c80 100644
--- a/fluxer_gateway/src/gateway/gateway_periodic_gc.erl
+++ b/fluxer_gateway/src/gateway/gateway_periodic_gc.erl
@@ -201,12 +201,13 @@ reap_stuck_spawns(Progress) ->
-spec process_scan_pids() -> [pid()].
process_scan_pids() ->
Pids = erlang:processes(),
- case length(Pids) =< ?MAX_PROCESS_SCAN of
+ Count = length(Pids),
+ case Count =< ?MAX_PROCESS_SCAN of
true ->
Pids;
false ->
- Shuffled = [P || {_, P} <- lists:sort([{rand:uniform(), P} || P <- Pids])],
- lists:sublist(Shuffled, ?MAX_PROCESS_SCAN)
+ {Front, Back} = lists:split(rand:uniform(Count) - 1, Pids),
+ lists:sublist(Back ++ Front, ?MAX_PROCESS_SCAN)
end.
-spec reap_if_stuck(pid(), stuck_progress(), stuck_progress()) -> stuck_progress().
@@ -294,9 +295,7 @@ is_known_stuck_function(_) -> false.
reset_drifted_counters() ->
try persistent_term:get(gateway_concurrency_counters) of
Ref ->
- SessionMax = gateway_rollout_config:max_concurrent_session_starts(),
GuildMax = gateway_rollout_config:max_concurrent_guild_starts(),
- check_counter(Ref, 1, SessionMax, "session"),
check_counter(Ref, 2, GuildMax, "guild")
catch
error:badarg -> ok