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 1tVtDk-00CNut-2d for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jan 2025 14:09:12 +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 1tVtDj-002NWn-5S for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jan 2025 14:09:10 +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 1tVtDi-002NWe-H6 for pgsql-hackers@lists.postgresql.org; Thu, 09 Jan 2025 14:09:10 +0000 Received: from forward100b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:d100]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tVtDe-000icp-1S for pgsql-hackers@postgresql.org; Thu, 09 Jan 2025 14:09:08 +0000 Received: from mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:292e:0:640:3761:0]) by forward100b.mail.yandex.net (Yandex) with ESMTPS id 3CDA260E84; Thu, 9 Jan 2025 17:09:03 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id w8oUTJ2OeW20-YfmxjcWI; Thu, 09 Jan 2025 17:09:02 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tantorlabs.com; s=mail; t=1736431742; bh=8avI9jQugxnqdhoGRsravDxR9nluIRcmaLtlMjVm9hQ=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=hdKCBdekpZ7eKWe3DEdAg7STQzu1AyTQg4FqKeTsqTeFLtTuDwFVkPCU/UXay7YEW PAmKOZ3yBbOUavSlzl0G1+s3s8tKkb0xuLyqPiUIVNbF35mqLqgkEdQsWRolIuxLcF I1yuNpgpkuk8w7GMODBC1916yY5kNqkoB5OzfACo= Authentication-Results: mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net; dkim=pass header.i=@tantorlabs.com Message-ID: <5be4578b-cfdb-4129-b1d0-58d4d5e0bd84@tantorlabs.com> Date: Thu, 9 Jan 2025 17:08:58 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Sample rate added to pg_stat_statements To: Sami Imseih Cc: "Andrey M. Borodin" , Alexander Korotkov , Michael Paquier , Greg Sabino Mullane , pgsql-hackers References: <6707FCA9-FD1A-4609-A1A6-142456C14E0C@yandex-team.ru> <320a31e6-4c91-438b-ab17-8a1d72384727@tantorlabs.com> <52e5e3aa-066a-4daf-8d65-77c34a2f0d98@tantorlabs.com> <6482A576-4465-4E46-A42C-F1767E8DDE30@yandex-team.ru> <20994d10-ab44-4c6b-91bc-c4675cd2e58e@tantorlabs.com> <9D8A5BC8-A3A5-4DA9-9382-F30D343247D1@yandex-team.ru> <6cf6270b-e8fa-4d99-b74a-17e781cdf309@tantorlabs.com> <9af7cb4e-d191-421f-85a2-22d8c406b47a@tantorlabs.com> Content-Language: en-US From: Ilia Evdokimov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 09.01.2025 05:29, Sami Imseih wrote: >> Unfortunately, these changes do not achieve the intended sampling goal. >> I looked into this more deeply: while the sampled-out queries do not >> appear in pg_stat_statements, an entry is still allocated in the hash >> table after normalization, which, in my view, should not happen when >> sampling is in effect. Therefore, patch v9 is unlikely to meet our needs. > pg_stat_statements creates entries as "sticky" initially to give them > more time to stay in the hash before the first execution completes. > It's not perfect, but it works for the majority of cases. So, what you > are observing is how pg_stat_statements currently works. > > If an entry is popular enough, we will need it anyways ( even > with the proposed sampling ). An entry that's not popular will > eventually be aged out. > > From my understanding, what the proposed sampling will do is > to reduce the overhead of incrementing counters of popular entries, > because of the spinlock to update the counters. This is particularly > the case with high concurrency on large machines ( high cpu count ), > and especially when there is a small set of popular entries. > IMO, This patch should also have a benchmark that proves > that a user can benefit with sampling in those types of > workloads. Ah, so patch version 9 might be the best fit to achieve this. I’ll need to benchmark it on a large, high-concurrency machine then. -- Best regards, Ilia Evdokimov, Tantor Labs LLC.