Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqANs-00058c-8F for pgsql-general@arkaria.postgresql.org; Wed, 24 Jul 2019 06:04:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqANr-0006tI-1C for pgsql-general@arkaria.postgresql.org; Wed, 24 Jul 2019 06:04:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqAK2-0005Kf-Ib for pgsql-general@lists.postgresql.org; Wed, 24 Jul 2019 06:00:18 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqAJz-0005uy-2j for pgsql-general@postgresql.org; Wed, 24 Jul 2019 06:00:18 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 768CB2213D; Wed, 24 Jul 2019 02:00:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 24 Jul 2019 02:00:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=Tt3yWIbox6wCWO060Yq0hZqF8pH hUz1F614CMb7alcA=; b=dv8ULCzzG0MMoeKWM6fEPUJdptAKfjkNE6aTs3lM6jb KCKgaioxe1pbvSOAeBi9E1LpZe5f+WoU0tRCK25yYFxXLL/8qL1+tXalnu6yzQM+ GoxSQ0syMXFRx7HAOsub12mwIQPTwJhNKUIhJT6LqXvQtGN2Mm1scJHhxW8uY0ec 4rrMEXd2rQrLjB5cJlejItFxGZwXHwi3hHI+BfrD7DZOBfc4udldtD8y0873a1DP St1pfLOq0FBYKgXOwHHkid2s6tVKyyIbykGIL8auqIFfISdlz1QKXZkz77mfAPRp 6XIwQ9hIh3JX3MdG+P8nA1r2G80DEoe7C3wckJEUMog== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Tt3yWI box6wCWO060Yq0hZqF8pHhUz1F614CMb7alcA=; b=hUsQtISf1tgLlDE1dtOZCk WUBVpJeYpnaAHFeb5TBKxRokPxDYFhLUcZ1FxczZK7jSdUv/pV4wDUY6KyvnDCnU yL/PKd2JuQ16VvQrRgLT1LE1IkV2fpu46WTjMW+ttu1BmE90pNDfwhmc9MC0mPHD Kodt0ISG3uoHbuaNi+95C6srijVvC6L6g/+HHNyYuyOhSXpPaOAK4fQOqS/slj4E WLyxjk9fX4JKxhBRxhJqA0SpX8W5IwCAN/uKr4E7SyaUdP669DuUF6Z744D809oq hi4qrfiXA0GYX90WPZvfKWNrwzr1nDKQAtDHXJIUmOYpzac3vgibtjmT/7SxPzUQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrjeelgddutdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucffohhmrg hinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeeijedrudeitddrvddukedrvdef jeenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdrug gvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-218-237.hsd1.ca.comcast.net [67.160.218.237]) by mail.messagingengine.com (Postfix) with ESMTPA id A72AD8006C; Wed, 24 Jul 2019 02:00:10 -0400 (EDT) Date: Tue, 23 Jul 2019 12:53:39 -0700 From: Andres Freund To: Alexander Pyhalov Cc: "pgsql-general@postgresql.org" Subject: Re: LWLock optimization Message-ID: <20190723195339.hgnldeep7kvihfc4@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2019-07-23 16:28:52 +0000, Alexander Pyhalov wrote: > I was asked to bring up this topic on maling lists after asking question on IRC. > > The issue is the following. > On one of our servers (10.5), I see a lot of queries with wait_event_type='LWLock', wait_event='lock_manager' Could you qualify this a bit more? What does "a lot" mean, in comparison to the total number of queries/session? > This is a stat gathering/analyzing application with tables which have > > 100 partitions. Hm, what kind of partitioning scheme is this? The "new"-ish partitioning support isn't yet always that good to only perform the minimal amount of metadata lookups (which in turn require locks). Especially in 10. Are you using prepared statements? > The queries itself are mostly simple (select by pkey, update by primary key and so on). > > select count(*) from pg_locks shows about 40K records (all granted) and > > select count(*) from (select distinct locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid from pg_locks) > > is varying from about 1K to 25K (I haven't stored this value in monitoring system, just observed manually). I think to know what exactly is going on, we'd need a cpu profile, and then perhaps a followup profile for also getting the callsites for lock waits. Could you take a perf profile? https://wiki.postgresql.org/wiki/Profiling_with_perf > Currently I was adviced to increase LOG2_NUM_LOCK_PARTITIONS at > compile time. If it bothers us enough, we would likely do it, but I > have a question, if this (or NUM_LOCK_PARTITIONS) value should be > increased by default or set tunable? I'm not quite sure what you're asking precisely here. Are you wondering whether postgres should increase the default value for LOG2_NUM_LOCK_PARTITIONS should be increased? And whether it should be runtime configurable? I'm fairly sure we don't want to make it runtime configurable, that'd add overhead to some pretty central code. Increasing the default would need a lot of benchmarks, to prove it doesn't cause regressions in other common scenarios. Greetings, Andres Freund