Re: usleep feature for pgbench

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
Thread:
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 #

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2007-07-05 20:50:55 Bgwriter strategies
Previous Message Florian G. Pflug 2007-07-05 19:41:33 Re: [PATCH] A crash and subsequent recovery of themaster can cause the slave to get out-of-sync