Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ivoQC-0001Is-J6 for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jan 2020 20:22:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ivoQB-0005Gx-9I for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jan 2020 20:22:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ivoQ9-0005Gm-Hu for pgsql-hackers@lists.postgresql.org; Sun, 26 Jan 2020 20:22:15 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ivoQ5-0005qY-7e for pgsql-hackers@postgresql.org; Sun, 26 Jan 2020 20:22:13 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B3A16546; Sun, 26 Jan 2020 15:22:05 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 26 Jan 2020 15:22:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=2BAm3Vu3IlT7ea4ALS/WVpLRCyo uCCRMroE9Qxt8yJs=; b=G7G1oMdFy6p3sdit5hHVhepqTjT10wUr548LYaMo0fD ozxwcKdvobeBWNQWCpEk5+g5AglUPRUZdct2A7qujLWE6S/YSu4v+h58lSWnukBm A/FBArKWeQ7rm6lgTrXFpZMtTHXmDwb4oJ6Yew4sGPuiBzbqB+8iT0BfqyJlrx7S 8Rc/TV42Jq638VTd2DLLLhCawbIyKjWaoo3Mwag+f2go5mEiu5CIlNO9Ptki+VPV e0U+lPULHMOgubRN4nk0P6vDs0snRXoRflZOOrxc9gJzMt4f8AVyji3nV48bFE9N aQRjNPS49OkIDs4McSgCqBdCOx8U9W/n7vA9ykJjRBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=2BAm3V u3IlT7ea4ALS/WVpLRCyouCCRMroE9Qxt8yJs=; b=uD1yRAW+qK0Q+otuZp8QgM Q+rJyfbtRSS91zoLWi9pqQiOo2Xcq0Vp+Tut+dLBE5gQeY/ZJ856syhiGBH9lH0s T+jPUbqb8CQf49L+gX6NiGJLAwGwpkMTj7rMZ72GCkNLzArnqD8TybZ84W9aae1a 2deUJB5yvY88exvllLHtMyua41XmKi+1T09fnqdZ+LbazO6YG9wiRAJVCSB8FSHi TjHFDDNegJrDgYlyBHbId0xaeaqmdHBznx5hqWlUCwaAsF1W7yx6c8StE8NLW2rj Xj3cH+2xIh5/CzPgYGIifgR2PLD9XE/JFIqMIu0ovdPp6/TZha5yRFyFvGbv36ZQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrfedtgddufeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucfkphepie ejrdduiedtrddvudejrddvhedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-217-250.hsd1.ca.comcast.net [67.160.217.250]) by mail.messagingengine.com (Postfix) with ESMTPA id D7F5C3280059; Sun, 26 Jan 2020 15:22:04 -0500 (EST) Date: Sun, 26 Jan 2020 12:22:03 -0800 From: Andres Freund To: Magnus Hagander Cc: PostgreSQL-development , Lukas Fittl , Kyotaro Horiguchi , Thomas Munro Subject: Re: pg_stat_bgwriter.buffers_backend is pretty meaningless (and more?) Message-ID: <20200126202203.55lv2u63ptkunnt4@alap3.anarazel.de> References: <20200124195226.lth52iydq2n2uilq@alap3.anarazel.de> <20200126004401.6pipuxkq5yxrudyq@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: Precedence: bulk Hi, On 2020-01-26 16:20:03 +0100, Magnus Hagander wrote: > On Sun, Jan 26, 2020 at 1:44 AM Andres Freund wrote: > > On 2020-01-25 15:43:41 +0100, Magnus Hagander wrote: > > > On Fri, Jan 24, 2020 at 8:52 PM Andres Freund wrote: > > > > Lastly, I don't understand what the point of sending fixed size stats, > > > > like the stuff underlying pg_stat_bgwriter, through pgstats IPC. While > > > > I don't like it's architecture, we obviously need something like pgstat > > > > to handle variable amounts of stats (database, table level etc > > > > stats). But that doesn't at all apply to these types of global stats. > > > > > > That part has annoyed me as well a few times. +1 for just moving that > > > into a global shared memory. Given that we don't really care about > > > things being in sync between those different counters *or* if we loose > > > a bit of data (which the stats collector is designed to do), we could > > > even do that without a lock? > > > > I don't think we'd quite want to do it without any (single counter) > > synchronization - high concurrency setups would be pretty likely to > > loose values that way. I suspect the best would be to have a struct in > > shared memory that contains the potential counters for each potential > > process. And then sum them up when actually wanting the concrete > > value. That way we avoid unnecessary contention, in contrast to having a > > single shared memory value for each(which would just pingpong between > > different sockets and store buffers). There's a few details like how > > exactly to implement resetting the counters, but ... > > Right. Each process gets to do their own write, but still in shared > memory. But do you need to lock them when reading them (for the > summary)? That's the part where I figured you could just read and > summarize them, and accept the possible loss. Oh, yea, I'd not lock for that. On nearly all machines aligned 64bit integers can be read / written without a danger of torn values, and I don't think we need perfect cross counter accuracy. To deal with the few platforms without 64bit "single copy atomicity", we can just use pg_atomic_read/write_u64. These days (e8fdbd58fe) they automatically fall back to using locked operations for those platforms. So I don't think there's actually a danger of loss. Obviously we could also use atomic ops to increment the value, but I'd rather not add all those atomic operations, even if it's on uncontended cachelines. It'd allow us to reset the backend values more easily by just swapping in a 0, which we can't do if the backend increments non-atomically. But I think we could instead just have one global "bias" value to implement resets (by subtracting that from the summarized value, and storing the current sum when resetting). Or use the new global barrier to trigger a reset. Or something similar. Greetings, Andres Freund