Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcDZy-0005ty-Dl for pgsql-general@arkaria.postgresql.org; Tue, 14 Mar 2023 22:57:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pcDZx-0004LB-As for pgsql-general@arkaria.postgresql.org; Tue, 14 Mar 2023 22:57:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcDZw-0004L1-WD for pgsql-general@lists.postgresql.org; Tue, 14 Mar 2023 22:57:13 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcDZu-0001cW-HR for pgsql-general@lists.postgresql.org; Tue, 14 Mar 2023 22:57:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 32EMv3L43012914; Tue, 14 Mar 2023 18:57:03 -0400 From: Tom Lane To: "Peter J. Holzer" cc: pgsql-general@lists.postgresql.org Subject: Re: Issues Scaling Postgres Concurrency In-reply-to: <20230314220505.wfrbnflrdealumyg@hjp.at> References: <20230314220505.wfrbnflrdealumyg@hjp.at> Comments: In-reply-to "Peter J. Holzer" message dated "Tue, 14 Mar 2023 23:05:05 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3012912.1678834623.1@sss.pgh.pa.us> Date: Tue, 14 Mar 2023 18:57:03 -0400 Message-ID: <3012913.1678834623@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Peter J. Holzer" writes: > On 2023-03-14 22:47:43 +0100, Laurenz Albe wrote: >> A query that counts the number of rows in a table of half a million >> rows is quite expensive and keeps a CPU core busy for a while >> (provided everything is cached). At some degree of parallelism, your >> CPU is overloaded, which leads to non-linear slowdown. > The interesting thing is that on my laptop even two concurrent accesses > cause a 100% slowdown. I think this is because the task is actually > memory-bound: The cores may do the counting in parallel, but they have > to read the data from the same RAM (since it's too large to fit in the > CPU cache) and they have to take turns accessing it. I wondered if synchronize_seqscans might exacerbate this behavior by encouraging more cores to be touching the same buffers at the same time. I couldn't measure much difference between having it on vs. off in a pgbench test with all the clients counting the same table ... but maybe on other hardware the effect would show up. regards, tom lane