OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5

Lists: pgsql-hackers
From: markw(at)osdl(dot)org
To: pgsql-hackers(at)postgresql(dot)org
Cc: osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 00:18:19
Message-ID: 200311010018.hA10IMC24238@mail.osdl.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I thought someone might be interested in a data point I have comparing
7.3.4 and 7.4beta5 with results from our DBT-2 workload. Keep in mind I
haven't done much tuning with either version. The following links have
references iostat, vmstat, sar, readprofile (linux kernel profile), and
oprofile (postgresql profile) statistics.

Results from 7.3.4:
http://developer.osdl.org/markw/dbt2-pgsql/184/
- metric 1354.58

Results from 7.4beta5
http://developer.osdl.org/markw/dbt2-pgsql/188/
- metric 1446.01

7.4beta5 offers more throughput. One significant difference I see is in
the oprofile for the database. For the additional 7% increase in the
metric, there are about 32% less ticks in SearchCatCache.

These are the only database parameters I've explicitly set for each one,
any other differences will be differences in default values:
- shared_buffers = 40000
- tcpip_socket = true
- checkpoint_segments = 200
- checkpoint_timeout = 1800
- stats_start_collector = true
- stats_command_string = true
- stats_block_level = true
- stats_row_level = true
- stats_reset_on_server_start = true

If anyone has any tuning recommendations for either 7.3 or 7.4, I'll be
happy to try them. Or if anyone wants to be able to poke around on the
system, we can arrange that too. Feel free to ask any questions.

--
Mark Wong - - markw(at)osdl(dot)org
Open Source Development Lab Inc - A non-profit corporation
12725 SW Millikan Way - Suite 400 - Beaverton, OR 97005
(503) 626-2455 x 32 (office)
(503) 626-2436 (fax)


From: Rod Taylor <rbt(at)rbt(dot)ca>
To: markw(at)osdl(dot)org
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, OSDL - DB General <osdldbt-general(at)lists(dot)sourceforge(dot)net>
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 01:04:34
Message-ID: 1067648641.18476.23.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Excellent.

I just noticed that most of the numbers in the system are given the
numeric data type. Is there any particular reason you don't use integer
(test enforced?)?

On Fri, 2003-10-31 at 19:18, markw(at)osdl(dot)org wrote:
> I thought someone might be interested in a data point I have comparing
> 7.3.4 and 7.4beta5 with results from our DBT-2 workload. Keep in mind I
> haven't done much tuning with either version. The following links have
> references iostat, vmstat, sar, readprofile (linux kernel profile), and
> oprofile (postgresql profile) statistics.
>
> Results from 7.3.4:
> http://developer.osdl.org/markw/dbt2-pgsql/184/
> - metric 1354.58
>
> Results from 7.4beta5
> http://developer.osdl.org/markw/dbt2-pgsql/188/
> - metric 1446.01
>
> 7.4beta5 offers more throughput. One significant difference I see is in
> the oprofile for the database. For the additional 7% increase in the
> metric, there are about 32% less ticks in SearchCatCache.
>
> These are the only database parameters I've explicitly set for each one,
> any other differences will be differences in default values:
> - shared_buffers = 40000
> - tcpip_socket = true
> - checkpoint_segments = 200
> - checkpoint_timeout = 1800
> - stats_start_collector = true
> - stats_command_string = true
> - stats_block_level = true
> - stats_row_level = true
> - stats_reset_on_server_start = true
>
> If anyone has any tuning recommendations for either 7.3 or 7.4, I'll be
> happy to try them. Or if anyone wants to be able to poke around on the
> system, we can arrange that too. Feel free to ask any questions.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: markw(at)osdl(dot)org
Cc: pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 05:19:22
Message-ID: 22527.1067663962@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

markw(at)osdl(dot)org writes:
> 7.4beta5 offers more throughput. One significant difference I see is in
> the oprofile for the database. For the additional 7% increase in the
> metric, there are about 32% less ticks in SearchCatCache.

Hmm. I have been profiling PG for some years now, and I cannot remember
ever seeing a profile in which SearchCatCache topped everything else
(the usual suspects for me are palloc/pfree support code). Can you give
any explanation why it looks like that? Can your profiling code tell
where the hotspot call sites of SearchCatCache are?

regards, tom lane


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: markw(at)osdl(dot)org
Cc: pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 10:44:35
Message-ID: 3FA38E93.3040502@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

markw(at)osdl(dot)org wrote:

>Results from 7.4beta5
> http://developer.osdl.org/markw/dbt2-pgsql/188/
> - metric 1446.01
>
>

CPU: P4 / Xeon with 2 hyper-threads, speed 1497.51 MHz (estimated)
Counted GLOBAL_POWER_EVENTS events (time during which processor is not stopped) with a unit mask of 0x01 (count cycles when processor is active) count 100000
samples % app name symbol name
15369575 9.6780 postgres SearchCatCache
13714258 8.6357 vmlinux .text.lock.signal
10611912 6.6822 vmlinux do_sigaction
4400461 2.7709 vmlinux rm_from_queue

