File 4542-kernel-Use-async_dist-for-the-global-and-global_grou.patch of Package erlang
From b418637e610842a9e8f4ba8b8778363161fa39b4 Mon Sep 17 00:00:00 2001
From: Rickard Green <rickard@erlang.org>
Date: Wed, 22 Mar 2023 20:31:23 +0100
Subject: [PATCH 2/3] [kernel] Use async_dist for the global and global_group
servers
Prevent the global and global_group servers from getting blocked on distributed
send operations. The amount of signals sent by these servers are limited in
proportion to the amount of nodes in the cluster. A large cluster will even
with async_dist disabled be able to consume more memory than a small cluster
due to the distribution busy limit being per channel. With the async_dist
disabled you can also get into situations memory consumption grow out of
control due to the server being blocked on distributed send operations and not
being able to handle incoming requests.
---
lib/kernel/src/global.erl | 5 +----
lib/kernel/src/global_group.erl | 1 +
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/kernel/src/global.erl b/lib/kernel/src/global.erl
index 12b6667d71..28bd01d228 100644
--- a/lib/kernel/src/global.erl
+++ b/lib/kernel/src/global.erl
@@ -497,6 +497,7 @@ disconnect() ->
-spec init([]) -> {'ok', state()}.
init([]) ->
+ _ = process_flag(async_dist, true),
process_flag(trap_exit, true),
%% Monitor all 'nodeup'/'nodedown' messages of visible nodes.
@@ -2762,9 +2763,7 @@ inform_connection_loss(_Node, #state{}) ->
%%
gns_volatile_send(Node, Msg) ->
- OldAsyncDist = process_flag(async_dist, true),
_ = erlang:send({global_name_server, Node}, Msg, [noconnect]),
- _ = process_flag(async_dist, OldAsyncDist),
ok.
%%
@@ -2774,7 +2773,6 @@ gns_volatile_send(Node, Msg) ->
%%
gns_volatile_multicast(Msg, IgnoreNode, MinVer,
AlsoPend, #state{known = Known}) ->
- OldAsyncDist = process_flag(async_dist, true),
maps:foreach(fun (Node, Ver) when is_atom(Node),
Node =/= IgnoreNode,
Ver >= MinVer ->
@@ -2788,7 +2786,6 @@ gns_volatile_multicast(Msg, IgnoreNode, MinVer,
(_, _) ->
ok
end, Known),
- _ = process_flag(async_dist, OldAsyncDist),
ok.
is_node_potentially_known(Node, #state{known = Known}) ->
diff --git a/lib/kernel/src/global_group.erl b/lib/kernel/src/global_group.erl
index 4301e28ac0..0fa1854e9e 100644
--- a/lib/kernel/src/global_group.erl
+++ b/lib/kernel/src/global_group.erl
@@ -260,6 +260,7 @@ start_link() -> gen_server:start_link({local, global_group}, global_group,[],[])
stop() -> gen_server:call(global_group, stop, infinity).
init([]) ->
+ _ = process_flag(async_dist, true),
process_flag(priority, max),
ok = net_kernel:monitor_nodes(true, #{connection_id => true}),
put(registered_names, [undefined]),
--
2.35.3