erlang/otp — pull request #481 by evanmcc (2014-09-23 01:16:13+00:00)
Title: Add process flag to allow bounded message queue lengths

Many high-volume Erlang applications find that they need to limit the
maximum length of message queues for certain processes, either to add
back-pressure via dropped messages, or to bound the memory used by their
application. For performance reasons, this code is often quite lengthy
and somewhat arcane, relying on various BEAM features, both documented
and undocumented. A good example can be found here:
https://github.com/basho/riak_core/blob/2.0.0/src/riak_core_vnode_proxy.erl#L187-L272

This patch adds a mechanism for bounding process message queues from
within beam, retaining the older, unbounded behavior as the default. It
provides for two behaviors, dropping messages that fall outside the
bounds or causing the overloaded process to exit, depending on which mode the
user has selected.

Also included are tests and documentation changes for setting this
option via `process_flag/2,3` and `process_info/2`. The setting is not
displayed by default in `process_info/1`.

Testing: added a test to the emulator tests called process_flag_bound, and ran the whole suite of emulator tests.
Master results:
```
Testing tests.emulator_test: TEST COMPLETE, 1024 ok, 3 failed, 23 skipped of 1050 test cases
```
Branch results:
```
Testing tests.emulator_test: TEST COMPLETE, 1026 ok, 3 failed, 22 skipped of 1051 test cases
```