Re: [HACKERS] pg_stat_activity.waiting_start - Mailing list pgsql-hackers

From Joel Jacobson
Subject Re: [HACKERS] pg_stat_activity.waiting_start
Date
Msg-id CAASwCXeBAbU1qQz=RZSzg2k9Fpcn=hTgF4QPr1ny8RSgGeAh0g@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] pg_stat_activity.waiting_start  (Joel Jacobson <joel@trustly.com>)
Responses Re: [HACKERS] pg_stat_activity.waiting_start  (Joel Jacobson <joel@trustly.com>)
List pgsql-hackers
On Sat, Dec 24, 2016 at 9:56 AM, Joel Jacobson <joel@trustly.com> wrote:
>> The difficulty with that is it'd require a gettimeofday() call for
>> every wait start.  Even on platforms where those are relatively cheap,

I just realized how this can be optimized.
We only need to set wait_start for every new waiting period,
not for every wait start, i.e. not for every call to pgstat_report_wait_start():

Example:

In pgstat_report_wait_start():
if (proc->wait_start == 0)  proc->wait_start = (pg_time_t) time(NULL);

And then in pgstat_report_wait_end():
proc->wait_start = 0;

This means we only need to call time() or gettimeofday() once per
waiting period.


-- 
Joel Jacobson



pgsql-hackers by date:

Previous
From: Joel Jacobson
Date:
Subject: Re: [HACKERS] pg_stat_activity.waiting_start
Next
From: Joel Jacobson
Date:
Subject: Re: [HACKERS] pg_stat_activity.waiting_start