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 1smDGA-0044tf-8y for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Sep 2024 14:14:54 +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 1smDG8-00BSWp-Sm for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Sep 2024 14:14:53 +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 1smDG8-00BSUy-JA for pgsql-hackers@lists.postgresql.org; Thu, 05 Sep 2024 14:14:52 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1smDG6-000IPn-Ar for pgsql-hackers@lists.postgresql.org; Thu, 05 Sep 2024 14:14:52 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-37747c1d928so491424f8f.1 for ; Thu, 05 Sep 2024 07:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725545689; x=1726150489; 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=NpXl8UPL0Sg9PobaGKoV4IC7L1ziUYb2Nxhy+l4L0EA=; b=WzadSLfB+HF4iKnksk8wMdDvcm5seTfUPZlQOlsqgyFFWDCgsHoy1x6fKrKGtNeI5L AfyGUdxfzNxjNQvEa5R2tNwVDGmQhzfF+2o8xKkkOtyVOZIeO1MlX6QKEzeMfMiaAYFY dw3/coOaXhe70LIddeNOYU0UTtBkZCWxML1S2I2g2BKUC1RX6/CycrZQmDS3DpHnePLn 8/qUz8eArN8qojKJsdxmEU1926EZLzjPQ5e+DyN6oUGMkVw85W3efrq42uSW9QG8r5OG 5SeWK/2FpkrSSUfsImYhxcibIa9oKRd2NhN9MauMmLEhrBcz3/XshtkZ2MqPc2hNIxXm 2s6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725545689; x=1726150489; 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=NpXl8UPL0Sg9PobaGKoV4IC7L1ziUYb2Nxhy+l4L0EA=; b=cobs8Bdfa4fQ1AU+Npa0+XP4MOn1NxP9uny65kq0lCeHgo5K0EBctgnAylpxpks2O5 XrlSOH27Ij46Tz1rOmgbrHkUhZtT8APF7qKavBw7UpFu/LUSTty/6+9okFF91X7sKihF KLoD6PJRFU2SUaneEtGsUh+CDYsGgJMdtLO7/lNicLUY5/iOOVODj8XsVQp/jsZDOfo6 Fvhx+Rc9fwtcjCTt8/UzPIhz5R4rK5adxc5Y2QRWxy9mC4uW3DKV9QsxLKG8fjoR3YAc 303iLDz5vvnop0vlUdYWuyvyXvYtl37Cg8JecQjeICTjgzuXEurmORwyEvpdGTxgbMOm j37w== X-Forwarded-Encrypted: i=1; AJvYcCWcr+k0uFvJvdPPmFWUco1srj1X6ekVxqh3INSuQdgUPQ/OdIMWEKzZTgbh+Qek+MUcgIHgru+sdDpXDXlb@lists.postgresql.org X-Gm-Message-State: AOJu0YzR1FRh38UirpvlkGqwdMTkEWdO24f6QgXbQGRI94LRYC9cgJMC nx6GMGZmF9RKcUWHpKAyk1ryLfqgb7FbEvbFfY/wTJ/8fu69IoqQ X-Google-Smtp-Source: AGHT+IEoUD+3G/uya6wCaeTsxf3rcUM1VP2z/wS3bJzi4gcOC7q8H8ExXDYXdgN6WB2/rQOCYCZf4Q== X-Received: by 2002:a05:6000:1944:b0:371:9395:9c2d with SMTP id ffacd0b85a97d-374bf1e46f4mr9996698f8f.55.1725545688961; Thu, 05 Sep 2024 07:14:48 -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 ffacd0b85a97d-374cf7e2dbfsm9467951f8f.37.2024.09.05.07.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 07:14:48 -0700 (PDT) Date: Thu, 5 Sep 2024 14:14:47 +0000 From: Bertrand Drouvot To: Alvaro Herrera Cc: 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: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202409051303.qumelxccgzzn@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Sep 05, 2024 at 03:03:32PM +0200, Alvaro Herrera wrote: > On 2024-Sep-03, Bertrand Drouvot wrote: > > > Cons is probably allocating shared memory space that might not be used ( > > sizeof(PgStat_IO) is 16392 so that could be a concern for a high number of > > unused connection). OTOH, if a high number of connections is not used that might > > be worth to reduce the max_connections setting. > > I was surprised by the size you mention so I went to look for the > definition of that struct: > Thanks for looking at it! > typedef struct PgStat_IO > { > TimestampTz stat_reset_timestamp; > PgStat_BktypeIO stats[BACKEND_NUM_TYPES]; > } PgStat_IO; > > (It would be good to have more than zero comments here BTW) > > So what's happening is that struct PgStat_IO stores the data for every > single process type, be it regular backends, backend-like auxiliary > processes, and all other potential postmaster children. Yeap. > So it seems to > me that storing one of these struct for "my backend stats" is wrong: I > think you should be using PgStat_BktypeIO instead (or maybe another > struct which has a reset timestamp plus BktypeIO, if you care about the > reset time). That struct is only 1024 bytes long, so it seems much more > reasonable to have one of those per backend. Yeah, that could be an area of improvement. Thanks, I'll look at it. Currently the filtering is done when retrieving the per backend stats but better to do it when storing the stats. > Another way to think about this might be to say that the B_BACKEND > element of the PgStat_Snapshot.io array should really be spread out to > MaxBackends separate elements. This would make it more difficult to > obtain a total value accumulating ops done by all backends (since it's > require to sum the values of each backend), but it allows you to obtain > backend-specific values, including those of remote backends rather than > only your own, as Kyotaro suggests. > One backend can already see the stats of the other backends thanks to the pg_stat_get_backend_io() function (that takes a backend pid as parameter) that is introduced in the 0002 sub-patch. I'll ensure that's still the case with the next version of the patch. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com