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 1sliZk-000lUj-It for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Sep 2024 05:29:04 +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 1sliZi-004SJp-Dq for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Sep 2024 05:29:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sliZi-004SJh-4F for pgsql-hackers@lists.postgresql.org; Wed, 04 Sep 2024 05:29:02 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sliZf-0003kL-UH for pgsql-hackers@lists.postgresql.org; Wed, 04 Sep 2024 05:29:01 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-374b9761eecso3075780f8f.2 for ; Tue, 03 Sep 2024 22:28:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725427738; x=1726032538; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=4cQHxk74ZcKjTYK07CSig36El6IfiXN+UMfGQzGnfTg=; b=NpvmMgg7tUs4Tsne9T2nyDHhmU5HnOyKk9q8hDbnllu06N7La4zM6wocvZKhwPypGm s8pxmJIc4rkPDiaAc1hRh7p/wDmKhbAIW8lK5R5LdKsxcYvgOmqxdDpqAdcOIk2CFYQ1 3IzEP4F2UVgsY1Mm1yyad+UkVmBhOxWWAGRNNN6NEMAXvqdXUuiTiBvGLqFEBjoyfIsF FArgQI/ONos5QrEhAj56YVwFoFrKET0KbIArUH+Ctqy+xN1ggtstYtNqAB/9NHA+eNpA uiMaYkdGx8Scrobky+P7gb5gIL6UrIVjO8I13Yd6HVwRLNqEn/MjovQeGtszqUZ5XBsh CBGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725427738; x=1726032538; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4cQHxk74ZcKjTYK07CSig36El6IfiXN+UMfGQzGnfTg=; b=ofHFWlWP97Ne40hNEzDEhEYoKMg+l0uLlXFxAJQThTXUmdYLSjAYpgLnDNfIlVhLYj o/dHuSokfbuvRgg8lqXOxxIGl8OpauZp6oYzJnD6A/WVYdo+mXG1GOCH71K1OupV6sJG Y67IofOssxyGE0U1Z10fcWW4aRSOxEvouiEk84wIqW+veo6x1WGiQOE9ncTN88qcEJaL /jB1yVPNXzkcgTUYOyaziIvfK8BMADGjKyhzDfC+uNOFBeVkdQFcUas0fMc9TO4+oYUS OgVsn1ORc4IQtdlrn25XZOL0JLeYMTFAUx/+nMtjfRU7XFJ8/noUd6Uq+V7s4A+iQ7nJ aZaw== X-Forwarded-Encrypted: i=1; AJvYcCUvYKhhw2us6lPyq+MLnpiryYV5hH7LUodNUBf5Rngvek85jPky0V09QJXs+xFCynefjufz/6Yq5LrTKBdj@lists.postgresql.org X-Gm-Message-State: AOJu0YxKn76d+a11RLoGdS9v2SIpEOgqp4+hnq5Tmj3Ni5fxNnlfISXK mdA+8/1nfrN1bnRbVHQ1nuZsiqwP9YQHaK9YifOOfpZVFP7Kn9gu X-Google-Smtp-Source: AGHT+IH/tX5dlUxMy5KoQpBag9pj7EldjQJzjL2TgphEQJZjxEbSOx1xBsdXml28ReQtkxkpH/CBIA== X-Received: by 2002:a5d:6790:0:b0:371:6fba:d555 with SMTP id ffacd0b85a97d-374bcea5a58mr7089135f8f.18.1725427738140; Tue, 03 Sep 2024 22:28:58 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bbd1eee1bsm160492815e9.9.2024.09.03.22.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 22:28:57 -0700 (PDT) Date: Wed, 4 Sep 2024 05:28:56 +0000 From: Bertrand Drouvot To: Kyotaro Horiguchi Cc: michael@paquier.xyz, pgsql-hackers@lists.postgresql.org Subject: Re: Add callbacks for fixed-numbered stats flush in pgstats Message-ID: References: <20240904.140546.948122275033564187.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240904.140546.948122275033564187.horikyota.ntt@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Sep 04, 2024 at 02:05:46PM +0900, Kyotaro Horiguchi wrote: > 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. +1 on the idea. > 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. Agree. Another option could be to add only one callback (the flush_fixed_cb one) and get rid of the have_fixed_pending_cb one. Then add an extra parameter to the flush_fixed_cb that would only check if there is pending stats (without flushing them). I think those 2 callbacks are highly related that's why I think we could "merge" them, thoughts? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com