Re: pg_stat_activity.waiting_start

From: Joel Jacobson <joel(at)trustly(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_stat_activity.waiting_start
Date: 2016-12-24 05:32:58
Message-ID: CAASwCXeBAbU1qQz=RZSzg2k9Fpcn=hTgF4QPr1ny8RSgGeAh0g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

On Sat, Dec 24, 2016 at 9:56 AM, Joel Jacobson <joel(at)trustly(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joel Jacobson 2016-12-24 06:34:27 Re: pg_stat_activity.waiting_start
Previous Message Joel Jacobson 2016-12-24 02:56:08 Re: pg_stat_activity.waiting_start