Re: any experience with multithreaded pg apps?

From: Ben <bench(at)silentmedia(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: any experience with multithreaded pg apps?
Date: 2004-05-07 18:52:40
Message-ID: Pine.LNX.4.44.0405071142430.12573-100000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mike Mascari 2004-05-07 18:53:22 Re: any experience with multithreaded pg apps?
Previous Message Tom Lane 2004-05-07 18:48:24 Re: Interpreting vacuum verbosity