Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbqeS-0003LF-V0 for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Apr 2022 21:23:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nbqeR-0001Eq-QV for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Apr 2022 21:23:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbqeR-0001Eg-Fl for pgsql-hackers@lists.postgresql.org; Tue, 05 Apr 2022 21:23:47 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nbqeL-000607-0w for pgsql-hackers@lists.postgresql.org; Tue, 05 Apr 2022 21:23:46 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id BDB805C0209; Tue, 5 Apr 2022 17:23:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 05 Apr 2022 17:23:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; bh=9D5l0MN9gM66tvsOyC++sbGN9/P69IDPeL0LDh xR9bk=; b=PD5Kx3uurY4NDY+jE5tM61uCWKEVbzLSd/z9JpkpXRIbMH0M42Ev74 jY9HGUcJtzk6U9USYxvwB0QZwW/W2eW1cfwY9Hc3f64LsV/d+QAu3mOQHT499rtX nHj/2HYw9VilOyupzFxY6ScWB9/7FZLqO2CuuWmr34AaDgNkiETy9+IUHmEE9F0k VymNDRuxUzBMKEOswOB8fnWkbRLO2vda05soWfqJ6GPGaECaDiit7BEH9I2zkHiK QkBI13751+MGSKt924LumiyH6fVcD9DCJXUuRLHOwMOLLIYyiO6SkIMcBGmNn0r8 3orlxFL9fB19VdMaDfYt4sJThtQ82j9Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=9D5l0MN9gM66tvsOy C++sbGN9/P69IDPeL0LDhxR9bk=; b=dbAg6RsnmKeRPVmISXhTwMpVF67nhSZkY 8uGNkwU4TMWee/3MsTJGt63EwSTNkeTvlS6VRq9uGBpv24MgxIyGP75Y4gNnKpde xAiWclctVdchKY6KQwguOFVwalCvyKv13cgYhSLV/RxlxTaSupjOezOXg8+hH09i BVqwQqB2VK1jPruLD4g5wz5gRXja/xKHuHjKQihNZUP6OCy1gPutMrxi9L0GCQu5 6lbi4vajhiVsXUtsPMyJj+sa85pRYXE/nW+yeQApZBFK6BthkF/CMztwoMTGySkM WStGQsvKX8MuLFey5yxw9LYCaULm3XmrjNbCz2DkR8eaBMwmwco+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudejgedgudehjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepudekhfekleeugeevteehleffffejgeelueduleeffeeutdelffeujeff hfeuffdunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Apr 2022 17:23:39 -0400 (EDT) Date: Tue, 5 Apr 2022 14:23:38 -0700 From: Andres Freund To: "David G. Johnston" Cc: Kyotaro Horiguchi , Melanie Plageman , Justin Pryzby , Thomas Munro , PostgreSQL Hackers Subject: Re: shared-memory based stats collector - v69 Message-ID: <20220405212338.tvhtm5fxhmczaib2@alap3.anarazel.de> References: <20220317073652.kz3uuh6le6vbfod4@alap3.anarazel.de> <20220325.142256.1649716600998659084.horikyota.ntt@gmail.com> <20220325.172418.1055357550509939415.horikyota.ntt@gmail.com> <20220402082102.ojdd2e6cobsmljvh@alap3.anarazel.de> <20220404041516.cctrvpadhuriawlq@alap3.anarazel.de> <20220405030506.lfdhbu5zf4tzdpux@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-04-05 13:51:12 -0700, David G. Johnston wrote: > On Mon, Apr 4, 2022 at 8:05 PM Andres Freund wrote: > > > - added an architecture overview comment to the top of pgstat.c - not sure > > if > > it makes sense to anybody but me (and perhaps Horiguchi-san)? > > > > > I took a look at this, diff attached. Thanks! > Some typos and minor style stuff, > plus trying to bring a bit more detail to the caching mechanism. I may > have gotten it wrong in adding more detail though. > > + * read-only, backend-local, transaction-scoped, hashtable > (pgStatEntryRefHash) > + * in front of the shared hashtable, containing references > (PgStat_EntryRef) > + * to shared hashtable entries. The shared hashtable thus only needs to be > + * accessed when the PgStat_HashKey is not present in the backend-local > hashtable, > + * or if stats_fetch_consistency = 'none'. > > I'm under the impression, but didn't try to confirm, that the pending > updates don't use the caching mechanism They do. >, but rather add to the shared queue Queue? Maybe you mean the hashtable? >, and so the cache is effectively read-only. It is also transaction-scoped >based upon the GUC and the nature of stats vis-a-vis transactions. No, that's not right. I think you might be thinking of pgStatLocal.snapshot.stats? I guess I should add a paragraph about snapshots / fetch consistency. > Even before I added the read-only and transaction-scoped I got a bit hung > up on reading: > "The shared hashtable only needs to be accessed when no prior reference to > the shared hashtable exists." > Thinking in terms of key seems to make more sense than value in this > sentence - even if there is a one-to-one correspondence. Maybe "prior reference to the shared hashtable exists for the key"? > I am wondering why there are no mentions to the header files in this > architecture, only the .c files. Hm, I guess, but I'm not sure it'd add a lot? It's really just intended to give a starting point (and it can't be worse than explanation of the current system). > diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c > index bfbfe53deb..504f952c0e 100644 > --- a/src/backend/utils/activity/pgstat.c > +++ b/src/backend/utils/activity/pgstat.c > @@ -4,9 +4,9 @@ > * > * > * PgStat_KindInfo describes the different types of statistics handled. Some > - * kinds of statistics are collected for fixed number of objects > - * (e.g. checkpointer statistics). Other kinds are statistics are collected > - * for variable-numbered objects (e.g. relations). > + * kinds of statistics are collected for a fixed number of objects > + * (e.g., checkpointer statistics). Other kinds of statistics are collected Was that comma after e.g. intentional? Applied the rest. > + * for a varying number of objects (e.g., relations). > * Fixed-numbered stats are stored in plain (non-dynamic) shared memory. > * > @@ -19,19 +19,21 @@ > * > * All variable-numbered stats are addressed by PgStat_HashKey while running. > * It is not possible to have statistics for an object that cannot be > - * addressed that way at runtime. A wider identifier can be used when > + * addressed that way at runtime. A alternate identifier can be used when > * serializing to disk (used for replication slot stats). Not sure this improves things. > * The names for structs stored in shared memory are prefixed with > * PgStatShared instead of PgStat. > @@ -53,15 +55,16 @@ > * entry in pgstat_kind_infos, see PgStat_KindInfo for details. > * > * > - * To keep things manageable stats handling is split across several > + * To keep things manageable, stats handling is split across several Done. > * files. Infrastructure pieces are in: > - * - pgstat.c - this file, to tie it all together > + * - pgstat.c - this file, which ties everything together I liked that :) > - * Each statistics kind is handled in a dedicated file: > + * Each statistics kind is handled in a dedicated file, though their structs > + * are defined here for lack of better ideas. -0.5 Greetings, Andres Freund