[erlang-questions] How do mailboxes relate to reduction counts?

Dmytro Lytovchenko <>
Sun Mar 5 20:07:10 CET 2017


Increased cost to send to larger mailboxes is a sort of simple approach to
work balancing. The idea is that if mailbox of some process grows, we
should (naively) try and skew scheduling in such a way so it gets more
processing time to clean up that mailbox. So we increase the cost of
sending to it, and this makes senders schedule out faster and wait for
their turn longer (as they get shorter time to run). This in theory might
make the "busy" process with the large mailbox get more CPU and fix the
problem faster.

Of course this *naive *approach won't work if the mailbox grows because the
receiver ignores new messages. Such system is sick and must be debugged and
code must be modified so that extra messages are flushed (dropped).
This is *artificial
*feature, as sending is a very cheap operation.

Increased cost of receive is another thing, and indeed it depends on how
many instructions are executed to scan and find the right message in *selective
*receive.

2017-03-05 16:11 GMT+01:00 Sasha Fonseca <>:

> I’ve read the following blog post (http://jlouisramblings.
> blogspot.pt/2013/01/how-erlang-does-scheduling.html), and it has the
> following excerpt which got me thinking:
>
> *Both processes and ports have a "reduction budget" of 2000 reductions.
> Any operation in the system costs reductions. This includes function calls
> in loops, calling built-in-functions (BIFs), garbage collecting heaps of
> that process[n1], storing/reading from ETS, sending messages (The size of
> the recipients mailbox counts, large mailboxes are more expensive to send
> to). *
>
> I’m wondering how does the size of a process’s mailbox relates the
> reduction count? Is it due to each message having to be matched against
> several message patterns in a case condition, for example? Also how large
> would the mailbox have to be to noticed any kind of impact in, let’s say, a
> server process?
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170305/8d8d01d9/attachment.html>


More information about the erlang-questions mailing list