Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sliDL-000jd5-E8 for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Sep 2024 05:05:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sliDJ-004DcE-V0 for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Sep 2024 05:05:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sliDJ-004Dar-LW for pgsql-hackers@lists.postgresql.org; Wed, 04 Sep 2024 05:05:54 +0000 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sliDH-0004Cn-EO for pgsql-hackers@lists.postgresql.org; Wed, 04 Sep 2024 05:05:53 +0000 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-5df9343b5b8so3958465eaf.0 for ; Tue, 03 Sep 2024 22:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725426350; x=1726031150; darn=lists.postgresql.org; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=EwIg4MobDETc5ZJeBJVG//3o6Vxg01LvQP7p0oKMq/g=; b=Zd1DH2WiWzZPlvxE8cEDKn6jP8sDQLTMnou/3QzscwXdZWUjqK2XYjIQpFRV/pmu7H /nTnbT9UWXrdODaB08gKCdGGfpH3AN2y/g1tVMssCj9LaQdTVPvym2ReeR/YUJ7msdUu lSw4Q3GjAZnSs4jmQU27xkxXdtyZlcUwO32vc3V6bPH0D0zvk5DujSAD9LCBfgWNfb/a kbUVFFZ0xWlDqXU/DpOhmq1VCEZBd2WhrcoLHPEev7AMHg3cjOZ8jE434ZJFdHrm5pTW Mqvz28gLB1OsEXjyFJEcrIZlqVTeMGnzQqAaE581+Krk6K/T9Q4nSyJAmsAi3fMhV8xe Xwag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725426350; x=1726031150; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EwIg4MobDETc5ZJeBJVG//3o6Vxg01LvQP7p0oKMq/g=; b=hPW0UAynDSrqtUjDZSnyPpBMi8aZaCe2zWlNFVcIslSwX1Bq0vQsxHjnr/svASeml1 d57TssiM9yS9TAl0Oy0SK7rVkzWDz78WPvJ7Udf5QeLrQx4pDwl39XTz+KJSBjb1kqyC UeuIhCiRjslLIhq3jm/fehCAMeKODRZx4SAkpuOgQIAGKpPHqeoVO6snQEojZhFAH8HC 3mtE8LbM2qir98vjQeW6fbH+YsFrIR7TguVnRyRPCFNaluQZ+toRLPaujzJxZyk4Ne4g ve8tWTGl5rvueD4tplXmgAJBvqjEx3Rs+7lC/bD7NvKL6MmgyD6I2oco3XWu8s2Rwr/F dFkg== X-Gm-Message-State: AOJu0YzpFCn+oMGG8Snha+WbUdJ8Zk/OFnk1OIs86nYVvZAlzlf0vglF IBdUMngApsSSV2JLq6pDVXc3DA25iruFULOZk8hFuURSmmeZD8ae X-Google-Smtp-Source: AGHT+IGoCsOdQCee/SxlO1uTdt424vrvXEp8WGk1HI4Jg41+rj1pEaajXMsw6JCB68gJHEnXauWSkw== X-Received: by 2002:a05:6358:9485:b0:1b7:fb33:23c with SMTP id e5c5f4694b2df-1b8117ef5cbmr631297955d.20.1725426349559; Tue, 03 Sep 2024 22:05:49 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71778521026sm772062b3a.18.2024.09.03.22.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 22:05:49 -0700 (PDT) Date: Wed, 04 Sep 2024 14:05:46 +0900 (JST) Message-Id: <20240904.140546.948122275033564187.horikyota.ntt@gmail.com> To: michael@paquier.xyz Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Add callbacks for fixed-numbered stats flush in pgstats From: Kyotaro Horiguchi In-Reply-To: References: User-Agent: Mew version 6.8 on Emacs 27.2 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk At Tue, 3 Sep 2024 13:48:59 +0900, Michael Paquier wrote in > Hi all, > > The last TODO item I had in my bucket about the generalization of > pgstats is the option to a better control on the flush of the stats > depending on the kind for fixed-numbered stats. Currently, this is > controlled by pgstat_report_stat(), that includes special handling for > WAL, IO and SLRU stats, with two generic concepts: > - Check if there are pending entries, allowing a fast-path exit. > - Do the actual flush, with a recheck on pending entries. > > SLRU and IO control that with one variable each, and WAL uses a > routine for the same called pgstat_have_pending_wal(). Please find > attached a patch to generalize the concept, with two new callbacks > that can be used for fixed-numbered stats. SLRU, IO and WAL are > switched to use these (the two pgstat_flush_* routines have been kept > on purpose). This brings some clarity in the code, by making > have_iostats and have_slrustats static in their respective files. The > two pgstat_flush_* wrappers do not need a boolean as return result. The generalization sounds good to me, and hiding the private flags in private places also seems good. Regarding pgstat_io_flush_cb, I think it no longer needs to check the have_iostats variable, and that check should be moved to the new pgstat_flush_io(). The same applies to pgstat_wal_flush_cb() (and pgstat_flush_wal()). As for pgstat_slru_flush_cb, it simply doesn't need the check anymore. > Running Postgres on scissors with a read-only workload that does not > trigger stats, I was not able to see a difference in runtime, but that > was on my own laptop, and I am planning to do more measurements on a > bigger machine. I don't think it matters, since the actual flushing occurs at 10-second intervals during busy times. We could change the check from a callback to a variable, but that would just shift the function call overhead to a more frequently called side. > This is in the same line of thoughts as the recent thread about the > backend init callback, generalizing more the whole facility: > https://www.postgresql.org/message-id/ZtZr1K4PLdeWclXY@paquier.xyz > > Like the other one, I wanted to send that a few days ago, but well, > life likes going its own ways sometimes. reards. -- Kyotaro Horiguchi NTT Open Source Software Center