Re: any experience with multithreaded pg apps? - Mailing list pgsql-general

From Ben
Subject Re: any experience with multithreaded pg apps?
Date
Msg-id Pine.LNX.4.44.0405071142430.12573-100000@localhost.localdomain
Whole thread Raw
In response to Re: any experience with multithreaded pg apps?  (Bill Moran <wmoran@potentialtech.com>)
List pgsql-general
Mark Harrison wrote:
> I'm looking for feedback from anybody who has used pg in a
> multi-threaded program, particularly one in which several
> threads each open a database connection.
>
> It's documented to work in that scenario, but I'm interested
> in anybody who can share some real-world with that.

We've wrapped the libpq commands inside some code that makes use of a glib
thread pool. On startup, we have a bunch of threads make persistant
connections to the database. The rest of our app simply has to push
querries onto this pool, and the first available thread will make use of
its persistant connection to return the results as fast as possible. If
all threads are busy working on queries, our wrapper code takes care of
the queuing for us.

It's a scaleable solution that we can make as complex as we want. (For
instance, if the database crashes, each thread should be able to
re-establish its connection.) It works pretty well. The only drawback is
that the application can't make use of the threadpool for multi-query
transactions, but we've wrapped all of those in stored procs anyway.


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Interpreting vacuum verbosity
Next
From: Carlos
Date:
Subject: pg_restore -L option