Basically, a program illustrating the back pressure problem mentioned in http://erlang.org/pipermail/erlang-questions/2014-November/081843.html

Run it using erl +S1 -noshell -eval 'back_pressure:main(0), halt(0).. In htop, it shows unbounded memory grow (due to the growing of unbounded mailbox). Nonsuprisingly, after removing sleep, the memeory stays constant.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-module(back_pressure).
-mode(compile).
-compile(export_all).

consumer() ->
receive _ -> ok end,
timer:sleep(1000),
consumer().

producer(C) ->
C ! 0,
producer(C).

main(_) ->
C = spawn(fun consumer/0),
producer(C),
ok.