Reputation: 605
I have a process that sits in a loop and receives commands.
receive
increase ->
...
decrease ->
...
after 5000 ->
...
end
But when I bombard it with thousands of messages it breaks down and receives these warnings.
Warning Message:
***WARNING*** Unexp msg {<0.106.0>,rec_acked}, info {running,
[{'_UserConnections',20}],
{ieval,3994,34,log,
clientLogging,
[20],
false}}
Is there anyway to handle this? And does it cause any issue?
Thank you for your answer!
Upvotes: 1
Views: 258
Reputation: 1626
This code is good just for example and practice, but don't run in production environment.
You should always receive all messages from process mailbox and select what you want after getting.
handle_message() ->
receive
Msg ->
handle_message(Msg)
after 5000 ->
handle_timeout()
end.
handle_message(increase) ->
...;
handle_message(decrease) ->
...;
handle_message(_) ->
%% Back to receiving loop
handle_message().
You should prevent filling process mailbox.
In production-ready application, often nobody uses receive
statement, often they use some standard codes which those codes handle receiving, timeouts, replies, hibernation, etc. we call those codes behavior, for example one of OTP standad behaviors is gen_server behavior
Because OTP behaviors are for general purposes if you need very efficient code for doing some special duty, you have to write something named Special process which should handle your own messages and Erlang system messages.
Upvotes: 3