Re: Sub-millisecond [autovacuum_]vacuum_cost_delay broken

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Melanie Plageman <melanieplageman(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: Sub-millisecond [autovacuum_]vacuum_cost_delay broken
Date: 2023-03-13 23:10:08
Message-ID: 20230313231008.GB428842@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> * NOTE: although the delay is specified in microseconds, the effective
> - * resolution is only 1/HZ, or 10 milliseconds, on most Unixen. Expect
> - * the requested delay to be rounded up to the next resolution boundary.
> + * resolution is only 1/HZ on systems that use periodic kernel ticks to wake
> + * up. This may cause sleeps to be rounded up by 1-20 milliseconds on older
> + * Unixen and Windows.

nitpick: Could the 1/HZ versus 20 milliseconds discrepancy cause confusion?
Otherwise, I think this is the right idea.

> + * CAUTION: if interrupted by a signal, this function will return, but its
> + * interface doesn't report that. It's not a good idea to use this
> + * for long sleeps in the backend, because backends are expected to respond to
> + * interrupts promptly. Better practice for long sleeps is to use WaitLatch()
> + * with a timeout.

I'm not sure this argument follows. If pg_usleep() returns if interrupted,
then why are we concerned about delayed responses to interrupts?

> - delay.tv_usec = microsec % 1000000L;
> - (void) select(0, NULL, NULL, NULL, &delay);
> + delay.tv_nsec = (microsec % 1000000L) * 1000;
> + (void) nanosleep(&delay, NULL);

Using nanosleep() seems reasonable to me.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2023-03-13 23:16:16 Re: lz4 --rm on Ubuntu 18.04 (Add LZ4 compression to pg_dump)
Previous Message Melanie Plageman 2023-03-13 23:00:59 Re: Show various offset arrays for heap WAL records