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 1tEMqU-006xTJ-Go for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Nov 2024 06:08:46 +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 1tEMqR-005jfR-CW for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Nov 2024 06:08:43 +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 1tEMqQ-005jf7-W3 for pgsql-hackers@lists.postgresql.org; Fri, 22 Nov 2024 06:08:43 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tEMqO-003ECv-Ho for pgsql-hackers@postgresql.org; Fri, 22 Nov 2024 06:08:42 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-aa4d257eb68so329291466b.0 for ; Thu, 21 Nov 2024 22:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732255719; x=1732860519; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=z81EdgNS9apM6hoxkIKe97pMxwub+/iAuOt2lINySNE=; b=PGfpWG2ySPo7ZxBQj48GOglg9dly0KGUQYABgcv1avWXrp8LIGkoXopUM6MAiTwEOj qqFwxLzx+hOnBFEUDzHTV0gziw9AkGxhD1NgLGVdPyQYS1m01GZwBAhDxiZbmwzcEh7F i5QvCJxewgO4GMvNP21y2MDE634m55ZuzTc6mZsQugWNQOunk38stylICxFMPtZl3BC7 +R8Sbkp++JMRq2Osj4mzonfowJ5f4oSUDZeDPs1QDSL7m45I1+tux0xZE4SCrF95Q/Gi AThFiPmMY0ZT+Mwbu9z2vz8uF0dUFmJn9drcs3CbNOIBE5Cnn3/xt60TAIjK5DBFV3Af tjmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732255719; x=1732860519; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z81EdgNS9apM6hoxkIKe97pMxwub+/iAuOt2lINySNE=; b=P/WCuQkO5S5NFr9GU32olXf3+sfeD3+LAAu6GI0vILhTNC4+vKTDM0MUsSZPRnb4Om QlVHdUh8lSNqBuPt2kiMhyChBcpVu/4aMSEYlOYS9KEiba/ATaB9ZqzUR3RYmPcsGmj7 fndmOGMRTuzru0L7Mwk/rHt/lu9Yz6ZhUqE0eAo75KXDGHXJdv1sv8O0z3E6K/PWeVq4 An8lTgTS1hu2TMdM9frIzP4N/oCfYHcxKAP93jjtg4WKCYbddXXp0BpeCqDPM/Xfpq8o eUreS6iaCdDrfCoDzCSQfWgXbnHnF320CPyU+ys6xB5fqlCPSDYrN9lymwL6CYYVzCvj VTLg== X-Forwarded-Encrypted: i=1; AJvYcCULEwCKXOrhSs1BLi7UcPVitypAUxQpibWAdMxA2lB+Y43yOjpMWlBJPkzmkEkV7zWvnoaSTQhQybZYGlKr@postgresql.org X-Gm-Message-State: AOJu0YwoX4grY2opqJKq7n3ajqeDqbovAD6W0LwE1Wy+5b5rAR4BLFLJ wpf2W1JbgMOVzbQ2e4ZgfiKDt1k+C3W1CkGbniymb0wZnfGKyFUndzVUnOd62zowNobxrWUJ8bx XwZKR1fmyBhuV3wojoJUBXmAe8/0= X-Gm-Gg: ASbGnctt6n+Q2CnkCwQ/3VSshanqCtIDUfCpcifLK1AYCfLl8eIIMxOz+Q+SQCELnKa 5mS8uPgJWh38nL7FOOinSS1TrskxYfeM= X-Google-Smtp-Source: AGHT+IHSJze7yvLAAtaNaug0wNpVCLE8HKmjIPgek55uCbLqjKlNjvROCwreFbp2o9UJi8fblYG0KOjHLcwiYzx6+YY= X-Received: by 2002:a17:907:703:b0:a9e:85f8:2a49 with SMTP id a640c23a62f3a-aa4ef969d21mr647932466b.8.1732255719086; Thu, 21 Nov 2024 22:08:39 -0800 (PST) MIME-Version: 1.0 References: <6707FCA9-FD1A-4609-A1A6-142456C14E0C@yandex-team.ru> In-Reply-To: From: Alexander Korotkov Date: Fri, 22 Nov 2024 08:08:28 +0200 Message-ID: Subject: Re: Sample rate added to pg_stat_statements To: Michael Paquier Cc: Greg Sabino Mullane , "Andrey M. Borodin" , Ilia Evdokimov , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Nov 20, 2024 at 12:07=E2=80=AFAM Michael Paquier wrote: > On Tue, Nov 19, 2024 at 09:39:21AM -0500, Greg Sabino Mullane wrote: > > Oh, and a +1 in general to the patch, OP, although it would also be nic= e to > > start finding the bottlenecks that cause such performance issues. > > FWIW, I'm not eager to integrate this proposal without looking at this > exact argument in depth. > > One piece of it would be to see how much of such "bottlenecks" we > would be able to get rid of by integrating pg_stat_statements into > the central pgstats with the custom APIs, without pushing the module > into core. This means that we would combine the existing hash of pgss > to shrink to 8 bytes for objid rather than 13 bytes now as the current > code relies on (toplevel, userid, queryid) for the entry lookup (entry > removal is sniped with these three values as well, or dshash seq > scans). The odds of conflicts still still play in our favor even if > we have a few million entries, or even ten times that. If you run "pgbench -S -M prepared" on a pretty large machine with high concurrency, then spin lock in pgss_store() could become pretty much of a bottleneck. And I'm not sure switching all counters to atomics could somehow improve the situation given we already have pretty many counters. I'm generally +1 for the approach taken in this thread. But I would suggest introducing a threshold value for a query execution time, and sample just everything below that threshold. The slower query shouldn't be sampled, because it can't be too frequent, and also it could be more valuable to be counter individually (while very fast queries probably only matter "in average"). ------ Regards, Alexander Korotkov Supabase