Re: Add new option 'all' to pg_stat_reset_shared() - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject Re: Add new option 'all' to pg_stat_reset_shared()
Date
Msg-id 20231108.100842.899919087426357988.horikyota.ntt@gmail.com
Whole thread Raw
In response to Re: Add new option 'all' to pg_stat_reset_shared()  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Responses Re: Add new option 'all' to pg_stat_reset_shared()
Re: Add new option 'all' to pg_stat_reset_shared()
List pgsql-hackers
At Mon, 6 Nov 2023 14:00:13 +0530, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote in 
> On Mon, Nov 6, 2023 at 11:39 AM torikoshia <torikoshia@oss.nttdata.com> wrote:
> > Since each stats, except wal_prefetch was reset acquiring LWLock,
> > attached PoC patch makes the call atomic by using these LWlocks.
> >
> > If this is the right direction, I'll try to make wal_prefetch also take
> > LWLock.

I must say, I have reservations about this approach. The main concern
is the duplication of reset code, which has been efficiently
encapsulated for individual targets, into this location. This practice
degrades the maintainability and clarity of the code.

> Well, that's a total of ~17 LWLocks this new function takes to make
> the stats reset atomic. I'm not sure if this atomicity is worth the
> effort which can easily be misused - what if someone runs something
> like SELECT pg_stat_reset_shared() FROM generate_series(1,
> 100000....n); to cause heavy lock acquisition and release cycles?
...
> IMV, atomicity is not something that applies for the stats reset
> operation because stats are approximate numbers by nature after all.
> If the pg_stat_reset_shared() resets stats for only a bunch of stats
> types and fails, it's the basic application programming style that
> when a query fails it's the application that needs to have a retry
> mechanism. FWIW, the atomicity doesn't apply today if someone wants to
> reset stats in a loop for all stats types.

The infrequent use of this feature, coupled with the fact that there
is no inherent need for these counters to be reset simultaneoulsy,
leads me to think that there is little point in cnetralizing the
locks.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Atomic ops for unlogged LSN
Next
From: Andres Freund
Date:
Subject: Re: Atomic ops for unlogged LSN