Tuesday, January 20, 2009

Erlang and PostgreSQL Redux

I spent last weekend implementing encoding and decoding of PostgreSQL's date and time types. With this complete, epgsql is nearing a 1.0 release. Aside from bug fixes I've also implemented support for the 'returning' clause to return rows from an insert, update, or delete. The README file has been updated and includes a section describing how PostgreSQL types are represented in Erlang.

One thing you may notice is a lack of support for connection pooling, which I have remedied with epgsql_pool, available from this mercurial repository:

http://glozer.net/src/epgsql_pool

I debated including connection pools in epgsql itself, but I don't think they are the correct approach in Erlang. Instead I create pools of application-specific database accessor processes which are supervised and hold a persistent connection. This provides both a nice abstraction and the ability to prepare named statements during initialization rather than when a request comes in.

So use epgsql_pool at your own risk, I probably won't be maintaining it =)

5 comments:

Christian said...

Hi, I very much agree with you about not pooling connections, but instead pool the application specific servers.

Will you also solve the issue of load-balancing requests to a set of instances of the application specific servers? Databases have been known to give better throughput using many connections to them.


/jungerl-pgsql-christian

Will Glozer said...

Hey Christian! I'm using pg2:get_closest_pid/1 to distribute load over the data access servers.

jespern said...

Hey Will,

If it wasn't for this blogpost showing up on reddit, I wouldn't have known about epgsql, it wasn't showing up in any of my google searches.

Is there any chance you would let me mirror the mercurial repository on bitbucket, or perhaps you could move it over? It would be much easier to navigate it there.

Will Glozer said...

Hey jespern, thanks for the reminder of bitbucket! I've cloned the repo to http://bitbucket.org/will/epgsql/

tdilshod said...

I have not mercurial, how can i download it?