clsql seems to support connection pooling, since the connect method has the :pool key, and the cliki makes note of it being thread-safe when using with-database. I can't find an example of this being used online and I'm really not sure I'm using it right.
Currently I do something like this:
(defvar connection-string '("localhost" "database" "user" "password"))
(loop repeat 4 do (clsql:connect connection-string :pool t :database-type :mysql))
(defun called-on-seperate-thread (the-query)
(clsql:with-database (db connection-string :pool t :database-type :mysql)
(clsql:query the-query :database db)))
but only 2 of the 4 database connections ever get used. I've been running my application for about a week, and it seems to be thread-safe as the cliki suggested, but I'm not sure I could prove it and I'm confused as to why it only uses some of my connections when it should be selecting them randomly from the pool.
How do you correctly use connection pools in clsql?
This is the description of the
:poolkeyword argument ofclsql:connect, taken from https://www.quicklisp.org/beta/UNOFFICIAL/docs/clsql/doc/connect.html:On https://quickref.common-lisp.net/clsql.html, it is said that:
I guess that means that when you do
only the first call returns a new connection; the second, third and fourth calls to
clsql:connectmerely return the connection created on the first iteration, which was on the "general pool".Though I didn't test it, I suppose that if you pass
nilto the:poolargument, all four connections will actually be established.