[erlang-questions] [ANN] Asynchronous PostgreSQL driver

Anton Lebedevich mabrek@REDACTED
Tue Nov 8 07:08:52 CET 2011

On 11/02/2011 07:21 AM, Tim Watson wrote:
> I've found the gen_servers that use cast heavily can easily get
> overwhelmed without back pressure. 

I'm considering providing both kinds of API: call and cast.
What's the better way to implement back pressure?
Currently there are 3 queues: driver process inbox, driver internal
queue of sent to backend requests, tcp send buffer.
One kind of backpressure implementation might look like using
gen_server:call that returns after calling gen_tcp:send. In this case
slow database will eventually stop reading from tcp socket, then
gen_tcp:send will hang, then gen_server:call will hang too.

> Now honestly, you're really missing a trick with this change. Does the
> client (pid) get a message as soon as data comes off the wire and a row
> has been successfully decoded? Because that is *far* more useful that
> just happening not to block the client pid while you go off and fetch
> everything in one go. If you either allow the client to pass a callback
> or simply send a message for each DataRow, you will have provided a boon
> for fast web applications.

I've started experimenting with it in branch
Currently it's incomplete, passes only one test case.

Anton Lebedevich.

More information about the erlang-questions mailing list