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 1tZ7O5-001JoQ-WE for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 11:53:15 +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 1tZ7O4-00HTiE-GZ for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 11:53:12 +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 1tZ7O4-00HTi5-1N for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 11:53:12 +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 1tZ7O1-000Bx0-16 for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 11:53:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1737201186; bh=1aukdrKjMII9c1AC3wbARMAKUdDOT9JKLD5Pu6lLHk4=; h=Message-ID:Date:User-Agent:Subject:From:To:Cc:References: In-Reply-To:From; b=Y4okStn62HfGmtvrjoBGy/78n3KPv0+kZFGSq12jNryY8GEh3FRjTjLxWAUyNDoL4 /5SbnbaYlKMW/GyG2iN5cuCGnxqYj3BQC+WQEqTnyPpZ6jjpIlaBIilyYoK7Qjp3Jw F4jFk8/vIz+WyYvYmQGHIHo5tcB4h03RCVC6C1gIfTYqBLjhUrOpg6zoLV2i5ACITH 6xs2Uv1U36hXqtEbFCwLqGqlH6qoQyjPUjJOYB4cF2PI2m3oD+vSxchHDY/VSHH1fm qKEqz5d+08pJ8lKgCfNXFq5R37v/SXY5x0x+0fnESQG0k4yyNWPD7NBR5deq7xrZj8 Cq0cU9+9IwyFg== 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 CA8D960ACA; Sat, 18 Jan 2025 14:53:05 +0300 (MSK) Message-ID: Date: Sat, 18 Jan 2025 14:53:05 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Increase NUM_XLOGINSERT_LOCKS From: Yura Sokolov 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 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected 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/18 08:11:00 #27058329 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 Since it seems Andres missed my request to send answer's copy, here it is: On 2025-01-16 18:55:47 +0300, Yura Sokolov wrote: > 16.01.2025 18:36, Andres Freund пишет: >> 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). Oops, I swapped the results around when reformatting the results, sorry! It's the opposite way. I.e. increasing the locks hurts. Here's that issue fixed and a few more NUM_XLOGINSERT_LOCKS. This is a slightly different disk (the other seems to have to go the way of the dodo), so the results aren't expected to be exactly the same. NUM_XLOGINSERT_LOCKS TPS 1 2583 2 2524 4 2711 8 2788 16 1938 32 1834 64 1865 128 1543 >> >> 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. I know that there's that thread, I just don't see how we can increase NUM_XLOGINSERT_LOCKS due to the regressions it can cause. >> 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. But LWLockWaitForVar is called from WaitXLogInsertionsToFinish, which just iterates over all locks. Greetings, Andres Freund