Are there any OCaml solutions for DBMS connection pooling and query/request queues?

Are there any OCaml solutions for DBMS connection pooling and query/request queues? First of all I’m interested in solutions for PostgreSQL RDBMS.

P.S. Dear admins, could you please add category for DB-related questions?

There was a related thread Databases and OCaml recently. At least Ezpostgresql and my own Caqti supports connection pooling. Not sure if it fit’s your bill, but due to the monadic concurrency used by these libraries, requests will be queued by the underlying event system.

4 Likes

So far there hasn’t been a standalone generic resource pool library for OCaml that I’m aware of. One of the most widely used (e.g. by Ocsigen and Docker) is Lwt_pool. But yeah, you would need to build it yourself. Ezpostgresql aims to give you that by wrapping postgresql-ocaml and make it Lwt-friendly; by limiting the abstraction to just Lwt and postgresql-ocaml, Ezpostgresql can be specific enough to keep the API simple while supporting postgres’ specific features. @paurkedal’s Caqti on the other hand aims to support more DB drivers and concurrency lib, and (afaik) it implements its own pooling system (not using Lwt_pool). Both have tradeoffs in this regard.

2 Likes

Yes, Lwt_pool was the inspiration for Caqti_pool. Since Caqti supports async, I think it was simplest to re-implement to pool. I also wanted priorities for requests, so it’s using a heap to queue them.

3 Likes

It’s currently implemented in ocsigen-start.

1 Like