Re: usleep feature for pgbench

Lists: pgsql-hackers
From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: usleep feature for pgbench
Date: 2007-07-05 19:12:51
Message-ID: 468D42B3.4010701@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

To test some changes in Slony I needed a

\usleep [microseconds|:variable]

in pgbench's scripting language to be able to have hundreds of
concurrent running transactions without totally swamping the system. I
was wondering if anyone would object to permanently adding this to the
pgbench code?

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usleep feature for pgbench
Date: 2007-07-05 19:34:06
Message-ID: 20905.1183664046@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> To test some changes in Slony I needed a
> \usleep [microseconds|:variable]
> in pgbench's scripting language to be able to have hundreds of
> concurrent running transactions without totally swamping the system. I
> was wondering if anyone would object to permanently adding this to the
> pgbench code?

How's it implemented? Does the whole pgbench app freeze up for the
duration of the sleep, or does it just delay that one client script?

regards, tom lane


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usleep feature for pgbench
Date: 2007-07-05 20:43:31
Message-ID: 468D57F3.7030405@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 7/5/2007 3:34 PM, Tom Lane wrote:
> Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
>> To test some changes in Slony I needed a
>> \usleep [microseconds|:variable]
>> in pgbench's scripting language to be able to have hundreds of
>> concurrent running transactions without totally swamping the system. I
>> was wondering if anyone would object to permanently adding this to the
>> pgbench code?
>
> How's it implemented? Does the whole pgbench app freeze up for the
> duration of the sleep, or does it just delay that one client script?

Only that one client script.

The \usleep command itself calculates a "struct timeval until" that sits
in the state struct and sets a "sleeping" flag also in the state struct.
So both are per client script/connection and multiple clients can be
sleeping in an overlapping fashion. The loop in main() then picks the
lowest timeval (if there is anyone sleeping) and uses that to calculate
the timeout for select(). doCustom() resets the sleeping flag for those
scheduled for wakeup and advances the client to the next scripted command.

I think I've coded it in a way that if one doesn't use the \usleep
command at all, it will never even call gettimeofday() and use a NULL
timeout in select() as it used to.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usleep feature for pgbench
Date: 2007-07-05 21:30:14
Message-ID: 21985.1183671014@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> I think I've coded it in a way that if one doesn't use the \usleep
> command at all, it will never even call gettimeofday() and use a NULL
> timeout in select() as it used to.

Did you check that the observed performance for non-usleep-using scripts
didn't change? If this extra overhead causes a reduction in reported
TPS rates it would make it hard to compare older and newer tests.

Other than that I've got no objection to it.

regards, tom lane


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usleep feature for pgbench
Date: 2007-07-05 21:49:39
Message-ID: 20070705214939.GE21455@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> > I think I've coded it in a way that if one doesn't use the \usleep
> > command at all, it will never even call gettimeofday() and use a NULL
> > timeout in select() as it used to.
>
> Did you check that the observed performance for non-usleep-using scripts
> didn't change? If this extra overhead causes a reduction in reported
> TPS rates it would make it hard to compare older and newer tests.

I keep wondering, why is that important? If you want to compare results
of different PG versions, surely you can run the tests with the newest
version of pgbench?

--
Alvaro Herrera http://www.flickr.com/photos/alvherre/
"Those who use electric razors are infidels destined to burn in hell while
we drink from rivers of beer, download free vids and mingle with naked
well shaved babes." (http://slashdot.org/comments.pl?sid=44793&cid=4647152)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usleep feature for pgbench
Date: 2007-07-05 21:54:32
Message-ID: 22479.1183672472@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Tom Lane wrote:
>> Did you check that the observed performance for non-usleep-using scripts
>> didn't change? If this extra overhead causes a reduction in reported
>> TPS rates it would make it hard to compare older and newer tests.

> I keep wondering, why is that important? If you want to compare results
> of different PG versions, surely you can run the tests with the newest
> version of pgbench?

It's more about not having to repeat old test cases every time you want
to have numbers comparable to your latest case.

regards, tom lane


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usleep feature for pgbench
Date: 2007-07-06 02:58:29
Message-ID: 468DAFD5.30002@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 7/5/2007 5:30 PM, Tom Lane wrote:
> Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
>> I think I've coded it in a way that if one doesn't use the \usleep
>> command at all, it will never even call gettimeofday() and use a NULL
>> timeout in select() as it used to.
>
> Did you check that the observed performance for non-usleep-using scripts
> didn't change? If this extra overhead causes a reduction in reported
> TPS rates it would make it hard to compare older and newer tests.

