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 1oLSOb-0001E7-89 for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Aug 2022 16:47:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oLSOa-0006s1-5d for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Aug 2022 16:47:56 +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 1oLSOZ-0006rs-Rs for pgsql-hackers@lists.postgresql.org; Tue, 09 Aug 2022 16:47:55 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oLSOX-0004Hp-Ma for pgsql-hackers@lists.postgresql.org; Tue, 09 Aug 2022 16:47:55 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 10EB83200915; Tue, 9 Aug 2022 12:47:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 09 Aug 2022 12:47:51 -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; t=1660063670; x=1660150070; bh=JjGS0slwtW 6Z0EYguAq22LgtylrWK95gvxOzJ6+aA/U=; b=CXeA51oN3dQVZn1WReu9ZjQ9gC pedsv6U/6ZbV66dNyzhzuT8pXBU+k7f3+U1RN0V3vOOmZAvSkt9vrmUzTH+s+s9E ihm0E2WpXQ2udO22dU4fsKADOQJRvxZRyZFWYoH1PJ0HUh5GOrEspZ4fp7/8NFXP 6HNXAgvz+wKL/+6Q8y+Nvq8J/1tJJdGDI0yQv5C960h5nYEbeSKQGH4jm5VJMPGS VgJr/7byaR6rVhkpYHLpa/9s1atmXAgr6b1wVD+hblYKc+AkpRMAZloIu+Kl+Apk ml6hHU4hS9E0QcIyuXikwyV4YrNr/EHG6AiBMk+R0SWk6Vyh5axYNqvb+Ehg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id: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= fm1; t=1660063670; x=1660150070; bh=JjGS0slwtW6Z0EYguAq22LgtylrW K95gvxOzJ6+aA/U=; b=UKjqg8QLIfJE2xdK/AxRigXoynF46/Hjsid0/Bm3ZmVC wfqtcR0H5fXQ6xtBv0tb44cs9MnM9S0R689jmh+mhLptsDzS0P1At8rWCNN0bfvv UJPSH0tNBU7N+j5ufBizDOJWPGy1c3h/BQKUameMm8+InFlkAMTybEH8QlVli3a0 BG9t7nO8qtLdRFAqMZCvydYDbyEvcHV5nviZ418EjFR2VQp6+/CGrZYGGGxgfjql KYZaoic95mzNNTOHj4kEJKrPmx6ABBk3eMHeGrFbRtTOVLusPm81ABphB5Y7LaFa NFTB7dnN6Dkj467pWByoXxARWY5AEzaNgrry85l2vQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegtddguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgu rhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtf frrghtthgvrhhnpedvffefvefhteevffegieetfefhtddvffejvefhueetgeeludehteev udeitedtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 9 Aug 2022 12:47:49 -0400 (EDT) Date: Tue, 9 Aug 2022 09:47:48 -0700 From: Andres Freund To: Greg Stark Cc: "Drouvot, Bertrand" , Tom Lane , Melanie Plageman , Kyotaro Horiguchi , Justin Pryzby , Thomas Munro , "David G. Johnston" , PostgreSQL Hackers Subject: Re: shared-memory based stats collector - v70 Message-ID: <20220809164748.6omys6j64yf2a2lr@awork3.anarazel.de> References: <20220405030506.lfdhbu5zf4tzdpux@alap3.anarazel.de> <20220406030008.2qxipjxo776dwnqs@alap3.anarazel.de> <1736122.1658333315@sss.pgh.pa.us> <83D73EC0-E3ED-4C98-A528-5E122278D553@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-08-09 12:00:46 -0400, Greg Stark wrote: > I was more aiming at a C function that extensions could use directly > rather than an SQL function -- though I suppose having the former it > would be simple enough to implement the latter using it. (though it > would have to be one for each stat type I guess) I think such a C extension could exist today, without patching core code? It'd be a bit ugly to include pgstat_internal.h, I guess, but other than that... > The reason I want a C function is I'm trying to get as far as I can > without a connection to a database, without a transaction, without > accessing the catalog, and as much as possible without taking locks. I assume you don't include lwlocks under locks? > I think this is important for making monitoring highly reliable and low > impact on production. I'm doubtful about that, but whatever. > The main problem with my current code is that I'm accessing the shared > memory hash table directly. This means the I'm possibly introducing > locking contention on the shared memory hash table. I don't think that's a large enough issue to worry about unless you're polling at a very high rate, which'd be a bad idea in itself. If a backend can't get the lock for some stats change it'll defer flushing the stats a bit, so it'll not cause a lot of other problems. > I'm thinking of separating the shared memory hash scan from the metric scan > so the list can be quickly built minimizing the time the lock is held. I'd really really want to see some evidence that any sort of complexity here is worth it. > I have a few things I would like to suggest for future improvements to > this infrastructure. I haven't polished the details of it yet but the > main thing I think I'm missing is the catalog name for the object. I > don't want to have to fetch it from the catalog and in any case I > think it would generally be useful and might regularize the > replication slot handling too. I'm *dead* set against including catalog names in shared memory stats. That'll add a good amount of memory usage and complexity, without any sort of comensurate gain. > I also think it would be nice to have a change counter for every stat > object, or perhaps a change time. Prometheus wouldn't be able to make > use of it but other monitoring software might be able to receive only > metrics that have changed since the last update which would really > help on databases with large numbers of mostly static objects. I think you're proposing adding overhead that doesn't even have a real user. Greetings, Andres Freund