18% cpu time in the kernel signal handlers.

What are signals used for by postgres? I've seen the sigalarm to
implement timeouts, what else?

--
Manfred


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 13:37:21
Message-ID: 3FA3B711.8080906@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>markw(at)osdl(dot)org writes:
>
>
>>7.4beta5 offers more throughput. One significant difference I see is in
>>the oprofile for the database. For the additional 7% increase in the
>>metric, there are about 32% less ticks in SearchCatCache.
>>
>>
>
>Hmm. I have been profiling PG for some years now, and I cannot remember
>ever seeing a profile in which SearchCatCache topped everything else
>(the usual suspects for me are palloc/pfree support code). Can you give
>any explanation why it looks like that? Can your profiling code tell
>where the hotspot call sites of SearchCatCache are?
>
If I understand the docs correctly, op_to_source -a can do that - the
result is annotated assembly, with percentage numbers for each
instruction. If the sources were compiled with -g2, even source level
annotation is possible.

Mark, do you still have the oprofile output? I don't understand why so
much time is spent in the kernel signal handlers, i.e. I could use
annotated assembly or source of linux/kernel/signal.c.

--
Manfred


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: markw(at)osdl(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 16:15:01
Message-ID: 3FA3DC05.3060708@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I've straced
$ pgbench -c 5 -s 6 -t 1000

total 157k syscalls, 70k of them are rt_sigaction(SIGPIPE):

1754 poll([{fd=3, events=POLLOUT|POLLERR, revents=POLLOUT}], 1, -1) = 1
1754 rt_sigaction(SIGPIPE, {SIG_IGN}, {SIG_DFL}, 8) = 0
1754 send(3, "\0\0\0%\0\3\0\0user\0postgres\0database\0t"..., 37, 0) = 37
1754 rt_sigaction(SIGPIPE, {SIG_DFL}, {SIG_IGN}, 8) = 0
1754 poll([{fd=3, events=POLLIN|POLLERR, revents=POLLIN}], 1, -1) = 1
1754 recv(3, "R\0\0\0\10\0\0\0\0S\0\0\0\36client_encoding\0SQ"...,
16384, 0) = 169
1754 rt_sigaction(SIGPIPE, {SIG_IGN}, {SIG_DFL}, 8) = 0
1754 send(3, "Q\0\0\0\35SET search_path = public\0", 30, 0) = 30
1754 rt_sigaction(SIGPIPE, {SIG_DFL}, {SIG_IGN}, 8) = 0
1754 poll([{fd=3, events=POLLIN|POLLERR, revents=POLLIN}], 1, -1) = 1
1754 recv(3, "C\0\0\0\10SET\0Z\0\0\0\5I", 16384, 0) = 15
1754 rt_sigaction(SIGPIPE, {SIG_IGN}, {SIG_DFL}, 8) = 0

and so on. Is that really necessary?

Mark: could you strace your dbt2 app? I guess your app creates a similar
streams of rt_sigaction calls.

--
Manfred


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 16:24:45
Message-ID: 1456.1067703885@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> Is that really necessary?

Unfortunately, yes. libpq can't change the global setting of SIGPIPE
without breaking the surrounding application, but we don't want to crash
the app if the server connection has disappeared, either. So we have to
set the SIGPIPE handler and then restore it around every send().

On some platforms there might be a better way, but this is the only
portable way I know about.

regards, tom lane


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 18:27:01
Message-ID: 3FA3FAF5.8020602@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>
>
>>Is that really necessary?
>>
>>
>
>Unfortunately, yes. libpq can't change the global setting of SIGPIPE
>without breaking the surrounding application, but we don't want to crash
>the app if the server connection has disappeared, either. So we have to
>set the SIGPIPE handler and then restore it around every send().
>
>
Ok. Ahm. No, wait. libpq is multi-threaded, right?

signal handlers are a process property, not a thread property - that
code is broken for multi-threaded apps.
At least that's how I understand the opengroup man page, and a quick
google confirmed that:
http://groups.google.de/groups?selm=353662BF.9D70F63A%40brighttiger.com

I haven't found a reliable thread-safe approach yet:
My first idea was block with pthread_sigmask, after send check if
pending with sigpending, and then delete with sigwait, and restore
blocked state. But that breaks if SIGPIPE is blocked and a signal is
already pending: there is no way to remove our additional SIGPIPE. I
don't see how we can avoid destroying the realtime signal info.

Mark: Is your dbt2 testapp multithreaded? I don't see the signal
functions near the top in the profiles on the osdl website.

--
Manfred


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 18:37:30
Message-ID: 2092.1067711850@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> signal handlers are a process property, not a thread property - that
> code is broken for multi-threaded apps.

Yeah, that's been mentioned before, but I don't see any way around it.
What we really want is to turn off SIGPIPE delivery on our socket
(only), but AFAIK there is no API to do that.

regards, tom lane


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 19:10:42
Message-ID: 3FA40532.2050802@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>
>
>>signal handlers are a process property, not a thread property - that
>>code is broken for multi-threaded apps.
>>
>>
>
>Yeah, that's been mentioned before, but I don't see any way around it.
>
Do not handle SIGPIPE on multithreaded apps, and ask the caller to do
that? The current code doesn't block SIGPIPE reliably, which makes it
totally useless (except that it's a debugging nightmare, because
triggering it depends on the right timing).

>What we really want is to turn off SIGPIPE delivery on our socket
>(only), but AFAIK there is no API to do that.
>
>
Linux has as MSG_NOSIGNAL flag for send(), but that seems to be Linux
specific.

--
Manfred


From: Mark Wong <markw(at)osdl(dot)org>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 19:16:52
Message-ID: 20031101111652.C2457@osdlab.pdx.osdl.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Nov 01, 2003 at 02:37:21PM +0100, Manfred Spraul wrote:
> Tom Lane wrote:
>
> >markw(at)osdl(dot)org writes:
> >
> >
> >>7.4beta5 offers more throughput. One significant difference I see is in
> >>the oprofile for the database. For the additional 7% increase in the
> >>metric, there are about 32% less ticks in SearchCatCache.
> >>
> >>
> >
> >Hmm. I have been profiling PG for some years now, and I cannot remember
> >ever seeing a profile in which SearchCatCache topped everything else
> >(the usual suspects for me are palloc/pfree support code). Can you give
> >any explanation why it looks like that? Can your profiling code tell
> >where the hotspot call sites of SearchCatCache are?
> >
> If I understand the docs correctly, op_to_source -a can do that - the
> result is annotated assembly, with percentage numbers for each
> instruction. If the sources were compiled with -g2, even source level
> annotation is possible.
>
> Mark, do you still have the oprofile output? I don't understand why so
> much time is spent in the kernel signal handlers, i.e. I could use
> annotated assembly or source of linux/kernel/signal.c.

I haven't been saving the raw output, but I will start. I'll try to get
some annotated source for the kernel going too.

Mark


From: Mark Wong <markw(at)osdl(dot)org>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 19:19:55
Message-ID: 20031101111955.D2457@osdlab.pdx.osdl.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Nov 01, 2003 at 07:27:01PM +0100, Manfred Spraul wrote:
> Tom Lane wrote:
>
> >Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> >
> >
> >>Is that really necessary?
> >>
> >>
> >
> >Unfortunately, yes. libpq can't change the global setting of SIGPIPE
> >without breaking the surrounding application, but we don't want to crash
> >the app if the server connection has disappeared, either. So we have to
> >set the SIGPIPE handler and then restore it around every send().
> >
> >
> Ok. Ahm. No, wait. libpq is multi-threaded, right?
>
> signal handlers are a process property, not a thread property - that
> code is broken for multi-threaded apps.
> At least that's how I understand the opengroup man page, and a quick
> google confirmed that:
> http://groups.google.de/groups?selm=353662BF.9D70F63A%40brighttiger.com
>
> I haven't found a reliable thread-safe approach yet:
> My first idea was block with pthread_sigmask, after send check if
> pending with sigpending, and then delete with sigwait, and restore
> blocked state. But that breaks if SIGPIPE is blocked and a signal is
> already pending: there is no way to remove our additional SIGPIPE. I
> don't see how we can avoid destroying the realtime signal info.
>
> Mark: Is your dbt2 testapp multithreaded? I don't see the signal
> functions near the top in the profiles on the osdl website.

Yeah, my dbt2 applications are multithreaded.

Mark


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5)
Date: 2003-11-01 19:20:46
Message-ID: 2319.1067714446@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> Tom Lane wrote:
>> What we really want is to turn off SIGPIPE delivery on our socket
>> (only), but AFAIK there is no API to do that.
>>
> Linux has as MSG_NOSIGNAL flag for send(), but that seems to be Linux
> specific.