Given pgbench's unpredictability of results ... lets see.

I ran

dropdb x
createdb x
pgbench -i -s10 x
psql -c 'checkpoint' x
sleep 1
psql -c 'checkpoint' x
pgbench -s10 -c5 -t10000 x
pgbench -s10 -c5 -t10000 x
pgbench -s10 -c5 -t10000 x

Original pgbench reported 39, 37 and 33 TPS. Having my patch applied it
reported 40, 38 and 33 TPS. Inserting a "\usleep 1" after the update to
accounts of a default equivalent script changed those numbers to 40, 37
and 33. I interpret that as "does not change observed performance".

>
> Other than that I've got no objection to it.

Will be committed after adjusting the README.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Greg Smith <gsmith(at)gregsmith(dot)com>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usleep feature for pgbench
Date: 2007-07-06 07:46:10
Message-ID: Pine.GSO.4.64.0707060323450.17749@westnet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 5 Jul 2007, Jan Wieck wrote:

> Original pgbench reported 39, 37 and 33 TPS. Having my patch applied it
> reported 40, 38 and 33 TPS. Inserting a "\usleep 1" after the update to
> accounts of a default equivalent script changed those numbers to 40, 37 and
> 33. I interpret that as "does not change observed performance".

Tell you what: put your work into a patch, send it to the list, and I'll
test that it doesn't degrade results for you. If your pgbench results are
in the <40 TPS range even with that low of a scale, you're not in a
position to tell whether it has a negative performance impact. That
select statement you're fiddling with can turn into a bottleneck at high
client loads, and from your description I can't tell if you've made that
worse, but you'll never see it unless you're pushing, say,
>1000 TPS and >50 clients. Also: 3 pgbench results at one client load
is quite a bit short of proving no impact on performance; I'll queue up 50
or so, which is where I start to trust results from that unruly tool.

This is actually a feature I'd be kind of interested to have, because it
would allow you to pass two (or more) script files to pgbench and adjust
the transaction mix. What happens when you do that right now is that
inevitably all the clients get blocked at once on whatever the hardest to
execute transaction is, and the results are kind of deceptive as a result.

--
* Greg Smith gsmith(at)gregsmith(dot)com http://www.gregsmith.com Baltimore, MD


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Jan Wieck <JanWieck(at)yahoo(dot)com>
Subject: Re: usleep feature for pgbench
Date: 2007-07-06 14:44:57
Message-ID: 200707061644.57878.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Am Donnerstag, 5. Juli 2007 21:12 schrieb Jan Wieck:
> To test some changes in Slony I needed a
>
> \usleep [microseconds|:variable]
>
> in pgbench's scripting language to be able to have hundreds of
> concurrent running transactions without totally swamping the system. I
> was wondering if anyone would object to permanently adding this to the
> pgbench code?

Or maybe a \sleep command that takes units, if it's not too much work.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: usleep feature for pgbench
Date: 2007-07-06 17:24:19
Message-ID: 468E7AC3.3040501@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 7/6/2007 10:44 AM, Peter Eisentraut wrote:
> Am Donnerstag, 5. Juli 2007 21:12 schrieb Jan Wieck:
>> To test some changes in Slony I needed a
>>
>> \usleep [microseconds|:variable]
>>
>> in pgbench's scripting language to be able to have hundreds of
>> concurrent running transactions without totally swamping the system. I
>> was wondering if anyone would object to permanently adding this to the
>> pgbench code?
>
> Or maybe a \sleep command that takes units, if it's not too much work.
>

You mean as a second, optional argument? Good idea.

us = microseconds
ms = milliseconds
s = seconds (default)

\sleep {value|:variable} [us|ms|s]

Is that okay with everyone?

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: usleep feature for pgbench
Date: 2007-07-06 17:32:27
Message-ID: 468E7CAB.9070802@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jan Wieck wrote:
> On 7/6/2007 10:44 AM, Peter Eisentraut wrote:
>> Am Donnerstag, 5. Juli 2007 21:12 schrieb Jan Wieck:
>>> To test some changes in Slony I needed a
>>>
>>> \usleep [microseconds|:variable]
>>>
>>> in pgbench's scripting language to be able to have hundreds of
>>> concurrent running transactions without totally swamping the system. I
>>> was wondering if anyone would object to permanently adding this to the
>>> pgbench code?
>>
>> Or maybe a \sleep command that takes units, if it's not too much work.
>>
>
> You mean as a second, optional argument? Good idea.
>
> us = microseconds
> ms = milliseconds
> s = seconds (default)
>
> \sleep {value|:variable} [us|ms|s]
>
> Is that okay with everyone?

