Re: Add connection active, idle time to pg_stat_activity

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: sergey(dot)dudoladov(at)gmail(dot)com
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, rjuju123(at)gmail(dot)com, kuntalghosh(dot)2007(at)gmail(dot)com, rafia(dot)pghackers(at)gmail(dot)com
Subject: Re: Add connection active, idle time to pg_stat_activity
Date: 2022-02-01 04:55:16
Message-ID: 20220201.135516.23011068590309830.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

At Mon, 31 Jan 2022 15:11:56 +0100, Sergey Dudoladov <sergey(dot)dudoladov(at)gmail(dot)com> wrote in
> > > if (beentry->st_state == STATE_RUNNING ||
> > > beentry->st_state == STATE_FASTPATH)
> > > - pgstat_count_conn_active_time((PgStat_Counter) secs * 1000000 + usecs);
> > > + {
> > > + pgstat_count_conn_active_time((PgStat_Counter) usecs_diff);
> > > + beentry->st_total_active_time += usecs_diff;
> > > + }
> > >
> > > The two lines operates exactly the same way on variables with slightly
> > > different behavior. pgStatActiveTime is reported at transaction end
> > > and reset at every tabstat reporting. st_total_active_time is reported
> > > immediately and reset at session end. Since we do the latter, the
> > > first can be omitted by remembering the last values for the local
> > > variables at every reporting. This needs additional two exporting
> >
> > Of course it's typo(?) of "values of the shared variables".
>
> Could you please elaborate on this idea ?
> So we have pgStatActiveTime and pgStatIdleInTransactionTime ultimately
> used to report respective metrics in pg_stat_database.
> Now beentry's st_total_active_time / st_total_transaction_idle_time
> duplicates this info, so one may get rid of pgStat*Time counters. Is
> the idea to report instead of them at every tabstat reporting the
> difference between the last memorized value of st_total_*_time and
> its current value ?

Exactly. The attached first diff is the schetch of that.

> > > This needs additional two exporting
> > > function in pgstatfuncs like pgstat_get_my_queryid so others might
> > > think differently.
>
> What would be example functions to look at ?

pgstat_get_my_queryid..

And, it seems like I forgot to mention this, but as Kuntal suggested
(in a different context and objective, though) upthraed, I think that
we can show realtime values in the two time fields by adding the time
of the current state. See the attached second diff.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2022-02-01 05:02:34 Re: Why is src/test/modules/committs/t/002_standby.pl flaky?
Previous Message Julien Rouhaud 2022-02-01 04:39:38 Re: Extensible Rmgr for Table AMs