Hmm ... a Linux-specific solution would be better than none at all.

A bigger objection is that we couldn't get libssl to use it (AFAIK).
The flag really needs to be settable on the socket (eg, via fcntl),
not per-send.

regards, tom lane


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-01 21:09:13
Message-ID: 3FA420F9.5010507@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>A bigger objection is that we couldn't get libssl to use it (AFAIK).
>The flag really needs to be settable on the socket (eg, via fcntl),
>not per-send.
>
It's a per-send flag, it's not possible to force it on with a fcntl :-(

What about an option to skip the sigaction calls for apps that can
handle SIGPIPE? I'm not sure if an option at connect time, or a flag
accessible through a function like PQsetnonblocking() is the better
approach.

Attached is a patch that adds a connstr option, but I don't like it.

--
Manfred

Attachment Content-Type Size
patch-sigpipe text/plain 4.2 KB

From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Mark Wong <markw(at)osdl(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-01 21:29:34
Message-ID: 3FA425BE.5060706@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Mark Wong wrote:

>Yeah, my dbt2 applications are multithreaded.
>
>
Do you need SIGPIPE delivery in your app? If no, could you try what
happens if you apply the attached patch to postgres, and perform the
signal(SIGPIPE, SIG_IGN);
once in your dbt2 app?

--
Manfred

Attachment Content-Type Size
patch-dirty text/plain 531 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5)
Date: 2003-11-01 21:37:25
Message-ID: 2846.1067722645@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> What about an option to skip the sigaction calls for apps that can
> handle SIGPIPE?

If the app is ignoring SIGPIPE globally, then our calls will have no
effect anyway. I don't see that this proposal adds any security.

regards, tom lane


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-01 22:25:15
Message-ID: 3FA432CB.1040207@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>
>
>>What about an option to skip the sigaction calls for apps that can
>>handle SIGPIPE?
>>
>>
>
>If the app is ignoring SIGPIPE globally, then our calls will have no
>effect anyway.
>
Wrong. From the opengroup manpage:
<<
SIG_IGN - ignore signal
[snip]
- Setting a signal action to SIG_IGN for a signal that is pending will
cause the pending signal to be discarded, whether or not it is blocked
<<
This is why the kernel spends 20% cpu time processing the SIG_IGN:
it must walk through all threads of the process and check if there
are any SIGPIPE signals pending.

> I don't see that this proposal adds any security.
>
>
It's not about security: Right now multithreaded apps must call
signal(SIGPIPE, SIG_IGN), otherwise they could get killed by sudden
SIGPIPE signals. Additionally, they can't rely on sigpending, because
the pendings bits are cleared regularly. On top, they get a noticable
performance hit.

My proposal means that apps that know what they are doing (SIGPIPE
either SIG_IGN, or blocked, or a suitable handler) can avoid the
signal(SIGPIPE, SIG_IGN) in pqsecure_write. With backward compatibility,
because the current system works for single threaded apps.

--
Manfred


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org
Cc: osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-02 00:54:39
Message-ID: 200311011954.39119.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Friday 31 October 2003 19:18, markw(at)osdl(dot)org wrote:
> These are the only database parameters I've explicitly set for each one,
> any other differences will be differences in default values:
> - shared_buffers = 40000
> - tcpip_socket = true
> - checkpoint_segments = 200
> - checkpoint_timeout = 1800

ISTM that these two are fairly unrepresentative of any real world setups. I
might be better to knock them way back towards there defaults and turn on
"checkpoint_warning" to see if they should be altered.

> - stats_start_collector = true
> - stats_command_string = true
> - stats_block_level = true
> - stats_row_level = true
> - stats_reset_on_server_start = true
>
> If anyone has any tuning recommendations for either 7.3 or 7.4, I'll be
> happy to try them. Or if anyone wants to be able to poke around on the
> system, we can arrange that too. Feel free to ask any questions.

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


From: Mark Wong <markw(at)osdl(dot)org>
To: Rod Taylor <rbt(at)rbt(dot)ca>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, OSDL - DB General <osdldbt-general(at)lists(dot)sourceforge(dot)net>
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-02 01:58:07
Message-ID: 20031101175807.F2457@osdlab.pdx.osdl.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I don't remember making a conscious decision between the number and integer
database type. Is that a significant oversight on my part?

On Fri, Oct 31, 2003 at 08:04:34PM -0500, Rod Taylor wrote:
> Excellent.
>
> I just noticed that most of the numbers in the system are given the
> numeric data type. Is there any particular reason you don't use integer
> (test enforced?)?
>
> On Fri, 2003-10-31 at 19:18, markw(at)osdl(dot)org wrote:
> > I thought someone might be interested in a data point I have comparing
> > 7.3.4 and 7.4beta5 with results from our DBT-2 workload. Keep in mind I
> > haven't done much tuning with either version. The following links have
> > references iostat, vmstat, sar, readprofile (linux kernel profile), and
> > oprofile (postgresql profile) statistics.
> >
> > Results from 7.3.4:
> > http://developer.osdl.org/markw/dbt2-pgsql/184/
> > - metric 1354.58
> >
> > Results from 7.4beta5
> > http://developer.osdl.org/markw/dbt2-pgsql/188/
> > - metric 1446.01
> >
> > 7.4beta5 offers more throughput. One significant difference I see is in
> > the oprofile for the database. For the additional 7% increase in the
> > metric, there are about 32% less ticks in SearchCatCache.
> >
> > These are the only database parameters I've explicitly set for each one,
> > any other differences will be differences in default values:
> > - shared_buffers = 40000
> > - tcpip_socket = true
> > - checkpoint_segments = 200
> > - checkpoint_timeout = 1800
> > - stats_start_collector = true
> > - stats_command_string = true
> > - stats_block_level = true
> > - stats_row_level = true
> > - stats_reset_on_server_start = true
> >
> > If anyone has any tuning recommendations for either 7.3 or 7.4, I'll be
> > happy to try them. Or if anyone wants to be able to poke around on the
> > system, we can arrange that too. Feel free to ask any questions.


From: Mark Wong <markw(at)osdl(dot)org>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-02 02:00:35
Message-ID: 20031101180035.G2457@osdlab.pdx.osdl.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Nov 01, 2003 at 02:37:21PM +0100, Manfred Spraul wrote:
> Tom Lane wrote:
>
> >markw(at)osdl(dot)org writes:
> >
> >
> >>7.4beta5 offers more throughput. One significant difference I see is in
> >>the oprofile for the database. For the additional 7% increase in the
> >>metric, there are about 32% less ticks in SearchCatCache.
> >>
> >>
> >
> >Hmm. I have been profiling PG for some years now, and I cannot remember
> >ever seeing a profile in which SearchCatCache topped everything else
> >(the usual suspects for me are palloc/pfree support code). Can you give
> >any explanation why it looks like that? Can your profiling code tell
> >where the hotspot call sites of SearchCatCache are?
> >
> If I understand the docs correctly, op_to_source -a can do that - the
> result is annotated assembly, with percentage numbers for each
> instruction. If the sources were compiled with -g2, even source level
> annotation is possible.
>
> Mark, do you still have the oprofile output? I don't understand why so
> much time is spent in the kernel signal handlers, i.e. I could use
> annotated assembly or source of linux/kernel/signal.c.

I've rerun a test, capturing the raw oprofile output, running opannotate for
source and assmebly output (links for each should be on the page now.) Let
me know if I've missed anything:
http://developer.osdl.org/markw/dbt2-pgsql/190/

I'm running a test with your patch now too. I should have results shortly.

Thanks,
Mark


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Mark Wong <markw(at)osdl(dot)org>
Cc: Rod Taylor <rbt(at)rbt(dot)ca>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, OSDL - DB General <osdldbt-general(at)lists(dot)sourceforge(dot)net>
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-02 03:03:34
Message-ID: 3FA47406.70905@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Numerics are a LOT slower than reals. Integers are faster than anything
I guess.

Chris

Mark Wong wrote:

> I don't remember making a conscious decision between the number and integer
> database type. Is that a significant oversight on my part?
>
>
> On Fri, Oct 31, 2003 at 08:04:34PM -0500, Rod Taylor wrote:
>
>>Excellent.
>>
>>I just noticed that most of the numbers in the system are given the
>>numeric data type. Is there any particular reason you don't use integer
>>(test enforced?)?
>>
>>On Fri, 2003-10-31 at 19:18, markw(at)osdl(dot)org wrote:
>>
>>>I thought someone might be interested in a data point I have comparing
>>>7.3.4 and 7.4beta5 with results from our DBT-2 workload. Keep in mind I
>>>haven't done much tuning with either version. The following links have
>>>references iostat, vmstat, sar, readprofile (linux kernel profile), and
>>>oprofile (postgresql profile) statistics.
>>>
>>>Results from 7.3.4:
>>> http://developer.osdl.org/markw/dbt2-pgsql/184/
>>> - metric 1354.58
>>>
>>>Results from 7.4beta5
>>> http://developer.osdl.org/markw/dbt2-pgsql/188/
>>> - metric 1446.01
>>>
>>>7.4beta5 offers more throughput. One significant difference I see is in
>>>the oprofile for the database. For the additional 7% increase in the
>>>metric, there are about 32% less ticks in SearchCatCache.
>>>
>>>These are the only database parameters I've explicitly set for each one,
>>>any other differences will be differences in default values:
>>> - shared_buffers = 40000
>>> - tcpip_socket = true
>>> - checkpoint_segments = 200
>>> - checkpoint_timeout = 1800
>>> - stats_start_collector = true
>>> - stats_command_string = true
>>> - stats_block_level = true
>>> - stats_row_level = true
>>> - stats_reset_on_server_start = true
>>>
>>>If anyone has any tuning recommendations for either 7.3 or 7.4, I'll be
>>>happy to try them. Or if anyone wants to be able to poke around on the
>>>system, we can arrange that too. Feel free to ask any questions.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend


From: Mark Wong <markw(at)osdl(dot)org>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-02 04:43:46
Message-ID: 20031101204346.J2457@osdlab.pdx.osdl.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Nov 01, 2003 at 10:29:34PM +0100, Manfred Spraul wrote:
> Mark Wong wrote:
>
> >Yeah, my dbt2 applications are multithreaded.
> >
> >
> Do you need SIGPIPE delivery in your app? If no, could you try what
> happens if you apply the attached patch to postgres, and perform the
> signal(SIGPIPE, SIG_IGN);
> once in your dbt2 app?

Wow, that patch made a pretty big difference:
http://developer.osdl.org/markw/dbt2-pgsql/191/
- metric 1605.51

So no one has to look for older mail before I applied that patch:
http://developer.osdl.org/markw/dbt2-pgsql/190/
- metric 1427.24

Looks like about a 12% improvement in the overall metric. The first thing I
noticed is that do_sigaction in the kernel profile almost disappeared. The
top few functions in the database profile doesn't appear to have changed much.

Mark


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Mark Wong <markw(at)osdl(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-02 11:06:03
Message-ID: 3FA4E51B.5010209@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Mark Wong wrote:

>On Sat, Nov 01, 2003 at 10:29:34PM +0100, Manfred Spraul wrote:
>
>
>>Mark Wong wrote:
>>
>>
>>
>>>Yeah, my dbt2 applications are multithreaded.
>>>
>>>
>>>
>>>
>>Do you need SIGPIPE delivery in your app? If no, could you try what
>>happens if you apply the attached patch to postgres, and perform the
>> signal(SIGPIPE, SIG_IGN);
>>once in your dbt2 app?
>>
>>
>
>Wow, that patch made a pretty big difference:
> http://developer.osdl.org/markw/dbt2-pgsql/191/
> - metric 1605.51
>
>So no one has to look for older mail before I applied that patch:
> http://developer.osdl.org/markw/dbt2-pgsql/190/
> - metric 1427.24
>
>Looks like about a 12% improvement in the overall metric. The first thing I
>noticed is that do_sigaction in the kernel profile almost disappeared.
>
Cool.

> The
>top few functions in the database profile doesn't appear to have changed much.
>
>
I've looked at the profile:
The only unusal line is the memcpy(cur_skey, cache->cc_skey,
sizeof(cur_skey)): it copies 144 byte and needs ~5.3% global cpu time,
from the 12.1% in SearchCatCache. The cachelines (line size 128 bytes)
of cc_skey are shared with cc_bucket. 1.8% cpu time is spent in
DLMoveToFront, the function that moves cache entries around.

Perhaps a scalability problem of the hash table? The implementation
moves the entries around all the time, i.e. the worst case for cache
line transfers.

--
Manfred


From: Rod Taylor <rbt(at)rbt(dot)ca>
To: Mark Wong <markw(at)osdl(dot)org>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, OSDL - DB General <osdldbt-general(at)lists(dot)sourceforge(dot)net>
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-02 12:25:38
Message-ID: 1067775937.571.8.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, 2003-11-01 at 20:58, Mark Wong wrote:
> I don't remember making a conscious decision between the number and integer
> database type. Is that a significant oversight on my part?

Numerics do exact math with support for arbitrary numbers. Unlike
Oracle, PostgreSQL does not retype NUMBER to a faster type internally
(like int).

You may find a good sized improvement (possibly as much as 15%) by
switching to integer as it will both reduce CPU load and storage
requirements.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-02 17:16:30
Message-ID: 15119.1067793390@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> Tom Lane wrote:
>> I don't see that this proposal adds any security.
>>
> It's not about security:

The proposal would be more salable if it addressed the security problem
too. As is, you are proposing putting a large wart on libpq's API in
order to work around an inefficiency that's only been shown to exist in
one version of one operating system. I'd like to look for other
solutions before we do that.

One possibility that comes to mind is simply to test whether the SIGPIPE
handler is already SIG_IGN before we munge it. Ideally we'd do that
once when the conn object is created, but even if it had to be done more
often, it might still be a net win.

regards, tom lane


From: AgentM <agentm(at)webopticon(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-02 20:32:51
Message-ID: BAF9D401-0D73-11D8-81CA-000A95672382@webopticon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sunday, Nov 2, 2003, at 18:16 Europe/Berlin, Tom Lane wrote:
> Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>> Tom Lane wrote:
>>> I don't see that this proposal adds any security.
>>>
>> It's not about security:
>
> The proposal would be more salable if it addressed the security problem
> too. As is, you are proposing putting a large wart on libpq's API in
> order to work around an inefficiency that's only been shown to exist in
> one version of one operating system. I'd like to look for other
> solutions before we do that.
>
> One possibility that comes to mind is simply to test whether the
> SIGPIPE
> handler is already SIG_IGN before we munge it. Ideally we'd do that
> once when the conn object is created, but even if it had to be done
> more
> often, it might still be a net win.

That wouldn't offer a solution for people who use SIGPIPE for other
things during the lifetime of the program (after creating the
connection) and if a SIGPIPE handler is called due to the connection,
the handler won't be expecting the source, and polling signal for state
is essentially what you do now. Instead, I propose a
PQsigpipeOK/PQacceptsigpipe/PQrecvsigpipe(PGconn*) or something to that
effect which skips this check for the connection. That way, programmers
are aware that the connection could call their SIGPIPE handler because
they explicitly request it and the library remains backwards-compatible.


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: AgentM <agentm(at)webopticon(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-02 21:10:57
Message-ID: 3FA572E1.8050609@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

AgentM wrote:

> That wouldn't offer a solution for people who use SIGPIPE for other
> things during the lifetime of the program (after creating the
> connection) and if a SIGPIPE handler is called due to the connection,
> the handler won't be expecting the source, and polling signal for
> state is essentially what you do now. Instead, I propose a
> PQsigpipeOK/PQacceptsigpipe/PQrecvsigpipe(PGconn*) or something to
> that effect which skips this check for the connection. That way,
> programmers are aware that the connection could call their SIGPIPE
> handler because they explicitly request it and the library remains
> backwards-compatible.

If I understand libpq sources correctly, the first packets are send
during connection setup - PQsigpipeOK(PGconn *) would be too late.
That's why I added "sigpipe=caller" as a new flag for PQconnectdb.

--
Manfred


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: AgentM <agentm(at)webopticon(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-02 23:06:45
Message-ID: 5377.1067814405@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> If I understand libpq sources correctly, the first packets are send
> during connection setup - PQsigpipeOK(PGconn *) would be too late.
> That's why I added "sigpipe=caller" as a new flag for PQconnectdb.

That's definitely a problem, but "sigpipe=caller" is one of the very
worst aspects of your proposal. In many apps the connectinfo string is
passed in more-or-less-directly from user input. But having the user
fool with sigpipe handling would be disastrous --- either the app is
coded to handle sigpipe properly for itself, or it isn't. If we're
going to make a hook that allows the app to tell libpq how to handle
sigpipe, then we have to make it feed in the information in some way
other than via the connectinfo string.

It strikes me that sigpipe handling will be a global affair in any
particular application --- it's unlikely that it would be correct for
some PG connections and wrong for others. So one possibility is to make
the control variable be global (static) and thus it could be set before
creating the first PGconn.

regards, tom lane


From: markw(at)osdl(dot)org
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: manfred(at)colorfullife(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-03 20:02:03
Message-ID: 200311032002.hA3K26C16009@mail.osdl.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 1 Nov, Tom Lane wrote:
> Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>> Tom Lane wrote:
>>> What we really want is to turn off SIGPIPE delivery on our socket
>>> (only), but AFAIK there is no API to do that.
>>>
>> Linux has as MSG_NOSIGNAL flag for send(), but that seems to be Linux
>> specific.
>
> Hmm ... a Linux-specific solution would be better than none at all.
>
> A bigger objection is that we couldn't get libssl to use it (AFAIK).
> The flag really needs to be settable on the socket (eg, via fcntl),
> not per-send.

I'm a bit unfamiliar with this stuff, so I wanted to ask if this was
something that Linux appears to be handling differently than other OS's,
or if this was a platform specific issue with postgresql.

Thanks,
Mark


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: AgentM <agentm(at)webopticon(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-03 20:49:44
Message-ID: 3FA6BF68.9060303@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>It strikes me that sigpipe handling will be a global affair in any
>particular application --- it's unlikely that it would be correct for
>some PG connections and wrong for others. So one possibility is to make
>the control variable be global (static) and thus it could be set before
>creating the first PGconn.
>
>
What about the attached patches?
I hope I found all places that must be updated when a new function is
added to libpq.

--
Manfred

Attachment Content-Type Size
patch-sigpipe-global text/plain 5.5 KB
patch-pgbench-global text/plain 2.6 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: markw(at)osdl(dot)org
Cc: manfred(at)colorfullife(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Date: 2003-11-03 21:14:47
Message-ID: 12065.1067894087@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

markw(at)osdl(dot)org writes:
> I'm a bit unfamiliar with this stuff, so I wanted to ask if this was
> something that Linux appears to be handling differently than other OS's,
> or if this was a platform specific issue with postgresql.

It's generic to all Unixen.

regards, tom lane


From: markw(at)osdl(dot)org
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: manfred(at)colorfullife(dot)com, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-04 19:03:17
Message-ID: 200311041903.hA4J3KC17830@mail.osdl.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 1 Nov, Tom Lane wrote:
> Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>> signal handlers are a process property, not a thread property - that
>> code is broken for multi-threaded apps.
>
> Yeah, that's been mentioned before, but I don't see any way around it.
> What we really want is to turn off SIGPIPE delivery on our socket
> (only), but AFAIK there is no API to do that.

Will this be a problem for multi-threaded apps with any of the client
interfaces?

Anyone working on making it threadsafe?

Thanks,
Mark


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: markw(at)osdl(dot)org
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-04 19:22:43
Message-ID: 3FA7FC83.1010008@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

markw(at)osdl(dot)org wrote:

>On 1 Nov, Tom Lane wrote:
>
>
>>Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>>
>>
>>>signal handlers are a process property, not a thread property - that
>>>code is broken for multi-threaded apps.
>>>
>>>
>>Yeah, that's been mentioned before, but I don't see any way around it.
>>What we really want is to turn off SIGPIPE delivery on our socket
>>(only), but AFAIK there is no API to do that.
>>
>>
>
>Will this be a problem for multi-threaded apps with any of the client
>interfaces?
>
>Anyone working on making it threadsafe?
>
>
The POSIX api is not thread safe: signal handlers are per process, and
libpq would like to block SIGPIPE for it's send() calls. For single
threaded apps, libpq just calls sigaction and sets the handler to
SIG_IGN around the syscalls.
For multithreaded apps, this is not possible: sigaction is per process.
Thus the calling application must handle the SIGPIPE signals for libpq -
either by blocking or ignoring them. We are still discussing the exact
API. Probably a global state that is accessible through a new function.

One thread-safe alternative might be the combination of sigprocmask /
pthread_sigmask and sigwait, but I think this would be too fragile.

--
Manfred


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-04 19:33:52
Message-ID: 24188.1067974432@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
> For multithreaded apps, this is not possible: sigaction is per process.
> Thus the calling application must handle the SIGPIPE signals for libpq -
> either by blocking or ignoring them. We are still discussing the exact
> API. Probably a global state that is accessible through a new function.

I think we should also take a hard look at avoiding the problem by using
MSG_NOSIGNAL on platforms that have it, so that the right things happen
and overhead is minimized whether or not the application knows to do
this. Besides I am not convinced that an app that *wants* SIGPIPE on
some of its output channels could reasonably solve the problem with a
custom signal handler --- how will the handler know which FD the signal
came from?

The difficulty with MSG_NOSIGNAL is in getting libssl to cooperate.
I wonder if we could convince the libssl implementors that MSG_NOSIGNAL
should be used when available in their standard release, or at least
they should provide an option to use it? The alternative would be to
create our own BIO for libssl, which I think is doable, but would likely
be a pain in the neck to maintain.

regards, tom lane


From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: markw(at)osdl(dot)org, pgsql-hackers(at)postgresql(dot)org, osdldbt-general(at)lists(dot)sourceforge(dot)net
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-04 19:58:58
Message-ID: 3FA80502.4000905@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:

>Manfred Spraul <manfred(at)colorfullife(dot)com> writes:
>
>
>>For multithreaded apps, this is not possible: sigaction is per process.
>>Thus the calling application must handle the SIGPIPE signals for libpq -
>>either by blocking or ignoring them. We are still discussing the exact
>>API. Probably a global state that is accessible through a new function.
>>
>>
>
>I think we should also take a hard look at avoiding the problem by using
>MSG_NOSIGNAL on platforms that have it,
>
I think that's the second step. First we need a portable solution, then
we can optimize it.
The fastest solution is one signal(SIGPIPE, SIG_IGN) in main(), but that
requires a change in all libpq users. OTHO there shouldn't be that many
multithreaded users.
sigprocmask + sigwait could work, but sigprocmask is undefined if
multiple threads are running. Is there a portable approach for weak
links? libpq would have to call proc_sigmask if linked against
libpthread, and sigprocmask if not linked against libpthread. With gcc,
I could use 'void proc_sigmask () __attribute__ ((weak, alias
("_sigprocmask")));' or something similar, but this wouldn't be portable
either.

--
Manfred


From: Mark Wong <markw(at)osdl(dot)org>
To: Rod Taylor <rbt(at)rbt(dot)ca>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, OSDL - DB General <osdldbt-general(at)lists(dot)sourceforge(dot)net>
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-17 23:04:47
Message-ID: 20031117150447.A25418@osdlab.pdx.osdl.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Nov 02, 2003 at 07:25:38AM -0500, Rod Taylor wrote:
> On Sat, 2003-11-01 at 20:58, Mark Wong wrote:
> > I don't remember making a conscious decision between the number and integer
> > database type. Is that a significant oversight on my part?
>
> Numerics do exact math with support for arbitrary numbers. Unlike
> Oracle, PostgreSQL does not retype NUMBER to a faster type internally
> (like int).
>
> You may find a good sized improvement (possibly as much as 15%) by
> switching to integer as it will both reduce CPU load and storage
> requirements.

I've changed all the numerics to integers and reals, where it was appropriate
to maintain the precision specificed in the TPC-C spec. Here's a comparison
of results:

http://developer.osdl.org/markw/dbt2-pgsql/214/
- using all numerics
- metric 1831.78

http://developer.osdl.org/markw/dbt2-pgsql/217/
- integers and reals where appropriate
- metric 1972.94

Looks like I see about an 8% improvement in the metric with this instance. A
definite decrease in user time in the processor utilization chart, which I
presume is attributed to the 70% decrease in ticks to SearchCatCache in the
database as reported by oprofile. Can anyone explain that one?

Mark


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Wong <markw(at)osdl(dot)org>
Cc: Rod Taylor <rbt(at)rbt(dot)ca>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, OSDL - DB General <osdldbt-general(at)lists(dot)sourceforge(dot)net>
Subject: Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Date: 2003-11-20 19:47:45
Message-ID: 6274.1069357665@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Mark Wong <markw(at)osdl(dot)org> writes:
> I've changed all the numerics to integers and reals, where it was appropriate
> to maintain the precision specificed in the TPC-C spec.
> ...
> Looks like I see about an 8% improvement in the metric with this instance. A
> definite decrease in user time in the processor utilization chart, which I
> presume is attributed to the 70% decrease in ticks to SearchCatCache in the
> database as reported by oprofile. Can anyone explain that one?

That's odd; I don't see why NUMERIC would be incurring extra
SearchCatCache calls. Does your profile provide info about where the
SearchCatCache calls are coming from?

regards, tom lane