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 1srVEZ-002ANm-86 for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Sep 2024 04:27:08 +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 1srVEX-00Ead3-7M for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Sep 2024 04:27:06 +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 1srVEW-00Eacv-Ss for pgsql-hackers@lists.postgresql.org; Fri, 20 Sep 2024 04:27:06 +0000 Received: from fout4-smtp.messagingengine.com ([103.168.172.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srVEU-0007mL-II for pgsql-hackers@lists.postgresql.org; Fri, 20 Sep 2024 04:27:05 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id F415A1380295; Fri, 20 Sep 2024 00:27:01 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Fri, 20 Sep 2024 00:27:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1726806421; x=1726892821; bh=ooldkWicTn 8dhj6uHqTOREbpC1Nb0rPUREBVeYD30BM=; b=ZeaNF2E2aIEL2Urx5CcV0eWu/4 flxd2SAZjLWqICbACRCR2I1ejtA4ZzA7hxa3T23cz1ErO8OEaFDAEtYIWsc8HgoJ vHkmFwUcVKinDXJJAgHKMUike4/Bg0izd7zMdUdV13BEk4Lq5LT6yhlfgY+65HH3 npCLY+/kbekKrlxPK9FBjC84ZUlM+CN72GVMEycFZJ+gr98fQLU+Y/yaF4omKdZz OE2arEZlg+aClJcIxRLJYmKVPrJw91HSVPIPqLhCdZ8Xxa/ZxYWt1JK94hMITqY9 s/9H3cOxtrvn4rZjOysfFz3HtQQzZ+6gx1vfCcJNccf8gzqTuSx2/+RJzChw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1726806421; x=1726892821; bh=ooldkWicTn8dhj6uHqTOREbpC1Nb 0rPUREBVeYD30BM=; b=dT7FAm0rnmks34zKN4Zgt+Q840/5rbTlZrmwfY5j40k9 QxSAap8it6iQh4yzi2N2t7RotI4Sy+phYNhz16AQtKL36uGNXRiq9Ky4gVu537YT gCuhpexWCXEmhh3CaV5QVHx2KOb4JaQ9j37udehdi5hfymMgKZilgmiEmdO9364u zfPluTEonK4URh8hOpzGn6v53pnsD7iFzubOfcCwVrdGIBDQn4f0UTMfY/meI64I M0Ld6hzZ2vN4+kTyLkPicnk+QlCdY/oMNiIdsUTKbL4ZNWt+6TUvsLaXq9U85+x+ 4ViHSXxyMnvbQAC5fPt+zgo2gTuCuWy7EwsM2Jop7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudelvddgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteel ieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiidpnhgspghrtghpthhtohephedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepsggvrhhtrhgrnhguughrohhuvhhothdrphhgsehgmhgrihhlrdgt ohhmpdhrtghpthhtohepsgihrghvuhiikedusehgmhgrihhlrdgtohhmpdhrtghpthhtoh eprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdprhgtphhtthhopehhohhr ihhkhihothgrrdhnthhtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhh grtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 20 Sep 2024 00:27:00 -0400 (EDT) Date: Fri, 20 Sep 2024 13:26:49 +0900 From: Michael Paquier To: Bertrand Drouvot Cc: Nazir Bilal Yavuz , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: per backend I/O statistics Message-ID: References: <202409051303.qumelxccgzzn@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="J0oayVaz+4AUiI8/" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --J0oayVaz+4AUiI8/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Sep 17, 2024 at 01:56:34PM +0000, Bertrand Drouvot wrote: > No problem at all! (I re-explained because I'm not always 100% sure that my > explanations are crystal clear ;-) ) We've discussed a bit this patch offline, but after studying the patch I doubt that this part is a good idea: + /* has to be at the end due to FLEXIBLE_ARRAY_MEMBER */ + PgStatShared_IO io; } PgStat_ShmemControl; We are going to be in trouble if we introduce a second member in this routine that has a FLEXIBLE_ARRAY_MEMBER, because PgStat_ShmemControl relies on the fact that all its members after deterministic offset positions in this structure. So this lacks flexibility. This choice is caused by the fact that we don't exactly know the number of backends because that's controlled by the PGC_POSTMASTER GUC max_connections so the size of the structure would be undefined. There is a parallel with replication slot statistics here, where we save the replication slot data in the dshash based on their index number in shmem. Hence, wouldn't it be better to do like replication slot stats, where we use the dshash and a key based on the procnum of each backend or auxiliary process (ProcNumber in procnumber.h)? If at restart max_connections is lower than what was previously used, we could discard entries that would not fit anymore into the charts. This is probably not something that happens often, so I'm not really worried about forcing the removal of these stats depending on how the upper-bound of ProcNumber evolves. So, using a new kind of ID and making this kind variable-numbered may ease the implementation quite a bit, while avoiding any extensibility issues with the shmem portion of the patch if these are fixed-numbered. The reporting of these stats comes down to having a parallel with pgstat_count_io_op_time(), but to make sure that the stats are split by connection slot number rather than the current split of pg_stat_io. All its callers are in localbuf.c, bufmgr.c and md.c, living with some duplication in the code paths to gather the stats may be OK. pg_stat_get_my_io() is based on a O(n^3). IOOBJECT_NUM_TYPES is fortunately low, still that's annoying. This would rely on the fact that we would use the ProcNumber for the dshash key, and this information is not provided in pg_stat_activity. Perhaps we should add this information in pg_stat_activity so as it would be easily possible to do joins with a SQL function that returns a SRF with all the stats associated with a given connection slot (auxiliary or backend process)? That would be a separate patch. Perhaps that's even something that has popped up for the work with threading (did not follow this part closely, TBH)? The active PIDs of the live sessions are not stored in the active stats, why not? Perhaps that's useless anyway if we expose the ProcNumbers in pg_stat_activity and make the stats available with a single function taking in input a ProcNumber. Just mentioning an option to consider. -- Michael --J0oayVaz+4AUiI8/ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmbs+YkACgkQnvQgOdby QH1OsQ/+LeD3zCr+61dxG5vrEYzJvtjyRE1vzqSlyfMWi0nAd1a6MeQzbUBoIBM8 v7ekyMwkitljoZ2zIwmdquhKOxrsucsC1bqBxTFoc/NQ2oak0XoNkzR/G+dnlBmA msDAk01SSxEfagPd1NfTwG1RWZhHZ3etH9D2MEttngJx3sICuxZLuSSFoEBmhWaz 5BO6qU4vzD9p5fWihJQZZ6u19txHmzFei9rkcHsGT/C3PYct50s2wW8qNKpph62g 45SX6You4+NKJWO+h6tHOx4nAWOcCYbGSaetHwrEhnYbw0WGiedN0Fh7fqsySORy 3sWqzcdR96O65vUZ5jSzHKx9BZsMpSiYAQ8CSXsTGPeTIIHpXSsbjf6HT7iJOitT UHG7tUYUYUapa3CtkbNx1mpMB36714QRQq6GuOW2atseR/cwYaM44w2xPlgWR5ye wi0lW4cXr0FXCT/otJ4PbBVtFyuL9se+zwdnJ1FXiAjTLdVoHVjea7KMl6C46+Vl bJ0tJwBxKUxKhQEc9QVWNRUVzk8U+efEaFawg79LlL0xEJvyHrWzQfIiJMutjd+7 Ha77vVMJnmRtZlrYPJHQzkeFjBVTT+uj7OGBnO5ct3330tqcFSL6piN+3Gmu+hYb W8khgAOodB8J8pHk+Jd9qiSxqrHkqgK6GRWOYJSSBSzWYHWdnCY= =zkWh -----END PGP SIGNATURE----- --J0oayVaz+4AUiI8/--