Erlang - how to limit the message queue or imitate it?

I'm doing the process now! Message, but as I searched the language a bit, the size of the message queue is limited only by memory. I have a process tree in which you can generate messages and boot to the root, and I need to limit the queue or switch to another way to do the same.

more, sometimes the process receives messages from one sheet, and sometimes from two leaves. In the second case, I need different final queues for the eave sheet.

+4
erlang message-queue
Jan 22 '10 at 21:45
source share
3 answers

There are no built-in mechanisms to limit the size of the message queue for a process.

A common solution to this problem in erlang is to introduce a flow control protocol between producer and consumer. It can be as simple as a sender waiting for a continue response before sending the next message. You can come up with more complex flow control protocols (windowing, ...), but often send / wait-response. The gen_server:call/2 protocol is a good request-response protocol and can be reused by looking at the code for gen_server and gen:call - it takes care of the many extreme cases that are possible.

Another approach is to pull messages through the system, rather than push them - in this case, the recipient asks the sender of the message when it is ready. Although, if you have external manufacturers that you cannot limit or limit enough, then you may not have this option.

+8
Jan 22 '10 at 23:28
source share

RabbitMQ implements this in the form of a credit flow. Additional information in this blog: http://videlalvaro.imtqy.com/2013/09/rabbitmq-internals-credit-flow-for-erlang-processes.html

+2
Nov 13 '13 at 19:54
source share

The classic way to handle your second case is to include in the Pid message the sending process. This is very common for erlang messages, which usually have a structure similar to {SendingPid,Data} . This allows the recipient to process both to see who sent the message, and using pattern matching in receive to choose which process they want to receive messages from.

Thus, erlang can multiplex messages from different senders in the same message queue and not force them to process all possible messages.

+1
Jan 26
source share



All Articles