pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
libpq and multi-threading on Linux?
5+ messages / 3 participants
[nested] [flat]

* libpq and multi-threading on Linux?
@ 1999-02-10 19:24  Michael Olivier <molivier@yahoo.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Michael Olivier @ 1999-02-10 19:24 UTC (permalink / raw)
  To: pgsql-interfaces

Hi folks,

I apologize in advance if I have overlooked docs, but I haven't been
able to find a discussion of how PostGreSQL via libpq on Linux fares
with pthreads. Can someone point me to docs if available, or otherwise
enlighten me? How well does it work and what are the important design
issues to consider?

I'm expecting to create a pool of db connections to use within a
long-running process, which will create a new thread for each incoming
request from a client. I've found just a very little bit about PG
being multi-processing, but not how it will interact with a
multi-threaded client. I appreciate your comments.

thanks,
--Michael

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] libpq and multi-threading on Linux?
@ 1999-02-11 08:59  Brendan Rempel <rempelb@cybersurf.net>
  parent: Michael Olivier <molivier@yahoo.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Brendan Rempel @ 1999-02-11 08:59 UTC (permalink / raw)
  To: pgsql-interfaces

I succeeded in doing exactly that.  I simply took the C source examples on
the Postgres documentation and pasted it into the thread with no problems
at all.  The only changes made to the examples were just simple ones like
return values or fprintf(stderr) stuff, but that's all. Postgres server
and libpq libraries run flawlessly in pthreads.

For me, synchronization was not required since each thread did not share
resources with other threads.  Each thread personally initialized the
libpq connection, did its job and destroyed the connection, just like the
example.

Brendan

Michael Olivier wrote:

> Hi folks,
>
> I apologize in advance if I have overlooked docs, but I haven't been
> able to find a discussion of how PostGreSQL via libpq on Linux fares
> with pthreads. Can someone point me to docs if available, or otherwise
> enlighten me? How well does it work and what are the important design
> issues to consider?
>
> I'm expecting to create a pool of db connections to use within a
> long-running process, which will create a new thread for each incoming
> request from a client. I've found just a very little bit about PG
> being multi-processing, but not how it will interact with a
> multi-threaded client. I appreciate your comments.
>
> thanks,
> --Michael
>
> _________________________________________________________
> DO YOU YAHOO!?
> Get your free @yahoo.com address at http://mail.yahoo.com




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] libpq and multi-threading on Linux?
@ 1999-02-13 12:37  Peter T Mount <peter@retep.org.uk>
  parent: Michael Olivier <molivier@yahoo.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Peter T Mount @ 1999-02-13 12:37 UTC (permalink / raw)
  To: Michael Olivier <molivier@yahoo.com>; +Cc: pgsql-interfaces

On Wed, 10 Feb 1999, Michael Olivier wrote:

> Hi folks,
> 
> I apologize in advance if I have overlooked docs, but I haven't been
> able to find a discussion of how PostGreSQL via libpq on Linux fares
> with pthreads. Can someone point me to docs if available, or otherwise
> enlighten me? How well does it work and what are the important design
> issues to consider?
> 
> I'm expecting to create a pool of db connections to use within a
> long-running process, which will create a new thread for each incoming
> request from a client. I've found just a very little bit about PG
> being multi-processing, but not how it will interact with a
> multi-threaded client. I appreciate your comments.

Take a look on how I got the JDBC driver to handle multi-threading.

At certain points, the driver obtains a lock on the network connection
before sending a query, and releases the lock when the query has finished
(ie: all results have been returned in to the ResultSet).

Another place where this locking occurs is in FastPath, a lock is obtained
on the network connection before sending the function call, and released
when the call returns.

When another thread tries to run a query, it has to wait until the lock is
released, then it can use that network connection. Also, it allows calls
to LargeObjects to run in one thread without any worries of confusing the
backend while queries are running.

I'm not sure if this is what you were after.

Peter

-- 
       Peter T Mount peter@retep.org.uk
      Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
 Java PDF Generator: http://www.retep.org.uk/pdf




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] libpq and multi-threading on Linux?
@ 1999-02-15 18:47  Michael Olivier <molivier@yahoo.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Michael Olivier @ 1999-02-15 18:47 UTC (permalink / raw)
  To: Peter T Mount <peter@retep.org.uk>; +Cc: pgsql-interfaces

Peter - thanks for your response -- see comments below.

