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 1tdrxW-00ADP7-9B for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Jan 2025 14:25:26 +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 1tdrxU-000nk2-SF for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Jan 2025 14:25:24 +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 1tdrxU-000njs-HH for pgsql-hackers@lists.postgresql.org; Fri, 31 Jan 2025 14:25:24 +0000 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tdrxS-002Tcg-0K for pgsql-hackers@postgresql.org; Fri, 31 Jan 2025 14:25:23 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id 4E1B625400CF; Fri, 31 Jan 2025 09:25:21 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Fri, 31 Jan 2025 09:25:21 -0500 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 :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1738333521; x=1738419921; bh=4 qREjQCaX7mb3YKVNKXfcNlthm+rE8HrzGtNFcLojOo=; b=VLJXY1pWK5smgePBu mNXXYmsp8VHL4/KJUScKYUaH10ZKwH8vXrykl92vT0CMRRP7fT6i0c9c5FLsw719 EmEnaA948gz/InrmoHCv2OsgYlmMCtQF0USehPnJBOJ4/D+r/LKumEiEtinwqrGO EwYQ+ZeD9vW0lxoUayW1JVhkPlCV4cGrvvJisgzYwP7uvggdVuD5Em2w1HFeTfae QL0AI7PPm8GbIzXQPiSIUWPsycmBdDxYBtRrg01lF2lvaD2F1Aben7ctvQAJEYKp KBnB53+KN2Axpv+7KQ1rVh6y2Z5F+KRgrOTNT3dl8izf+2MLX7iWqiry+GOFpvUr F5JWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeltddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeen ucfhrhhomheplmhlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhh drnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepleeigfekheetueelieehveej geeijeeivefftdffhefgheefteekkeekgefhgfevnecuffhomhgrihhnpegsuhhrthhlvg gsuhhrthhlvgdrnhgvthdpghhithhhuhgsrdgtohhmpdgvnhhtvghrphhrihhsvggusgdr tghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsggprhgtphhtthhopedv pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegumhhithhrhidrkhhothgvrhhovh esghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhs thhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 31 Jan 2025 09:25:20 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1738333518; bh=Q36FfjaYiqiiXmwGJvS8ma+H3tuJ+kw8d1f8zx9InFI=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=S97HPHlh1F3WHJXKLJH+i0/BZj9EZW8ZChPJevucYz8vwKHrcHRS629KxFW6cyafU RhTFBbdF9swtwnwSYMbJX5xSHRNki98OqbM2H43H2cDR16eHqsruveWM5fHeYuEuDs l5nHUg4UNXFjd/36+Bo0PuiaKXq5/XM/VIgD1c+5301m4xVnAbMySsBzLQIzGMbhGI WC0kgeksHVn4aD0HrREIjzPX9TUMh77usWFK5x1rjTV/MIMoyZgGUszFIY2WyOCGg5 Ghq0hRPKrfUH9iXBQG+xAThZ2t7luzQRqgYxOYJa7dGjL9sr5Ly75DIZCYHTjT3bAA l12FlEcQcSxFA== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 46BDA8C; Fri, 31 Jan 2025 15:25:18 +0100 (CET) Date: Fri, 31 Jan 2025 15:25:18 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Dmitry Koterov Cc: "pgsql-hackers@postgresql.org" Subject: Re: hash_search_with_hash_value is high in "perf top" on a replica Message-ID: <202501311425.5cp3kqeeribm@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-Jan-31, Dmitry Koterov wrote: > PG "startup recovering" eats up a lot of CPU (like 65 %user and 30 %sys), > which is a little surprising (what is it doing with all those CPU cycles? > it looked like WAL replay should be more IO bound than CPU bound?). > > Running "perf top -p ", it shows this: > > Samples: 1M of event 'cycles:P', 4000 Hz, Event count (approx.): > 18178814660 lost: 0/0 drop: 0/0 > Overhead Shared Object Symbol > 16.63% postgres [.] hash_search_with_hash_value Yeah, I noticed that this function was showing high in some profiles a couple of days ago as well. Looking now at hashfn.c (hash_bytes_uint32 there is the function involved in the buffer mapping hash table), the comments state that we're updated to Bob Jenkins code from 2006, but there's a version in his website that (if I read correctly) is twice as fast as what we're using now: http://burtleburtle.net/bob/hash/spooky.html Apparently this code in our repo is mostly unchanged since commit 1f559b7d3aa4, in 2007. He mentions that on Intel chips, Google's CityHash is faster; but they in turn claim that the difference is small on Intel chips and that Jenkins' hash is better on AMD chips. https://github.com/google/cityhash Anyway if you wanted to try your luck at improving things, here's your chance. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/