I won't object, but is it really worth the trouble?

Can you do microsecond precision sleeps, and on what platforms? How much
overhead is there? IIRC, on Linux the minimum time you can sleep depends
on CONFIG_HZ, and the default was 10 ms until recently.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: usleep feature for pgbench
Date: 2007-07-06 18:35:29
Message-ID: 468E8B71.90602@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 7/6/2007 1:32 PM, Heikki Linnakangas wrote:
> Jan Wieck wrote:
>> On 7/6/2007 10:44 AM, Peter Eisentraut wrote:
>>> Am Donnerstag, 5. Juli 2007 21:12 schrieb Jan Wieck:
>>>> To test some changes in Slony I needed a
>>>>
>>>> \usleep [microseconds|:variable]
>>>>
>>>> in pgbench's scripting language to be able to have hundreds of
>>>> concurrent running transactions without totally swamping the system. I
>>>> was wondering if anyone would object to permanently adding this to the
>>>> pgbench code?
>>>
>>> Or maybe a \sleep command that takes units, if it's not too much work.
>>>
>>
>> You mean as a second, optional argument? Good idea.
>>
>> us = microseconds
>> ms = milliseconds
>> s = seconds (default)
>>
>> \sleep {value|:variable} [us|ms|s]
>>
>> Is that okay with everyone?
>
> I won't object, but is it really worth the trouble?
>
> Can you do microsecond precision sleeps, and on what platforms? How much
> overhead is there? IIRC, on Linux the minimum time you can sleep depends
> on CONFIG_HZ, and the default was 10 ms until recently.
>

It is what you tell select(2) in the struct timeval. Why limit it to
some arbitrary precision?

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
Cc: Jan Wieck <JanWieck(at)Yahoo(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: usleep feature for pgbench
Date: 2007-07-07 03:13:31
Message-ID: 12923.1183778011@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Heikki Linnakangas <heikki(at)enterprisedb(dot)com> writes:
> Jan Wieck wrote:
>> You mean as a second, optional argument? Good idea.
>>
>> us = microseconds
>> ms = milliseconds
>> s = seconds (default)
>>
>> \sleep {value|:variable} [us|ms|s]
>>
>> Is that okay with everyone?

> I won't object, but is it really worth the trouble?

If we don't get it right now, we'll be stuck with the API later.
+1 for the definition suggested above.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jan Wieck <JanWieck(at)yahoo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: usleep feature for pgbench
Date: 2007-07-07 08:36:40
Message-ID: 200707071036.41585.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jan Wieck wrote:
> You mean as a second, optional argument? Good idea.

I think it should only be one argument, with the units being part of the
variable value, if any.

> us = microseconds
> ms = milliseconds
> s = seconds (default)
>
> \sleep {value|:variable} [us|ms|s]
--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Jan Wieck <JanWieck(at)yahoo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: usleep feature for pgbench
Date: 2007-07-07 15:40:17
Message-ID: 2384.1183822817@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Jan Wieck wrote:
>> You mean as a second, optional argument? Good idea.

> I think it should only be one argument, with the units being part of the
> variable value, if any.

No, because that makes it hard to do things like "sleep for a small
random number of microseconds". If pgbench had string concatenation
ability in its metalanguage then what you suggest would be sensible,
but let us not go there.

regards, tom lane


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: usleep feature for pgbench
Date: 2007-07-07 22:08:11
Message-ID: 46900ECB.8060304@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 7/7/2007 11:40 AM, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>> Jan Wieck wrote:
>>> You mean as a second, optional argument? Good idea.
>
>> I think it should only be one argument, with the units being part of the
>> variable value, if any.
>
> No, because that makes it hard to do things like "sleep for a small
> random number of microseconds". If pgbench had string concatenation
> ability in its metalanguage then what you suggest would be sensible,
> but let us not go there.

That is exactly the reason why I made it an optional argument. The usage
example in the README file shows how to actually do a random sleep
between 1000 and 2500 ms.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #