Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oFTXn-0000yy-PY for pgsql-hackers@arkaria.postgresql.org; Sun, 24 Jul 2022 04:48:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oFTXl-0001Uf-JV for pgsql-hackers@arkaria.postgresql.org; Sun, 24 Jul 2022 04:48:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oFTXl-0001UW-8T for pgsql-hackers@lists.postgresql.org; Sun, 24 Jul 2022 04:48:41 +0000 Received: from mail-oa1-x43.google.com ([2001:4860:4864:20::43]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oFTXd-0003o0-VD for pgsql-hackers@postgresql.org; Sun, 24 Jul 2022 04:48:40 +0000 Received: by mail-oa1-x43.google.com with SMTP id 586e51a60fabf-10d8880d055so10965706fac.8 for ; Sat, 23 Jul 2022 21:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/GMusUjsMfM1na0qReiwekEE9zJBeVfPA1wZs6qGXpc=; b=hhHw4ezAHjKfYftturWJ2Q6B853d6PtJAjcNASJIX+0NXpFgsmymjvJEWGnXPuszoe nn5NJHOJgSFjMIx9nOU8iDmUwbpg62LCuVoi4JrXoaksrXBU/KaajLZNS5Q7yDO27XGg hqEV2/NPPRoTeRahueU43DaTO114x0SmikzTWhJe38ErrjOkXtpT989maQaqyTG8zplU 8m9Q/RY6L832/mmbkf2dF802eQ/3DAgj/sgR4v3Us2x3rwgOPDVDIzN9C4aDAfo/UYPb vOh+ZaVdID7cYsX97vTAb6JAXpiq9igfM64/yvZdlt0phWtzWzPB8/QnI+U4qHeuR8jp ZaEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/GMusUjsMfM1na0qReiwekEE9zJBeVfPA1wZs6qGXpc=; b=Vtv2tIab2ca6n5FcQGGGE8giExnH1g+vd3hSzsTa4OxcESRgA14BqH5XJEwYltN0sw abQrdkCPmNYPcxTHs14eq+95BJv+vzWGmBwNBnxlwEZCkpnEwuWTenpLE9F555nK4oIS 7j+toHAWHc8+MJbBj+ZoFBYH8Ez7Ljbg6aqqg/W1ukgSzonwXVeDeHzokeDJv7Ugcq9G JFud2HWiQkqex7Loo4LOi/1dAHSCywiV58XlViS1KJUnHJXJ7QznvkdICLRu9Nfpgo1O 2zE0GbKM8FCuznI5IWw14flAEjfDvty/HOQfkgzeeLrtF5nx7+k04r0BqPCt4iXSOc98 v5QQ== X-Gm-Message-State: AJIora81ipF2/KQ0DgxyUNPtaZlpukKVyLsPPp84rELeUgmZn14iFU6N 1sotbeBG7oTSLAG7k5MJ0Ms= X-Google-Smtp-Source: AGRyM1vxGcvdydkjOmH7e40OJGEXfp7eOPl9xJ65JL+VY0vCljzNFD7LK/hnRyVLblyfD/wihpGHIg== X-Received: by 2002:a05:6870:e612:b0:109:d5fb:144c with SMTP id q18-20020a056870e61200b00109d5fb144cmr3348613oag.195.1658638111229; Sat, 23 Jul 2022 21:48:31 -0700 (PDT) Received: from smtpclient.apple ([206.190.130.164]) by smtp.gmail.com with ESMTPSA id f32-20020a056871072000b0010dc230fdd5sm2427550oap.22.2022.07.23.21.48.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Jul 2022 21:48:30 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: optimize lookups in snapshot [sub]xip arrays From: Zhang Mingli In-Reply-To: <20220713170950.GA3116318@nathanxps13> Date: Sun, 24 Jul 2022 12:48:25 +0800 Cc: pgsql-hackers@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <76ACEAF0-8050-41D5-B2F5-01164533BE99@gmail.com> References: <20220713170950.GA3116318@nathanxps13> To: Nathan Bossart X-Mailer: Apple Mail (2.3696.80.82.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, all >=20 > if (!snapshot->suboverflowed) > { > /* we have full data, so search subxip */ > - int32 j; > - > - for (j =3D 0; j < snapshot->subxcnt; j++) > - { > - if (TransactionIdEquals(xid, = snapshot->subxip[j])) > - return true; > - } > + if (XidInXip(xid, snapshot->subxip, = snapshot->subxcnt, > + &snapshot->subxiph)) > + return true; > =20 > /* not there, fall through to search xip[] */ > } If snaphost->suboverflowed is false then the subxcnt must be less than = PGPROC_MAX_CACHED_SUBXIDS which is 64 now. And we won=E2=80=99t use hash if the xcnt is less than = XIP_HASH_MIN_ELEMENTS which is 128 currently during discussion. So that, subxid=E2=80=99s hash table will never be used, right? Regards, Zhang Mingli > On Jul 14, 2022, at 01:09, Nathan Bossart = wrote: >=20 > Hi hackers, >=20 > A few years ago, there was a proposal to create hash tables for long > [sub]xip arrays in snapshots [0], but the thread seems to have fizzled = out. > I was curious whether this idea still showed measurable benefits, so I > revamped the patch and ran the same test as before [1]. Here are the > results for 60=E2=82=8Bsecond runs on an r5d.24xlarge with the data = directory on > the local NVMe storage: >=20 > writers HEAD patch diff > ---------------------------- > 16 659 664 +1% > 32 645 663 +3% > 64 659 692 +5% > 128 641 716 +12% > 256 619 610 -1% > 512 530 702 +32% > 768 469 582 +24% > 1000 367 577 +57% >=20 > As before, the hash table approach seems to provide a decent benefit = at > higher client counts, so I felt it was worth reviving the idea. >=20 > The attached patch has some key differences from the previous = proposal. > For example, the new patch uses simplehash instead of open-coding a = new > hash table. Also, I've bumped up the threshold for creating hash = tables to > 128 based on the results of my testing. The attached patch waits = until a > lookup of [sub]xip before generating the hash table, so we only need = to > allocate enough space for the current elements in the [sub]xip array, = and > we avoid allocating extra memory for workloads that do not need the = hash > tables. I'm slightly worried about increasing the number of memory > allocations in this code path, but the results above seemed = encouraging on > that front. >=20 > Thoughts? >=20 > [0] = https://postgr.es/m/35960b8af917e9268881cd8df3f88320%40postgrespro.ru > [1] = https://postgr.es/m/057a9a95-19d2-05f0-17e2-f46ff20e9b3e%402ndquadrant.com= >=20 > --=20 > Nathan Bossart > Amazon Web Services: https://aws.amazon.com >