Обсуждение: Question about Linux, threads, and Postgres

Поиск
Список
Период
Сортировка

Question about Linux, threads, and Postgres

От
Felix Morley Finch
Дата:
I've been running various versions of Postgres for several years now,
including one prototype web site for a customer.  I currently run
6.3.2 at home, and will upgrade to 6.4.2, but I have some questions.

I am programming on Linux 2.0, libc6, in C.

I am writing a server application to sit between the database and
clients.  I would like to thread it.  This is strictly a home
education application, so I don't mind experimenting.  I have written
some small threaded apps before, but nothing fancy.  In particular, I
have never used any "third party" libraries; it has all been my code
and general libc stuff.

The Linux thread documentation mentions problems using X libraries
which have been compiled without threading support, either designed-in
or even using the compile time flag _REENTRANT.  As long as only one
thread calls all non-threaded functions, errno itself is safe, because
all the threaded code uses a per-thread value, leaving the global
errno to the unthreaded code.  I would not be surprised to find there
are other global variables also abused this way :-)

Q 1: Does anyone have experience with Postgres in a threaded program?

Q 2: Is it necessary and/or sufficient to have only one thread talk to
     the Postgres library?

Q 3: Would it be good / bad to compile 6.4.2 with -D_REENTRANT, and
     would this help with Q#2?

I searched the archives, but variations on "thread" found nothing but
references to threaded mailing list archives :-)

I also saw the news about 6.5 going from table locks to no locks.
This sounds pretty exciting!  I think it will be fun to write some
test programs for that, leave my box thrashing on it for a while when
I go to work :-)  But I have to find the usual spare time first :-(

--
            ... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
     Felix Finch: scarecrow repairman & rocket surgeon / felix@crowfix.com
  PGP = 91 B3 94 7C E9 E8 76 2D   E1 63 51 AA A0 48 89 2F  ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o

Re: [GENERAL] Question about Linux, threads, and Postgres

От
Adam Haberlach
Дата:
On Sat, Jan 30, 1999 at 09:08:14PM -0800, Felix Morley Finch wrote:

> Q 1: Does anyone have experience with Postgres in a threaded program?

    I have done a bit of this under BeOS (where each window gets
its own event loop and thread).  My first program turned out to have
problems in my initial port of the libraries, and in the process
of finding that out I ended up making the app rely on using a single
PgDatabase object protected by a home-brewed locking class.
    In my recent apps I have just been instantiating the PgDatabase
objects wherever needed.  I have not noticed any problems, but I have
also not done much real testing.

> Q 2: Is it necessary and/or sufficient to have only one thread talk to
>      the Postgres library?

    Well, it would be sufficient--I am not sure if it is necessary.
When I get around to cleaning up my hackish port of the client libs
to BeOS, I will keep an eye out for things that could cause problems.


Re: [GENERAL] Question about Linux, threads, and Postgres

От
Felix Morley Finch
Дата:
>>In article <19990131124430.B22196@ricochet.net>, Adam Haberlach <haberlaa@ricochet.net> writes:

> On Sat, Jan 30, 1999 at 09:08:14PM -0800, Felix Morley Finch wrote:

>> Q 2: Is it necessary and/or sufficient to have only one thread talk to
>> the Postgres library?

>     Well, it would be sufficient--I am not sure if it is necessary.
> When I get around to cleaning up my hackish port of the client libs
> to BeOS, I will keep an eye out for things that could cause problems.

Hmmmmm.  I wonder.  If libpq doesn't know about per-thread errno, but
uses the global one, and my code thinks the per-thread errno is set,
this might cause problems.  I wonder if there are any other libc
variables which also have per-thread and global versions.

--
            ... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
     Felix Finch: scarecrow repairman & rocket surgeon / felix@crowfix.com
  PGP = 91 B3 94 7C E9 E8 76 2D   E1 63 51 AA A0 48 89 2F  ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o