Re: Add connection active, idle time to pg_stat_activity

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: rjuju123(at)gmail(dot)com
Cc: sergey(dot)dudoladov(at)gmail(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org, 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-01-28 05:36:31
Message-ID: 20220128.143631.654438319295147801.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi.

At Thu, 27 Jan 2022 20:36:56 +0800, Julien Rouhaud <rjuju123(at)gmail(dot)com> wrote in
> On Thu, Jan 27, 2022 at 11:43:26AM +0100, Sergey Dudoladov wrote:
> >
> > Per agreement with Rafia I have reworked the patch in the past days.
> > The new version 6 is now ready for review.
>
> Great, thanks a lot Sergey!
>
> The cfbot is happy with this new version:
> https://cirrus-ci.com/github/postgresql-cfbot/postgresql/commitfest/36/3405

I think we can easily add the duration of the current state to the two
in pg_stat_get_activity and it would offer better information.

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
function in pgstatfuncs like pgstat_get_my_queryid so others might
think differently.

The write operation to beentry needs to be enclosed by
PGSTAT_BEGIN/END_WRITE_ACTIVITY(). In that perspective, it would be
better to move that writes to the PGSTAT_WRITE_ACTIVITY section just
below.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro Horiguchi 2022-01-28 05:40:24 Re: Add connection active, idle time to pg_stat_activity
Previous Message r.takahashi_2@fujitsu.com 2022-01-28 05:07:28 RE: Support escape sequence for cluster_name in postgres_fdw.application_name