Re: Avoiding roundoff error in pg_sleep()

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Avoiding roundoff error in pg_sleep()
Date: 2025-09-25 19:41:25
Message-ID: CA+TgmoanvqTwQihU7ByWu+xWt8tjbUfpKV_8y=9iT09Ysw-q=w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Sep 25, 2025 at 2:42 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I chanced to notice that if you ask pg_sleep for 1ms delay,
> what you actually get is 2ms, for example

Oh, wow. I tested and I get the same behavior.

> Anyway, I propose trying to get rid of this misbehavior by avoiding
> floating point in the delay computation, as attached.

Score one for my blind yet fiery hatred of floating-point arithmetic.
The patch looks good except that (places tongue firmly in cheek) it
will cause problems for users who want to sleep for more than 150,000
years.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-09-25 19:44:34 Re: Avoiding roundoff error in pg_sleep()
Previous Message Tom Lane 2025-09-25 19:36:18 Re: Avoiding roundoff error in pg_sleep()