perf(emqx_router): optimise trans result receive
This commit is contained in:
parent
84e032f2e1
commit
eeffc209df
|
@ -271,24 +271,20 @@ maybe_trans(Fun, Args) ->
|
||||||
trans(Fun, Args) ->
|
trans(Fun, Args) ->
|
||||||
%% trigger selective receive optimization of compiler,
|
%% trigger selective receive optimization of compiler,
|
||||||
%% ideal for handling bursty traffic.
|
%% ideal for handling bursty traffic.
|
||||||
Ref = erlang:make_ref(),
|
{_, RefMon} = spawn_monitor(
|
||||||
Owner = self(),
|
|
||||||
{WPid, RefMon} = spawn_monitor(
|
|
||||||
fun() ->
|
fun() ->
|
||||||
Res = case mnesia:transaction(Fun, Args) of
|
Res = case mnesia:transaction(Fun, Args) of
|
||||||
{atomic, Ok} -> Ok;
|
{atomic, Ok} -> Ok;
|
||||||
{aborted, Reason} -> {error, Reason}
|
{aborted, Reason} -> {error, Reason}
|
||||||
end,
|
end,
|
||||||
Owner ! {Ref, Res}
|
exit({shutdown, Res})
|
||||||
end),
|
end),
|
||||||
receive
|
receive
|
||||||
{Ref, TransRes} ->
|
{'DOWN', RefMon, process, _, Info} ->
|
||||||
receive
|
case Info of
|
||||||
{'DOWN', RefMon, process, WPid, normal} -> ok
|
{shutdown, Res} -> Res;
|
||||||
end,
|
_ -> {error, {trans_crash, Info}}
|
||||||
TransRes;
|
end
|
||||||
{'DOWN', RefMon, process, WPid, Info} ->
|
|
||||||
{error, {trans_crash, Info}}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
lock_router() ->
|
lock_router() ->
|
||||||
|
|
Loading…
Reference in New Issue