Re: Sleep functions

From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: <mike(at)fuhr(dot)org>, <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Sleep functions
Date: 2005-08-22 07:30:01
Message-ID: 003001c5a6eb$5ae0de64$6a01a8c0@valehousing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


-----Original Message-----
From: "Michael Fuhr"<mike(at)fuhr(dot)org>
Sent: 22/08/05 05:41:50
To: "Tom Lane"<tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-hackers(at)postgresql(dot)org"<pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Sleep functions

> To others who've written their own sleep() > function: what are you
> using it for?

LOL - I honestly don't recall now!! I was certainly testing something I needed to slow down.

/D

-----Unmodified Original Message-----
On Sun, Aug 21, 2005 at 09:13:20PM -0400, Tom Lane wrote:
> Michael Fuhr <mike(at)fuhr(dot)org> writes:
> > What do people think of exposing pg_usleep() to the user?
>
> I'm not real enthused about it. Generally speaking, a sleep() on the
> database side means you are idling while holding locks, and that does
> not seem like something we want to encourage people to do.

I don't see how providing a server-side sleep() encourages idling
while holding locks any more than people can already do. In that
respect, is it any different than a client-side sleep() or going
to lunch with an open transaction in psql?

> As other responders noted, it's trivial to program this in any of the
> untrusted PL languages, So what you're really proposing is that we give
> sleep() to non-superusers, and that seems like a bit of a hard sell.
> Let's see a use-case or three.

Sure it's trivial in various languages, even in trusted PL/Tcl:

CREATE FUNCTION sleep(integer) RETURNS void AS $$
after [expr $1 * 1000]
$$ LANGUAGE pltcl STRICT;

So aside from the ways to idle I mentioned above, non-superusers
do have a way to perform a server-side sleep(), at least on systems
that use PL/Tcl. Or is allowing "after" a bug in trusted PL/Tcl?
In any case, I wonder how many people, not having a sleep() function,
effect a delay with a busy loop; an example of such has been posted
in response to the thread in pgsql-admin, and didn't the regression
tests do so until recently? That seems less desirable than a real
sleep().

A few use cases are learning, testing, and debugging: you might
want to slow down operations so you can more easily watch what's
happening, observe how the slowness affects other operations, or
look for application problems related to timing. With a server-side
sleep() those delays can be done with simple queries fed into psql
or another interface that doesn't provide a way to sleep, and a
client-side sleep() wouldn't help if you want to slow down operations
inside a PL/pgSQL function.

To others who've written their own sleep() function: what are you
using it for?

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Palle Girgensohn 2005-08-22 09:40:09 Re: Win32 unicode vs ICU
Previous Message Michael Fuhr 2005-08-22 04:40:14 Re: Sleep functions