Thanks Edi - using packages is indeed a better idea that just shadowing SELECT right in place.
I'll try to experiment with :pool again, though I remember having some troubles using it first time I tried.
BTW, it may be a good idea to have some place where people could contribute small snippets/examples of code related to your libraries rather then post them everywhere in their blogs, mailing lists etc. I myself would be happy to contribute finalized versions of thread-safe CLSQL usage / redefining error handlers; though this examples may sound obvious for more experienced Lisp programmers, they would probaly save some time for less experienced one, like myself. E.g. I could setup a separate page on cliki.net. Do you think that makes any sence?
Best Regards, Victor.
On 4/16/07, Edi Weitz edi@agharta.de wrote:
On Sun, 15 Apr 2007 19:03:15 -0500, "Victor Kryukov" victor.kryukov@gmail.com wrote:
The second question is: how do you use CLSQL thread-safely with Hunchentoot / SBCL? SBCL don't provide thread properties, so my first solution[1] was to create a hash-table and to assign each thread a connection, to check from every thread whether it already has a connection, and then to clean that hash-table periodically, closing connections for dead threads. That worked pretty well, but I was afraid of exhausting limit of database threads somehow, so I switched to the second solution.
The second solution[2] is to open new connection every time I need to save something to database or read something from it, and to close it right after that. That of course solves connection limit problem (unless I have very many users simultaneously, which is not expected in the near term), however it's much slower.
Anybody can share his/her strategy?
I'd use [2] but with pooled connections. See the :POOL keyword argument to CONNECT in CLSQL. That should get rid of your performance problems.
(let ((old-select (symbol-function 'clsql:select)))
That technique will break if you recompile the file the code is in. I'd propose to do this (shadow the original SELECT with your own function) with packages. _______________________________________________ tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel