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 1tcpHj-002yKY-O4 for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Jan 2025 17:22: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 1tcpHi-002U4C-Pi for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Jan 2025 17:21:58 +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 1tcpHi-002U44-EY for pgsql-hackers@lists.postgresql.org; Tue, 28 Jan 2025 17:21:58 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tcpHe-00206f-30 for pgsql-hackers@postgresql.org; Tue, 28 Jan 2025 17:21:57 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-3061513d353so62879501fa.2 for ; Tue, 28 Jan 2025 09:21:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738084914; x=1738689714; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DVb+aFFUaVfFRH9aA55bqcw6wnN0Ibf1CUmnWe/qLSs=; b=BF8wyaNGxXd8DWMrVLHZRNv2xDirCqTdxnnMhrZxZwQUmjZcCZ/Vt/Y8m8wUnDIhXs tZdwDzIUAzeGiygKT84sZ/BTE9eBEcEdPaTPb8WyoEzfn1uKu9piu+uKZNKmiN2/jOLM cIcbB06Pbs9WMjRe0+CV2w2o4l81fAR4lyW6lhfQDo7jUw17PInquaXA9BsNYLaNWBwN 88yuFxDxqT7jFntNabJ5vxqjUCW3JAj7GB2Q2zMWyClzpmCR2Vy//50YNJj9thNZV+vr VIS3WL9ZlMK+/gwtnADhdZlEn1JnzKdReEAvLFnha3W+f+jwJjHAAWtsihgyuDBpB5cB FCzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738084914; x=1738689714; h=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=DVb+aFFUaVfFRH9aA55bqcw6wnN0Ibf1CUmnWe/qLSs=; b=kYyQ1qqaQaeHVVW9BOQYTpTnIASXm7Le030DHWajtZPI8YNRGjolfJGtOI59LKYhTq GpGBGazSiemONRn1ZU5MZUs3SBVJuEIIKhm8dz4RMve4gz5UTOIDDFiwHNVnz0lrlTRi Qh1AIwhRhy6FfvnfM4vKgnrYThuoqSu7NSgQrrp5w0hja4fibL6dgRYB+DAQrRbulwob AS4e6ffl3cbBIYdvYoFDCE71NYaM8c3AtU867xc4eN7Z2I0YEEwBduMB4Ab6/EGL0Yo3 o2fdKfrPQjyGa6Aevd/thpl2KXrpdR0hQdzvICnBgZCdGCwynkrOSS1ryD6RdXu/50J6 8cWw== X-Forwarded-Encrypted: i=1; AJvYcCVgBJx4sBmUAaDDTE2jfmguG0kKqkCuJXk8h76cewEYFFEBOBgNnmsfDBMG/gVHfFcjGShqDJ06i34XL5Bb@postgresql.org X-Gm-Message-State: AOJu0Yx32wq0y9touYY7tn84zIicZShPuwQOQSs0lmwxtEa9LVjwu2Yt tH5oIriKLrPFClGGx4saKZWqN/tX9LuH5VKyAh9m9Zz9n7qjwFSLtdgBTPZnF0ApwrIc6SPkfHc cJ0xMxQ9s7pZHtAVyVdLfaCEWlMk= X-Gm-Gg: ASbGncuoFGvY5O92gRbAhFXGU7SQl/N0sl7cMhJ9HEMLAk+uKRjQGrQG6dYBmOGIC1a IMS33ylNTTlJYE3W3Ps+4ICLPq60y6rtkjQv0lowl5JWqjqwnggt4+hrPjHUj1QHctSX1WGI= X-Google-Smtp-Source: AGHT+IFeongnU2IQ8qS/aZParUxuPEbqJJP+b22cdOmlG1esehglyXDGW6AAd9a9+lQbV0DaC9Qn5kQdY94R8kkVuHk= X-Received: by 2002:a2e:a883:0:b0:302:264e:29dd with SMTP id 38308e7fff4ca-307968c5d79mr533171fa.24.1738084914188; Tue, 28 Jan 2025 09:21:54 -0800 (PST) MIME-Version: 1.0 References: <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> <3a27c830-b81f-4560-9774-a87d9b922fbd@tantorlabs.com> <7AD765EF-14DE-4B3E-8282-E82A9B44DBAA@yandex-team.ru> <0c7770bd-9750-4200-a472-bdb262583c2f@tantorlabs.com> In-Reply-To: <0c7770bd-9750-4200-a472-bdb262583c2f@tantorlabs.com> From: Sami Imseih Date: Tue, 28 Jan 2025 11:21:42 -0600 X-Gm-Features: AWEUYZlRv8yalfL7WCS3JfbrgGX0UVVibzSEcgEwvZyZO2lSoiekQOSH3zyTiGQ Message-ID: Subject: Re: Sample rate added to pg_stat_statements To: Ilia Evdokimov Cc: Andrey Borodin , Alena Rybakina , Alexander Korotkov , Michael Paquier , Greg Sabino Mullane , pgsql-hackers Content-Type: multipart/mixed; boundary="000000000000e66e19062cc76d83" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e66e19062cc76d83 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > All the changes mentioned above are included in the v13 patch. Since the > patch status is 'Ready for Committer,' I believe it is now better for > upstream inclusion, with improved details in tests and documentation. Do > you have any further suggestions? I am not quite clear on the sample_1.out. I do like the idea of separating the sample tests, but I was thinking of something a bit more simple. What do you think of my attached, sampling.sql, test? It tests sample rate in both simple and extended query protocols and for both top level and nested levels? > If anyone has the capability to run this benchmark on machines with more > CPUs or with different queries, it would be nice. I=E2=80=99d appreciate = any > suggestions or feedback. I wanted to share some additional benchmarks I ran as well on a r8g.48xlarge ( 192 vCPUs, 1,536 GiB of memory) configured with 16GB of shared_buffers. I also attached the benchmark.sh script used to generate the output. The benchmark is running the select-only pgbench workload, so we have a single heavily contentious entry, which is the worst case. The test shows that the spinlock (SpinDelay waits) becomes an issue at high connection counts and will become worse on larger machines. A sample_rate going from 1 to .75 shows a 60% improvement; but this is on a single contentious entry. Most workloads will likely not see this type of improvement. I also could not really observe this type of difference on smaller machines ( i.e. 32 vCPUs), as expected. ## init pgbench -i -s500 ### 192 connections pgbench -c192 -j20 -S -Mprepared -T120 --progress 10 sample_rate =3D 1 tps =3D 484338.769799 (without initial connection time) waits ----- 11107 SpinDelay 9568 CPU 929 ClientRead 13 DataFileRead 3 BufferMapping sample_rate =3D .75 tps =3D 909547.562124 (without initial connection time) waits ----- 12079 CPU 4781 SpinDelay 2100 ClientRead sample_rate =3D .5 tps =3D 1028594.555273 (without initial connection time) waits ----- 13253 CPU 3378 ClientRead 174 SpinDelay sample_rate =3D .25 tps =3D 1019507.126313 (without initial connection time) waits ----- 13397 CPU 3423 ClientRead sample_rate =3D 0 tps =3D 1015425.288538 (without initial connection time) waits ----- 13106 CPU 3502 ClientRead ### 32 connections pgbench -c32 -j20 -S -Mprepared -T120 --progress 10 sample_rate =3D 1 tps =3D 620667.049565 (without initial connection time) waits ----- 1782 CPU 560 ClientRead sample_rate =3D .75 tps =3D 620663.131347 (without initial connection time) waits ----- 1736 CPU 554 ClientRead sample_rate =3D .5 tps =3D 624094.688239 (without initial connection time) waits ----- 1741 CPU 648 ClientRead sample_rate =3D .25 tps =3D 628638.538204 (without initial connection time) waits ----- 1702 CPU 576 ClientRead sample_rate =3D 0 tps =3D 630483.464912 (without initial connection time) waits ----- 1638 CPU 574 ClientRead Regards, Sami --000000000000e66e19062cc76d83 Content-Type: application/octet-stream; name="sampling.sql" Content-Disposition: attachment; filename="sampling.sql" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_m6gq8ryv0 LS0KLS0gc2FtcGxlIHN0YXRlbWVudHMKLS0KCi0tIHRvcC1sZXZlbCB0cmFja2luZyAtIHNpbXBs ZSBxdWVyeSBwcm90b2NvbApTSE9XIHBnX3N0YXRfc3RhdGVtZW50cy50cmFjazsKU0VUIHBnX3N0 YXRfc3RhdGVtZW50cy5zYW1wbGVfcmF0ZSA9IDAuMDsKU0VMRUNUIHBnX3N0YXRfc3RhdGVtZW50 c19yZXNldCgpIElTIE5PVCBOVUxMIEFTIHQ7ClNFTEVDVCAxIEFTICJpbnQiOwpTRUxFQ1QgcXVl cnksIGNhbGxzIEZST00gcGdfc3RhdF9zdGF0ZW1lbnRzIE9SREVSIEJZIHF1ZXJ5IENPTExBVEUg IkMiOwpTRVQgcGdfc3RhdF9zdGF0ZW1lbnRzLnNhbXBsZV9yYXRlID0gMS4wOwpTRUxFQ1QgMSBB UyAiaW50IjsKU0VMRUNUIHF1ZXJ5LCBjYWxscyBGUk9NIHBnX3N0YXRfc3RhdGVtZW50cyBPUkRF UiBCWSBxdWVyeSBDT0xMQVRFICJDIjsKCi0tIHRvcC1sZXZlbCB0cmFja2luZyAtIGV4dGVuZGVk IHF1ZXJ5IHByb3RvY29sClNFVCBwZ19zdGF0X3N0YXRlbWVudHMuc2FtcGxlX3JhdGUgPSAwLjA7 ClNFTEVDVCBwZ19zdGF0X3N0YXRlbWVudHNfcmVzZXQoKSBJUyBOT1QgTlVMTCBBUyB0OwpTRUxF Q1QgMSBccGFyc2Ugc3RtdApcYmluZF9uYW1lZCBzdG10IFxnClNFTEVDVCBxdWVyeSwgY2FsbHMg RlJPTS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oKSBJUyBOT1Qg TlVMTCBBUyB0OwpTRVQgcGdfc3RhdF9zdGF0ZW1lbnRzLnNhbXBsZV9yYXRlID0gMTsKRVhQTEFJ TiAoQ09TVFMgT0ZGKSBTRUxFQ1QgMTsgXHBhcnNlIHN0bXQKXGJpbmRfbmFtZWQgc3RtdCBcZwpc YmluZF9uYW1lZCBzdG10IFxnClNFVCBwZ19zdGF0X3N0YXRlbWVudHMuc2FtcGxlX3JhdGUgPSAw OwpcYmluZF9uYW1lZCBzdG10IFxnClxiaW5kX25hbWVkIHN0bXQgXGcKU0VMRUNUIHRvcGxldmVs LCBjYWxscywgcXVlcnkgRlJPTSBwZ19zdGF0X3N0YXRlbWVudHMKICBPUkRFUiBCWSBxdWVyeSBD T0xMQVRFICJDIjs= --000000000000e66e19062cc76d83 Content-Type: application/x-sh; name="benchmark.sh" Content-Disposition: attachment; filename="benchmark.sh" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_m6gqfaap1 IyMjIHdhaXRzLnNxbApcbyAvdG1wL3dhaXRzCnNlbGVjdCAnT1VUJywgQ09BTEVTQ0Uod2FpdF9l dmVudCwgJ0NQVScpIHdhaXQgZnJvbSAgcGdfc3RhdF9hY3Rpdml0eSB3aGVyZSBzdGF0ZSA9ICdh Y3RpdmUnOwpcd2F0Y2ggMQoKCgojIyMgcGdiZW5jaApDT05ORUNUSU9OUz0xOTIKcGdiZW5jaCAt aSAtczUwMAoKcm0gLXJmdiAvdG1wL3Jlc3VsdHMKZm9yIGkgaW4gMSAuNzUgLjUgLjI1IDAKZG8K ICBwc3FsIC1jICJhbHRlciBzeXN0ZW0gc2V0IHBnX3N0YXRfc3RhdGVtZW50cy5zYW1wbGVfcmF0 ZSA9ICR7aX07IiAyPi9kZXYvbnVsbCA+L2Rldi9udWxsCiAgcHNxbCAtYyAic2VsZWN0IHBnX3Jl bG9hZF9jb25mKCk7IiAyPi9kZXYvbnVsbCA+L2Rldi9udWxsCiAgcHNxbCAtYyAic2hvdyB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