[erlang-questions] gen_server aggregating calls/casts

Fred Hebert mononcqc@REDACTED
Wed Jul 10 14:07:01 CEST 2013


On 07/10, Peer Stritzinger wrote:
> 
> Having said this, your possibly unbounded growing mailbox is a bit
> scary and will at some point probably crash your node.  You should
> combine your selective  receives with some way of limiting requests.
> 

I have recently extracted a couple of patterns implemented in Heroku's
Logplex to make them into a library for a case like that, and dubbed it
PO Box (https://github.com/ferd/pobox) as an external mailbox.

This model works on the idea of dropping messages that are going over a
threshold, and simply reporting the number of losses for the cases where
you simply can't tell producers to slow down. The process that uses the
PO Box can just request to have all of its mail delivered as a single
message, handle them individually, then get the next batch (if any).

The pattern has proven itself to be fairly nice when dealing with
blocking operations in a critical process -- decoupling the queue
management from the blocking operation in two different processes, and
it has worked well in production so far (though we've had issues when I
attempted to deploy it to a very common component that ended up doubling
the number of processes on the server and had the schedulers crapping
themselves). It also works well when you can afford to batch operations,
such as inserting logs in a DB or writing them to disk, behaving as a
buffer.

While the pattern has seen plenty of production use, the library hasn't
seen itself tried in critical paths yet, but it has been in prod in
smaller internal apps and appeared to work very well.

Regards,
Fred.



More information about the erlang-questions mailing list