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 1u4dvV-005Cvc-Hv for pgsql-performance@arkaria.postgresql.org; Tue, 15 Apr 2025 10:54:02 +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 1u4dvS-007yCp-GD for pgsql-performance@arkaria.postgresql.org; Tue, 15 Apr 2025 10:53:59 +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 1u4dvS-007yCU-5j for pgsql-performance@lists.postgresql.org; Tue, 15 Apr 2025 10:53:58 +0000 Received: from fhigh-b2-smtp.messagingengine.com ([202.12.124.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u4dvQ-000BAW-0f for pgsql-performance@lists.postgresql.org; Tue, 15 Apr 2025 10:53:57 +0000 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id EB8E0254028F; Tue, 15 Apr 2025 06:53:55 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 15 Apr 2025 06:53:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1744714435; x=1744800835; bh=mvF5o9b6aXc6F8vwQvuMVDZQOILODnPhDajCmT0QngU=; b= QKuFmfS6AhNK2LzVzj50tHGgmbw0YARt1udyk+OwJ59sp7RdoOGbGLR5CVvZnayq 7o1LcCgEMGF+RUZB70U67DIj7DBcoqAyf6P9YswfLVkmKWPhEgDY5A5b9cu43+Fp CfOzvZQSTaX7Obn8Hq7mtVVTeKwuw6WEpwVud559d3oiAHr5NpZVAYg6RL54hWeB ucYy5UDB6pfL25yd+UFnusONNe5IZYrbT5XLqviYbYHk0y+esT4SnXAR0oCHi+g9 JutbMbrYY21PTS2Xrh7RxtZJLd7+/E2enB3ehot8DJzG1xIbptUfC+OhQvwziiD+ GQhDoP0VhydCCmVSIbPuMA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1744714435; x= 1744800835; bh=mvF5o9b6aXc6F8vwQvuMVDZQOILODnPhDajCmT0QngU=; b=B qxKL+9In3JJKhkQjZHBCOa0EV1KaVzpVf4kzSJ1j6fMoKHOj21YgnFl/68l7ux7i wy6X/7jAkpkbpnPd/V+846SrUTJW3rE2sXxf+N5GyJEyVP+t3MIRscf7TSNnGJG1 GmUATEentWdfHYl0Qv2lBQR9j7SC9LPpE+PBkhsWJV7xzf+S+yaeyZKJ6OAcFBYN FVegQGbjGyGGngo/eOazDoqPSVMCSQjRRTdxyvS9gT9b4XoB3RdZTLjQrxwro/A3 OeYwdaMj/AD7L0b4HBXM7WwM8e1y8/oOkx1xnIrr/H+VUmEvQfvhNZawJ/b7ffIB BQdViUk8zz6ANmXxlfW5g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvvdeffeduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggugfgjsehtkefstddt tdejnecuhfhrohhmpeetnhgurhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrh griigvlhdruggvqeenucggtffrrghtthgvrhhnpedtleelvdfgjedvffeiueekfeeuleff hfegfffhgfffkeevueehieehhfeigffhvdenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvgdpnhgs pghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhgrmhgvsh hprghnghekkeeisehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqphgvrhhf ohhrmhgrnhgtvgeslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtoh ephidrshhokhholhhovhesphhoshhtghhrvghsphhrohdrrhhu X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Apr 2025 06:53:54 -0400 (EDT) Date: Tue, 15 Apr 2025 06:53:53 -0400 From: Andres Freund To: Yura Sokolov Cc: James Pang , pgsql-performance@lists.postgresql.org Subject: Re: many sessions wait on LWlock WALWrite suddenly Message-ID: References: <20ee7c44-bb93-4590-a984-b7fe4e4a9b14@postgrespro.ru> <4f101390-560c-4bd4-a547-e1c6ad90fe7f@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4f101390-560c-4bd4-a547-e1c6ad90fe7f@postgrespro.ru> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2025-04-15 13:44:09 +0300, Yura Sokolov wrote: > 15.04.2025 13:00, Andres Freund пишет: > > 1) Increasing NUM_XLOGINSERT_LOCKS allows more contention on insertpos_lck and > > spinlocks scale really badly under heavy contention > > > > I think we can redesign the mechanism so that there's an LSN ordered > > ringbuffer of in-progress insertions, with the reservation being a single > > 64bit atomic increment, without the need for a low limit like > > NUM_XLOGINSERT_LOCKS (the ring size needs to be limited, but I didn't see a > > disadvantage with using something like MaxConnections * 2). > > There is such attempt at [1]. And Zhiguo tells it really shows promising > results. > > No, I did it not with "ring-buffer", but rather with hash-table. But it is > still lock-free. I don't find that approach particularly promising - I do think we want this to be an ordered datastructure, not something as fundamentally unordered as a hashtable. > And then all stuck in WALWrite lock. That will often, but not always, mean that you're just hitting the IO throughput of the storage device. Right now it's too hard to tell the difference, hence the suggestion to make the wait events more informative. > > However, I think there's somewhat of an *inverse* relationship. To > > efficiently flush WAL in smaller increments, we need a cheap way of > > identifying the number of backends that need to wait up to a certain LSN. > > I believe, LWLockWaitForVar should be redone: > - currently it waits for variable to change (ie to be disctinct from > provided value). > - but I believe, it should wait for variable to be greater than provided value. I think we should simply get rid of the mechanism alltogether :) > This way: > - WALInsertLock waiter will not awake for every change of insertingAt > - process, which writes and fsync WAL, will be able to awake waiters on > every fsync, instead of end of whole write. > > It will reduce overhead of waiting WALInsertLock a lot, and will greately > reduce time spend on waiting WALWrite lock. > Btw, insertingAt have to be filled at the start of copying wal record to > wal buffers. Yes, we believe copying of small wal record is fast, but when > a lot of wal inserters does their job, we needlessly sleep on their > WALInsertLock although they are already in the future. Yes, that's a problem - but it also adds some overhead. I think we'll be better off going with the ringbuffer approach where insertions are naturally ordered and we can wait for precisely the insertions that we need to. Greetings, Andres Freund