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 1jppZi-0001kv-Eo for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 08:55:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jppZh-0008Lz-7W for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 08:55:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jppZg-0008Lr-W1 for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2020 08:55:36 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jppZc-0007bd-Ax for pgsql-hackers@postgresql.org; Mon, 29 Jun 2020 08:55:35 +0000 Received: from hnk.local (p2604028-ipngn12401funabasi.chiba.ocn.ne.jp [180.1.110.28]) by oss.nttdata.com (Postfix) with ESMTPSA id 83BDA602FB; Mon, 29 Jun 2020 17:55:28 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: track_planning causing performance regression To: Julien Rouhaud , "Tharakan, Robins" Cc: "pgsql-hackers@postgresql.org" References: <2895b53b033c47ccb22972b589050dd9@EX13D05UWC001.ant.amazon.com> From: Fujii Masao Message-ID: Date: Mon, 29 Jun 2020 17:55:28 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/06/29 16:05, Julien Rouhaud wrote: > Hi, > > On Mon, Jun 29, 2020 at 7:49 AM Tharakan, Robins wrote: >> >> During fully-cached SELECT-only test using pgbench, Postgres v13Beta1 shows Thanks for the benchmark! >> ~45% performance drop [2] at high DB connection counts (when compared with v12.3) That's bad :( >> >> Disabling pg_stat_statements.track_planning (which is 'On' by default) >> brings the TPS numbers up to v12.3 levels. >> >> The inflection point (in this test-case) is 128 Connections, beyond which the >> TPS numbers are consistently low. Looking at the mailing list [1], this issue >> didn't surface earlier possibly since the regression is trivial at low connection counts. >> >> It would be great if this could be optimized further, or track_planning >> disabled (by default) so as to not trip users upgrading from v12 with pg_stat_statement >> enabled (but otherwise not particularly interested in track_planning). Your benchmark result seems to suggest that the cause of the problem is the contention of per-query spinlock in pgss_store(). Right? This lock contention is likely to happen when multiple sessions run the same queries. One idea to reduce that lock contention is to separate per-query spinlock into two; one is for planning, and the other is for execution. pgss_store() determines which lock to use based on the given "kind" argument. To make this idea work, also every pgss counters like shared_blks_hit need to be separated into two, i.e., for planning and execution. >> These are some details around the above test: >> >> pgbench: scale - 100 / threads - 16 >> test-duration - 30s each >> server - 96 vCPUs / 768GB - r5.24xl (AWS EC2 instance) >> client - 72 vCPUs / 144GB - c5.18xl (AWS EC2 instance) (co-located with the DB server - Same AZ) >> v12 - REL_12_STABLE (v12.3) >> v13Beta1 - REL_13_STABLE (v13Beta1) >> max_connections = 10000 >> shared_preload_libraries = 'pg_stat_statements' >> shared_buffers 128MB > > I can't reproduce this on my laptop, but I can certainly believe that > running the same 3 queries using more connections than available cores > will lead to extra overhead. > > I disagree with the conclusion though. It seems to me that if you > really have this workload that consists in these few queries and want > to get better performance, you'll anyway use a connection pooler > and/or use prepared statements, which will make this overhead > disappear entirely, and will also yield an even bigger performance > improvement. A quick test using pgbench -M prepared, with > track_planning enabled, with still way too many connections already > shows a 25% improvement over the -M simple without track_planning. I understand your point. But IMO the default setting basically should be safer value, i.e., off at least until the problem disappears. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION