Re: usleep feature for pgbench - Mailing list pgsql-hackers

From Jan Wieck
Subject Re: usleep feature for pgbench
Date
Msg-id 468D57F3.7030405@Yahoo.com
Whole thread Raw
In response to Re: usleep feature for pgbench  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: usleep feature for pgbench
List pgsql-hackers
On 7/5/2007 3:34 PM, Tom Lane wrote:
> Jan Wieck <JanWieck@Yahoo.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
multipleclients 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@Yahoo.com #


pgsql-hackers by date:

Previous
From: "Florian G. Pflug"
Date:
Subject: Re: [PATCH] A crash and subsequent recovery of themaster can cause the slave to get out-of-sync
Next
From: Heikki Linnakangas
Date:
Subject: Bgwriter strategies