---Peter T Mount <peter@retep.org.uk> wrote:
>
> On Wed, 10 Feb 1999, Michael Olivier wrote:
> 
> > Hi folks,
> > 
> > I apologize in advance if I have overlooked docs, but I haven't been
> > able to find a discussion of how PostGreSQL via libpq on Linux fares
> > with pthreads. Can someone point me to docs if available, or
otherwise
> > enlighten me? How well does it work and what are the important
design
> > issues to consider?
> > 
> > I'm expecting to create a pool of db connections to use within a
> > long-running process, which will create a new thread for each
incoming
> > request from a client. I've found just a very little bit about PG
> > being multi-processing, but not how it will interact with a
> > multi-threaded client. I appreciate your comments.
> 
> Take a look on how I got the JDBC driver to handle multi-threading.

OK, great -- how do I get this? From looking at your web site, I can
see downloadable jdbc6.4.jar, but I'm not doing Java work so don't
have a way to access this - looks like an archive. Can you send me the
source file(s) or post a URL?

> At certain points, the driver obtains a lock on the network connection
> before sending a query, and releases the lock when the query has
finished
> (ie: all results have been returned in to the ResultSet).

Is this so several threads can share one connection, or so that
Postgresql doesn't get screwed up with different threads using
different connections? I think you're saying the former, but I'm not
sure. I'm looking at allocating one connection per thread, so I need
this clarified, i.e., do I need to do locking of some sort or will it
work for me that each thread has a unique DB connection?

> I'm not sure if this is what you were after.

Yes, it's getting at it. Thanks.

--Michael

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] libpq and multi-threading on Linux?
@ 1999-02-15 19:50  Peter T Mount <peter@retep.org.uk>
  parent: Michael Olivier <molivier@yahoo.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Peter T Mount @ 1999-02-15 19:50 UTC (permalink / raw)
  To: Michael Olivier <molivier@yahoo.com>; +Cc: pgsql-interfaces

On Mon, 15 Feb 1999, Michael Olivier wrote:

> Peter - thanks for your response -- see comments below.
> 
> ---Peter T Mount <peter@retep.org.uk> wrote:
> >
> > On Wed, 10 Feb 1999, Michael Olivier wrote:
> > 
> > > Hi folks,
> > > 
> > > I apologize in advance if I have overlooked docs, but I haven't been
> > > able to find a discussion of how PostGreSQL via libpq on Linux fares
> > > with pthreads. Can someone point me to docs if available, or
> otherwise
> > > enlighten me? How well does it work and what are the important
> design
> > > issues to consider?
> > > 
> > > I'm expecting to create a pool of db connections to use within a
> > > long-running process, which will create a new thread for each
> incoming
> > > request from a client. I've found just a very little bit about PG
> > > being multi-processing, but not how it will interact with a
> > > multi-threaded client. I appreciate your comments.
> > 
> > Take a look on how I got the JDBC driver to handle multi-threading.
> 
> OK, great -- how do I get this? From looking at your web site, I can
> see downloadable jdbc6.4.jar, but I'm not doing Java work so don't
> have a way to access this - looks like an archive.

I should have said look at the source. The .jar files on my site contain
just the pre-compiled .class files.

Oh, you can use any zip tool to expand a jar file.

> Can you send me the source file(s) or post a URL?

It's under the src/interfaces/jdbc directory in the main source tree.

> > At certain points, the driver obtains a lock on the network connection
> > before sending a query, and releases the lock when the query has
> finished
> > (ie: all results have been returned in to the ResultSet).
> 
> Is this so several threads can share one connection, or so that
> Postgresql doesn't get screwed up with different threads using
> different connections? I think you're saying the former, but I'm not
> sure.

It's the former. Usually most people only run one connection per thread,
but just in case, the locking of the connection gives us some protection.

> I'm looking at allocating one connection per thread, so I need
> this clarified, i.e., do I need to do locking of some sort or will it
> work for me that each thread has a unique DB connection?

What you need is a pool of connections. In the current development source,
there is an example of a pool of connections in the JDBC-CORBA example.
It's under src/interfaces/jdbc/example/corba

> > I'm not sure if this is what you were after.
> 
> Yes, it's getting at it. Thanks.

-- 
       Peter T Mount peter@retep.org.uk
      Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
 Java PDF Generator: http://www.retep.org.uk/pdf




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~1999-02-15 19:50 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-02-10 19:24 libpq and multi-threading on Linux? Michael Olivier <molivier@yahoo.com>
1999-02-11 08:59 ` Brendan Rempel <rempelb@cybersurf.net>
1999-02-13 12:37 ` Peter T Mount <peter@retep.org.uk>
1999-02-15 18:47 Re: [INTERFACES] libpq and multi-threading on Linux? Michael Olivier <molivier@yahoo.com>
1999-02-15 19:50 ` Peter T Mount <peter@retep.org.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox