Re: Backup throttling
Andres Freund <andres@2ndquadrant.com>
From: Andres Freund <andres@2ndquadrant.com>
To: Antonin Houska <antonin.houska@gmail.com>
Cc: pgsql-hackers@postgresql.org
Date: 2013-09-03T12:51:55Z
Lists: pgsql-hackers
Hi, On 2013-09-03 14:35:18 +0200, Antonin Houska wrote: > + /* > + * THROTTLING_SAMPLE_MIN / MAX_RATE_LOWER (in seconds) should be the > + * longest possible time to sleep. > + */ > + pg_usleep((long) sleep); > + else > + > + /* > + * The actual transfer rate is below the limit. Negative value would > + * distort the adjustment of throttled_last. > + */ > + sleep = 0; > + > + /* > + * Only the whole multiples of throttling_sample processed. The rest will > + * be done during the next call of this function. > + */ > + throttling_counter %= throttling_sample; > + /* Once the (possible) sleep ends, new period starts. */ > + throttled_last += elapsed + sleep; > +} It's probably better to use latches for the waiting, those have properly defined interruption semantics. Whether pg_usleep will be interrupted is platform dependant... Greetings, Andres Freund