Browse Source

perf(emqx_connection): no priority receive

Prior to this change the main message receive loop of emqx_connection
is a priority receive which selects system messages and parent EXIT
signals prior to other message.
This accidental (not intended) design may cause the receive operation
to scan potentially large mail box.
Zaiming Shi 5 years ago
parent
commit
6e1a55e9ed
1 changed files with 8 additions and 5 deletions
  1. 8 5
      src/emqx_connection.erl

+ 8 - 5
src/emqx_connection.erl

@@ -269,17 +269,20 @@ exit_on_sock_error(Reason) ->
 
 
 recvloop(Parent, State = #state{idle_timeout = IdleTimeout}) ->
 recvloop(Parent, State = #state{idle_timeout = IdleTimeout}) ->
     receive
     receive
-        {system, From, Request} ->
-            sys:handle_system_msg(Request, From, Parent, ?MODULE, [], State);
-        {'EXIT', Parent, Reason} ->
-            terminate(Reason, State);
         Msg ->
         Msg ->
-            process_msg([Msg], Parent, ensure_stats_timer(IdleTimeout, State))
+            handle_recv(Msg, Parent, State)
     after
     after
         IdleTimeout + 100 ->
         IdleTimeout + 100 ->
             hibernate(Parent, cancel_stats_timer(State))
             hibernate(Parent, cancel_stats_timer(State))
     end.
     end.
 
 
+handle_recv({system, From, Request}, Parent, State) ->
+    sys:handle_system_msg(Request, From, Parent, ?MODULE, [], State);
+handle_recv({'EXIT', Parent, Reason}, Parent, State) ->
+    terminate(Reason, State);
+handle_recv(Msg, Parent, State = #state{idle_timeout = IdleTimeout}) ->
+    process_msg([Msg], Parent, ensure_stats_timer(IdleTimeout, State)).
+
 hibernate(Parent, State) ->
 hibernate(Parent, State) ->
     proc_lib:hibernate(?MODULE, wakeup_from_hib, [Parent, State]).
     proc_lib:hibernate(?MODULE, wakeup_from_hib, [Parent, State]).