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 1ssfu5-00A2HA-W8 for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Sep 2024 10:02:50 +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 1ssfu4-005dli-QC for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Sep 2024 10:02:48 +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 1ssfu4-005dla-6j for pgsql-hackers@lists.postgresql.org; Mon, 23 Sep 2024 10:02:48 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ssftw-000cu9-86 for pgsql-hackers@lists.postgresql.org; Mon, 23 Sep 2024 10:02:46 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-5356bb5522bso4855815e87.1 for ; Mon, 23 Sep 2024 03:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1727085758; x=1727690558; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IKVlqkaNB5Q/w98Vat58ffLi6+pyEPxuxNGwp0QP4G8=; b=T3ECYGpcTEJ4gpVhw7VDpBDK43hfIl4XgcBaAu8jAcD8HsxiRkGncprd2o4iMbDsYu H+YsuI/xlvygGnf9pinLlCEwa2OQUxXl30M2xpAwba/ROjIEOIpnABGkh30Dx8pfCJFG Luapom6bTwKH0GXTjFLlIHHj8WkL5zfdAUzSq95yDx/Y6cL2TdLlkm/kY1Ee5V4VsZHp ht59g6d+5MEI9ZS5jYgWf4iTFC6+JALCcLLS4XHnXyxZFB9eE4RcnGhLVOMCM5R5Ux9n 2fEyYNlcUcOen7chd1uGsBYddmM13L3f0l+N2sL8JkHiHlRy3nJrz7aDWRhtauwfTQd/ blcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727085758; x=1727690558; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IKVlqkaNB5Q/w98Vat58ffLi6+pyEPxuxNGwp0QP4G8=; b=KSuIJFp6g5+f/Ra4xqbvL5B5vX75Hs+uZbGYXgH+6zyz6Qje0dfiXXHgidEJ0ZuS5u ORHcQW1Vy7jdHhQQ3TLwLhoMq43Nkos8EsZnqSOO9Wzryd+lWElcpNyGAMqhN5WmL9XM fHfbvhtUQN7quMyOjThDBlEyPeii2vU1m9/o4mWm2SF1EkrwNUh5UaXEYr9z9L5Ygaci a8zIAZyjrTo8UiSAwxjJC920SugB57YU4wotBlo4Z3yfmkHyqLQifqp6ma8p6wSRtufl Hm8Cj6DxsfC0bFvAfG9m+R2mbdCPQufh4FtoxK1FVRoqPuOh8MdYRu45iV/ylTfDf+LY MLfw== X-Forwarded-Encrypted: i=1; AJvYcCWe8p3JghUhrVzottFi+5Yk8GEMuQ79ZHg1WlA525iye8xnJSx3PuuYPU8WMQcqH4aWGUQUZP+QMF5UILMl@lists.postgresql.org X-Gm-Message-State: AOJu0YzK2XaP3RODWsGz8IpiN61FHAhSKhpr2r9sSbSJWHgpVf8X3/EC FWPXII1qoZnQy1V7DEk1+U43+fz3TyQU1NwnJydFX6Q9sm0OjYSSgXKzaW5/AC7D9AW+VW/i3xo mzuUOcXOClw8MiFWItrpeLhJ0gOAB3P2sHXEO X-Google-Smtp-Source: AGHT+IFnehE3oNQjnwTgQr07AgxneA+rFJwR9DtW1eq3K1X1yrzoaNiVMWe4XUfIf8wYFgo+b9lGje68lGA6f6qNVag= X-Received: by 2002:ac2:4c47:0:b0:536:9f02:17cc with SMTP id 2adb3069b0e04-536ac2f51admr4974092e87.31.1727085757719; Mon, 23 Sep 2024 03:02:37 -0700 (PDT) MIME-Version: 1.0 References: <510b887e-c0ce-4a0c-a17a-2c6abb8d9a5c@enterprisedb.com> <9266c8df-0df7-4605-ba5a-b204c5e52586@enterprisedb.com> <52afd566-d110-43ea-ae72-69349d4414f6@vondra.me> <52f026c4-6c4e-4de2-bd78-609091d7c772@vondra.me> <14cd8763-c905-4705-99c5-cbcc5db06f50@vondra.me> <0775ba8a-920c-4d37-b202-989a90b6ee4c@vondra.me> <0f27b64b-5bf3-4140-98b7-635e312e1796@vondra.me> In-Reply-To: <0f27b64b-5bf3-4140-98b7-635e312e1796@vondra.me> From: Jakub Wartak Date: Mon, 23 Sep 2024 12:02:24 +0200 Message-ID: Subject: Re: scalability bottlenecks with (many) partitions (and more) To: Tomas Vondra Cc: Robert Haas , PostgreSQL Hackers , Andres Freund Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Sep 16, 2024 at 4:19=E2=80=AFPM Tomas Vondra wrot= e: > On 9/16/24 15:11, Jakub Wartak wrote: > > On Fri, Sep 13, 2024 at 1:45=E2=80=AFAM Tomas Vondra = wrote: > > > >> [..] > > > >> Anyway, at this point I'm quite happy with this improvement. I didn't > >> have any clear plan when to commit this, but I'm considering doing so > >> sometime next week, unless someone objects or asks for some additional > >> benchmarks etc. > > > > Thank you very much for working on this :) > > > > The only fact that comes to my mind is that we could blow up L2 > > caches. Fun fact, so if we are growing PGPROC by 6.3x, that's going to > > be like one or two 2MB huge pages more @ common max_connections=3D1000 > > x86_64 (830kB -> ~5.1MB), and indeed: [..] > > then maybe(?) one could observe further degradation of dTLB misses in > > the perf-stat counter under some microbenchmark, but measuring that > > requires isolated and physical hardware. Maybe that would be actually > > noise due to overhead of context-switches itself. Just trying to think > > out loud, what big PGPROC could cause here. But this is already an > > unhealthy and non-steady state of the system, so IMHO we are good, > > unless someone comes up with a better (more evil) idea. > > > > I've been thinking about such cases too, but I don't think it can really > happen in practice, because: > > - How likely is it that the sessions will need a lot of OIDs, but not > the same ones? Also, why would it matter that the OIDs are not the same, > I don't think it matters unless one of the sessions needs an exclusive > lock, at which point the optimization doesn't really matter. > > - If having more fast-path slots means it doesn't fit into L2 cache, > would we fit into L2 without it? I don't think so - if there really are > that many locks, we'd have to add those into the shared lock table, and > there's a lot of extra stuff to keep in memory (relcaches, ...). > > This is pretty much one of the cases I focused on in my benchmarking, > and I'm yet to see any regression. Sorry for answering this so late. Just for context here: I was imagining a scenario with high max_connections about e.g. schema-based multi-tenancy and no partitioning (so all would be fine without this $thread/commit ; so under 16 (fast)locks would be taken). The OIDs need to be different to avoid contention: so that futex() does not end up really in syscall (just user-space part). My theory was that a much smaller PGPROC should be doing much less (data) cache-line fetches than with-the-patch. That hash() % prime , hits various parts of a larger array - so without patch should be quicker as it wouldn't be randomly hitting some larger array[], but it might be noise as you state. It was a theoretical attempt at crafting the worst possible conditions for the patch, so feel free to disregard as it already assumes some anti-pattern (big & all active max_connections). > > Well the only thing I could think of was to add to the > > doc/src/sgml/config.sgml / "max_locks_per_transaction" GUC, that "it > > is also used as advisory for the number of groups used in > > lockmanager's fast-path implementation" (that is, without going into > > further discussion, as even pg_locks discussion > > doc/src/sgml/system-views.sgml simply uses that term). > > > > Thanks, I'll consider mentioning this in max_locks_per_transaction. > Also, I think there's a place calculating the amount of per-connection > memory, so maybe that needs to be updated too. > I couldn't find it in current versions, but maybe that's helpful/reaffirmin= g: - up to 9.2. there were exact formulas used, see "(1800 + 270 * max_locks_per_transaction) * max_connections" [1] , that's a long time gone now. - if anything then Andres might want to improve a little his blog entry: [1] (my take is that is seems to be the most accurate and authoritative technical information that we have online) -J. [1] - https://www.postgresql.org/docs/9.2/kernel-resources.html [2] - https://blog.anarazel.de/2020/10/07/measuring-the-memory-overhead-of-= a-postgres-connection/