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 1tdSGB-007Lml-Hj for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Jan 2025 10:59:00 +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 1tdSG8-00BDHX-E0 for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Jan 2025 10:58:56 +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 1tdSG8-00BDHP-33 for pgsql-hackers@lists.postgresql.org; Thu, 30 Jan 2025 10:58:56 +0000 Received: from forward102d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:d102]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tdSG4-002HYu-1n for pgsql-hackers@postgresql.org; Thu, 30 Jan 2025 10:58:54 +0000 Received: from mail-nwsmtp-smtp-production-main-77.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-77.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:4caf:0:640:9790:0]) by forward102d.mail.yandex.net (Yandex) with ESMTPS id F113A60995; Thu, 30 Jan 2025 13:58:48 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-77.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id lwc9NJ7OniE0-9cOOg0SV; Thu, 30 Jan 2025 13:58:48 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tantorlabs.com; s=mail; t=1738234728; bh=EcW5JjCb4kqohOSg2dDjTpMjoiWNHLs+UTm7+MSmhRE=; h=In-Reply-To:Cc:Date:References:To:From:Subject:Message-ID; b=lfJd7hUdL81wcfvCO/CX3elxAocAMAAYuzoeuIghUB1YrkbDbJfdFWj0O91MRYNt4 D97GFV/Xc4tJxRG4CRpJEAJPJyYT3Ls83Qc/7yZqvoZ7JDlZvlIMhGA2i2MHSGwNCb BD605sLFPxoEdG5OqC3D4aAETzaI8Zy0i4SqM3as= Authentication-Results: mail-nwsmtp-smtp-production-main-77.klg.yp-c.yandex.net; dkim=pass header.i=@tantorlabs.com Message-ID: <4f98ec33-c627-4eb4-84f3-9994a0982277@tantorlabs.com> Date: Thu, 30 Jan 2025 13:58:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Sample rate added to pg_stat_statements From: Ilia Evdokimov To: Sami Imseih Cc: Andrey Borodin , Alena Rybakina , Alexander Korotkov , Michael Paquier , Greg Sabino Mullane , pgsql-hackers References: <20994d10-ab44-4c6b-91bc-c4675cd2e58e@tantorlabs.com> <9D8A5BC8-A3A5-4DA9-9382-F30D343247D1@yandex-team.ru> <6cf6270b-e8fa-4d99-b74a-17e781cdf309@tantorlabs.com> <3a27c830-b81f-4560-9774-a87d9b922fbd@tantorlabs.com> <7AD765EF-14DE-4B3E-8282-E82A9B44DBAA@yandex-team.ru> <0c7770bd-9750-4200-a472-bdb262583c2f@tantorlabs.com> <18631d46-1741-4edc-b116-8d9631cdf919@tantorlabs.com> Content-Language: en-US In-Reply-To: <18631d46-1741-4edc-b116-8d9631cdf919@tantorlabs.com> 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 29.01.2025 21:52, Ilia Evdokimov wrote: > >>> ... I also attached the benchmark.sh >>> script used to generate the output. > > > In my opinion, if we can't observe bottleneck of spinlock on 32 CPUs, > we should determine the CPU count at which it becomes. This will help > us understand the scale of the problem. Does this make sense, or are > there really no real workloads where the same query runs on more than > 32 CPUs, and we've been trying to solve a non-existent problem? I ran the same benchmark on 48 CPUs for -c 48 -j 20 for objectivity. ### 48 connections pgbench -c48 -j20 -S -Mprepared -T120 --progress 10 sample_rate = 1 tps = 643251.640175 (without initial connection time) waits -----     932  ClientRead     911  CPU      44  SpinDelay sample_rate = .75 tps = 653946.777122 (without initial connection time) waits -----     939  CPU     875  ClientRead       3  SpinDelay sample_rate = .5 tps = 651654.348463 (without initial connection time) waits -----     932  ClientRead     841  CPU sample_rate = .25 tps = 652668.807245 (without initial connection time) waits -----     910  ClientRead     860  CPU sample_rate = 0 tps = 659111.347019 (without initial connection time) waits -----     882  ClientRead     849  CPU There is a small amount ofSpinDelay, as the user mentioned. However, we can identify the threshold where the problem appears. To summarize the results of all benchmarks, I compiled them into a table:  CPUs | sample_rate | tps | CPU waits | ClientRead wait | SpinDelay wait   192 |         1.0 | 484338|      9568 |             929 | 11107   192 |        0.75 | 909547|      12079 |            2100 | 4781   192 |         0.5 |1028594|     13253 |            3378 | 174   192 |        0.25 |1019507|     13397 |            3423 | -   192 |         0.0 |1015425|     13106 |            3502 | -    48 |         1.0 | 643251|       911 |             932 | 44    48 |        0.75 | 653946|       939 |             939 |  3    48 |         0.5 | 651654|       841 |             932 | -    48 |        0.25 | 652668|       860 |             910 | -    48 |         0.0 | 659111|       849 |             882 | -    32 |         1.0 | 620667|      1782 |             560 | -    32 |        0.75 | 620667|      1736 |             554 | -    32 |         0.5 | 624094|      1741 |             648 | -    32 |        0.25 | 628638|      1702 |             576 | -    32 |         0.0 | 630483|      1638 |             574 | - -- Best regards, Ilia Evdokimov, Tantor Labs LLC.