[Haskell-cafe] Database connection pool

Michael Snoyman michael at snoyman.com
Thu May 6 01:51:42 EDT 2010


Hi all,

I would like to pool my database connections in an application I'm writing,
and so far haven't found any prior art on the subject (besides this[1]). I
was wondering if:

* There's a package somewhere that does this
* Others have implemented it and have suggestions
* There's some big gotchas

The stackoverflow that I linked to gives one approach to this that seems
valid. My original thought on an implementation was to use a Chan. That way:

* When a connection is released, is goes to the end of the pool, so
connections get used evenly (not sure if this actually matters in practice).
* If a process dies and for some reason doesn't return its connection, there
shouldn't be a problem. Of course, I'd use bracket, so such a situation
should never arise anyway.
* Keep the coding against MVar to a minimum to avoid normal multi-threaded
pitfalls.

I'm using HDBC in this case, but I don't think I'll be using any
HDBC-specific code.

Thanks,
Michael

[1]
http://stackoverflow.com/questions/1141677/concurrent-db-connection-pool-in-haskell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100506/89206c63/attachment.html


More information about the Haskell-Cafe mailing list