Erlang Message Strokes

How does the message loop work in erlang, are they synchronized during message processing?

As I understand it, the loop will start by β€œreceiving” the message, and then do something and hit another loop iteration.

So, should this be sync? is not it?

If several clients send messages in the same message cycle, all these messages are queued and executed one after another or?

To process multiple messages in parallel, you have to create multiple message cycles in different processes, right?

Or didn’t I understand all this?

+6
parallel-processing erlang
source share
2 answers

Sending a message is asynchronous. Processing the message synchronously - one message is received at a time - because each process has its own (and only one) mailbox.

+9
source share

From the manual ( Erlang concurrency

Each process has its own input queue for received messages. Received new messages are placed at the end of the queue. When the process is receiving, the first message in the queue is mapped to the first template in the reception, if it matches, the message is removed from the queue and actions corresponding to the template are performed.
However, if the first pattern does not match, the second pattern is checked, if it matches the message, it is removed from the queue, and actions corresponding to the second pattern are performed. If the second sample does not correspond to three, it is checked and so on until there is no more template for testing. If there are no more templates, the first message will be stored in the queue, and instead we will try the second message. If this matches any template, the corresponding actions are performed, and the second message is removed from the queue (keeping the first message and any other messages in the queue). If the second message does not match, we will try the third message and so on until we reach the end of the queue. If we reach the end of the queue, the process blocks (stops execution) and waits until a new message is received, and this procedure is repeated.
Of course, the Erlang implementation is β€œsmart” and minimizes the number of times each message is checked against patterns in each reception.

So you can create prios with regex, but concurrency is done through several processes.

+4
source share

All Articles