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 1tYhih-00DH1T-WE for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jan 2025 08:28:49 +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 1tYhig-00BJAF-6f for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jan 2025 08:28:46 +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 1tYhif-00BJ9z-OY for pgsql-hackers@lists.postgresql.org; Fri, 17 Jan 2025 08:28:46 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tYhie-000qup-0L for pgsql-hackers@lists.postgresql.org; Fri, 17 Jan 2025 08:28:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1737102520; bh=QnYEK472LHd8Uq/Fy9w+HULCqizB6zoOiI5MjB6u65I=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=HLpTGAcNh749oWwNzuCZ5mobZNqipsG63+soiipO87Lea/WLfdPryuUkCtcBNuIc+ AlLgg2L4zGTeoliEBp2I1dwIsTax2j4jlnPXP54Rfa7qULZU/baIu+tpLm0j+uGSlJ v+STgpRYCxxHu33HGPCIT9Q4tze4AxhKgKHpv+H5oNlc5dqbG9gePR2lYTdNVNVMKk JK3G0IBmEuD8xz2adu1joyrvPDq7252DPVB2AU0LtX8871HwyP27R+hzWF7ISCeuar I1LzxFe2xDMOSf/QApZSb+ifn+IjcjXt+57EhyMhbKIFoag5Sh2kxx65fdyGy8qJC5 f2Gnbpae/Us8A== Received: from [172.30.50.226] (unknown [172.30.50.226]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: y.sokolov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 9A02060B5C; Fri, 17 Jan 2025 11:28:39 +0300 (MSK) Message-ID: Date: Fri, 17 Jan 2025 11:28:38 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Increase NUM_XLOGINSERT_LOCKS To: Andres Freund Cc: "pgsql-hackers@lists.postgresql.org" , "Zhou, Zhiguo" , wenhui qiu References: <3b11fdc2-9793-403d-b3d4-67ff9a00d447@postgrespro.ru> <6ykez6chr5wfiveuv2iby236mb7ab6fqwpxghppdi5ugb4kdyt@lkrn4maox2wj> Content-Language: en-US From: Yura Sokolov In-Reply-To: <6ykez6chr5wfiveuv2iby236mb7ab6fqwpxghppdi5ugb4kdyt@lkrn4maox2wj> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-KSMG-AntiPhishing: NotDetected, bases: 2025/01/17 07:32:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/01/17 05:00:00 #27047805 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Excuse me, Andres, I've found I've pressed wrong button when I sent this letter first time, and it was sent only to you. So I'm sending the copy now. Please, reply to this message with copy of your answer. Your answer is really valuable to be published in the list. 16.01.2025 18:36, Andres Freund wrote: > Hi, > > On 2025-01-16 16:52:46 +0300, Yura Sokolov wrote: >> Good day, hackers. >> >> Zhiguo Zhow proposed to transform xlog reservation to lock-free algorighm to >> increment NUM_XLOGINSERT_LOCKS on very huge (480vCPU) servers. [1] >> >> While I believe lock-free reservation make sense on huge server, it is hard >> to measure on small servers and personal computers/notebooks. >> >> But increase of NUM_XLOGINSERT_LOCKS have measurable performance gain (using >> synthetic test) even on my working notebook: >> >> Ryzen-5825U (8 cores, 16 threads) limited to 2GHz , Ubuntu 24.04 > > I've experimented with this in the past. > > > Unfortunately increasing it substantially can make the contention on the > spinlock *substantially* worse. > > c=80 && psql -c checkpoint -c 'select pg_switch_wal()' && pgbench -n -M prepared -c$c -j$c -f <(echo "SELECT pg_logical_emit_message(true, 'test', repeat('0', 1024*1024));";) -P1 -T15 > > On a 2x Xeon Gold 5215, with max_wal_size = 150GB and the workload ran a few > times to ensure WAL is already allocated. > > With > NUM_XLOGINSERT_LOCKS = 8: 1459 tps > NUM_XLOGINSERT_LOCKS = 80: 2163 tps So, even in your test you have +50% gain from increasing NUM_XLOGINSERT_LOCKS. (And that is why I'm keen on smaller increase, like upto 64, not 128). > > The main reason is that the increase in insert locks puts a lot more pressure > on the spinlock. That it addressed by Zhiguo Zhow and me in other thread [1]. But increasing NUM_XLOGINSERT_LOCKS gives benefits right now (at least on smaller installations), and "lock-free reservation" should be measured against it. > Secondarily it's also that we spend more time iterating > through the insert locks when waiting, and that that causes a lot of cacheline > pingpong. Waiting is done with LWLockWaitForVar, and there is no wait if `insertingAt` is in future. It looks very efficient in master branch code. > On much larger machines this gets considerably worse. IIRC I saw something > like an 8x regression on a large machine in the past, but I couldn't find the > actual numbers anymore, so I wouldn't want to bet on it. I believe, it should be remeasured. [1] https://postgr.es/m/flat/PH7PR11MB5796659F654F9BE983F3AD97EF142%40PH7PR11MB5796.namprd11.prod.outlook.com ------ regards Yura