aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorZandra <[email protected]>2016-05-04 09:09:49 +0200
committerZandra <[email protected]>2016-05-04 09:09:49 +0200
commit5127e472cb142b2fb6ff2ffd8bec8257da3ace6a (patch)
tree4d2b1453ba5ed428ff0b5c12f9cdf383b683d67f /lib
parentefb19c7d8edf92f268fe42df2ba47c329b98ec2f (diff)
parent0c2954dd7fa1923a26d7da05e366bca63d5fe53e (diff)
downloadotp-5127e472cb142b2fb6ff2ffd8bec8257da3ace6a.tar.gz
otp-5127e472cb142b2fb6ff2ffd8bec8257da3ace6a.tar.bz2
otp-5127e472cb142b2fb6ff2ffd8bec8257da3ace6a.zip
Merge branch 'zandra/optimize-rpc/OTP-13518'
* zandra/optimize-rpc/OTP-13518: use maps instead of gb_trees to optimize the rpc server let the spawned processes handle rpc replies Conflicts: lib/runtime_tools/test/dbg_SUITE.erl
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/src/rpc.erl39
-rw-r--r--lib/runtime_tools/test/dbg_SUITE.erl4
2 files changed, 14 insertions, 29 deletions
diff --git a/lib/kernel/src/rpc.erl b/lib/kernel/src/rpc.erl
index 6f9ce17c0c..21bff02214 100644
--- a/lib/kernel/src/rpc.erl
+++ b/lib/kernel/src/rpc.erl
@@ -63,7 +63,7 @@
%%------------------------------------------------------------------------
--type state() :: gb_trees:tree(pid(), {pid(), reference()}).
+-type state() :: map().
%%------------------------------------------------------------------------
@@ -91,7 +91,7 @@ stop(Rpc) ->
init([]) ->
process_flag(trap_exit, true),
- {ok, gb_trees:empty()}.
+ {ok, maps:new()}.
-spec handle_call(term(), term(), state()) ->
{'noreply', state()} |
@@ -130,29 +130,15 @@ handle_cast(_, S) ->
-spec handle_info(term(), state()) -> {'noreply', state()}.
+handle_info({'DOWN', _, process, Caller, normal}, S) ->
+ {noreply, maps:remove(Caller, S)};
handle_info({'DOWN', _, process, Caller, Reason}, S) ->
- case gb_trees:lookup(Caller, S) of
- {value, To} ->
- receive
- {Caller, {reply, Reply}} ->
- gen_server:reply(To, Reply)
- after 0 ->
- gen_server:reply(To, {badrpc, {'EXIT', Reason}})
- end,
- {noreply, gb_trees:delete(Caller, S)};
- none ->
- {noreply, S}
- end;
-handle_info({Caller, {reply, Reply}}, S) ->
- case gb_trees:lookup(Caller, S) of
- {value, To} ->
- receive
- {'DOWN', _, process, Caller, _} ->
- gen_server:reply(To, Reply),
- {noreply, gb_trees:delete(Caller, S)}
- end;
- none ->
- {noreply, S}
+ case maps:get(Caller, S, undefined) of
+ undefined ->
+ {noreply, S};
+ {_, _} = To ->
+ gen_server:reply(To, {badrpc, {'EXIT', Reason}}),
+ {noreply, maps:remove(Caller, S)}
end;
handle_info({From, {sbcast, Name, Msg}}, S) ->
_ = case catch Name ! Msg of %% use catch to get the printout
@@ -190,7 +176,6 @@ code_change(_, S, _) ->
%% Auxiliary function to avoid a false dialyzer warning -- do not inline
%%
handle_call_call(Mod, Fun, Args, Gleader, To, S) ->
- RpcServer = self(),
%% Spawn not to block the rpc server.
{Caller,_} =
erlang:spawn_monitor(
@@ -205,9 +190,9 @@ handle_call_call(Mod, Fun, Args, Gleader, To, S) ->
Result ->
Result
end,
- RpcServer ! {self(), {reply, Reply}}
+ gen_server:reply(To, Reply)
end),
- {noreply, gb_trees:insert(Caller, To, S)}.
+ {noreply, maps:put(Caller, To, S)}.
%% RPC aid functions ....
diff --git a/lib/runtime_tools/test/dbg_SUITE.erl b/lib/runtime_tools/test/dbg_SUITE.erl
index 6b6e35fc31..0777503ef7 100644
--- a/lib/runtime_tools/test/dbg_SUITE.erl
+++ b/lib/runtime_tools/test/dbg_SUITE.erl
@@ -167,8 +167,8 @@ distributed(Config) when is_list(Config) ->
{value, {matched, Node, 1}} = lists:keysearch(Node, 2, Z),
dbg:cn(Node),
dbg:tp(dbg,ln,[]),
- ok = rpc:call(Node, dbg, ltp, []),
- ok = rpc:call(Node, dbg, ln, []),
+ ok = rpc:block_call(Node, dbg, ltp, []),
+ ok = rpc:block_call(Node, dbg, ln, []),
ok = dbg:ln(),
S = self(),
{TraceSend, TraceCall} =