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@osdl.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)

Fri, 31 Oct 2003 16:18:19 -0800 (PST)
markw@osdl.org
OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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@osdl.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.
Fri, 31 Oct 2003 20:04:34 -0500
Rod Taylor <rbt@rbt.ca>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
markw@osdl.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

Sat, 01 Nov 2003 00:19:22 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5 
markw@osdl.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


Sat, 01 Nov 2003 11:44:35 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Tom Lane wrote:

>markw@osdl.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


Sat, 01 Nov 2003 14:37:21 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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


Sat, 01 Nov 2003 17:15:01 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Manfred Spraul <manfred@colorfullife.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

Sat, 01 Nov 2003 11:24:45 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5 
Tom Lane wrote:

>Manfred Spraul <manfred@colorfullife.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


Sat, 01 Nov 2003 19:27:01 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Manfred Spraul <manfred@colorfullife.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

Sat, 01 Nov 2003 13:37:30 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5 
Tom Lane wrote:

>Manfred Spraul <manfred@colorfullife.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


Sat, 01 Nov 2003 20:10:42 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
On Sat, Nov 01, 2003 at 02:37:21PM +0100, Manfred Spraul wrote:
> Tom Lane wrote:
> 
> >markw@osdl.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

Sat, 1 Nov 2003 11:16:52 -0800
Mark Wong <markw@osdl.org>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
On Sat, Nov 01, 2003 at 07:27:01PM +0100, Manfred Spraul wrote:
> Tom Lane wrote:
> 
> >Manfred Spraul <manfred@colorfullife.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

Sat, 1 Nov 2003 11:19:55 -0800
Mark Wong <markw@osdl.org>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Manfred Spraul <manfred@colorfullife.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

Sat, 01 Nov 2003 14:20:46 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and
 7.4beta5)
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
Sat, 01 Nov 2003 22:09:13 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
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
Sat, 01 Nov 2003 22:29:34 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Manfred Spraul <manfred@colorfullife.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

Sat, 01 Nov 2003 16:37:25 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and
	7.4beta5)
Tom Lane wrote:

>Manfred Spraul <manfred@colorfullife.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


Sat, 01 Nov 2003 23:25:15 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
On Friday 31 October 2003 19:18, markw@osdl.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

Sat, 1 Nov 2003 19:54:39 -0500
Robert Treat <xzilla@users.sourceforge.net>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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@osdl.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.

Sat, 1 Nov 2003 17:58:07 -0800
Mark Wong <markw@osdl.org>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
On Sat, Nov 01, 2003 at 02:37:21PM +0100, Manfred Spraul wrote:
> Tom Lane wrote:
> 
> >markw@osdl.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

Sat, 1 Nov 2003 18:00:35 -0800
Mark Wong <markw@osdl.org>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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@osdl.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


Sun, 02 Nov 2003 11:03:34 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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

Sat, 1 Nov 2003 20:43:46 -0800
Mark Wong <markw@osdl.org>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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


Sun, 02 Nov 2003 12:06:03 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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.
Sun, 02 Nov 2003 07:25:38 -0500
Rod Taylor <rbt@rbt.ca>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Manfred Spraul <manfred@colorfullife.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

Sun, 02 Nov 2003 12:16:30 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 
On Sunday, Nov 2, 2003, at 18:16 Europe/Berlin, Tom Lane wrote:
> Manfred Spraul <manfred@colorfullife.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.


Sun, 2 Nov 2003 21:32:51 +0100
AgentM <agentm@webopticon.com>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 
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


Sun, 02 Nov 2003 22:10:57 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
Manfred Spraul <manfred@colorfullife.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

Sun, 02 Nov 2003 18:06:45 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 
On  1 Nov, Tom Lane wrote:
> Manfred Spraul <manfred@colorfullife.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

Mon, 3 Nov 2003 12:02:03 -0800 (PST)
markw@osdl.org
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
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
Mon, 03 Nov 2003 21:49:44 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL
markw@osdl.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

Mon, 03 Nov 2003 16:14:47 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Avoiding SIGPIPE (was Re: OSDL DBT-2 w/ PostgreSQL 
On  1 Nov, Tom Lane wrote:
> Manfred Spraul <manfred@colorfullife.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

Tue, 4 Nov 2003 11:03:17 -0800 (PST)
markw@osdl.org
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5 
markw@osdl.org wrote:

>On  1 Nov, Tom Lane wrote:
>  
>
>>Manfred Spraul <manfred@colorfullife.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


Tue, 04 Nov 2003 20:22:43 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Manfred Spraul <manfred@colorfullife.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

Tue, 04 Nov 2003 14:33:52 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5 
Tom Lane wrote:

>Manfred Spraul <manfred@colorfullife.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


Tue, 04 Nov 2003 20:58:58 +0100
Manfred Spraul <manfred@colorfullife.com>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
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

Mon, 17 Nov 2003 15:04:47 -0800
Mark Wong <markw@osdl.org>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5
Mark Wong <markw@osdl.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

Thu, 20 Nov 2003 14:47:45 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: OSDL DBT-2 w/ PostgreSQL 7.3.4 and 7.4beta5 