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 1sqCZl-007nHa-7a for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Sep 2024 14:19:38 +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 1sqCZk-00FmZ8-5y for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Sep 2024 14:19:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sqCZj-00FmYt-J9 for pgsql-hackers@lists.postgresql.org; Mon, 16 Sep 2024 14:19:35 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sqCZf-001UcZ-3N for pgsql-hackers@lists.postgresql.org; Mon, 16 Sep 2024 14:19:34 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id A7FC7FF807; Mon, 16 Sep 2024 14:19:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1726496371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jSMZF0Z1mnFJKuWu2TVb9aFeUeLYEHdK/mDEK4O01Pk=; b=I+7cQgxM6HwF1y+8UBsbdHORfqGkloBKuI+Vr6blTuMC9sXrVZ/WEjB/69yNcSQkuoqlaS KsGwM9Em8abgQXU/dh8SdJUUDN3jK97pyFN64AxdMXQmF30N9xzLDahnO7HUqjiYLePd6x y1+PP54vp2qWOH8weTENbuQWsF2Enpodk4Fzi8C98r4VjrP3Jn3S92l8zdF9ek3+2HvgF8 Ww2s0KN487dnbQ5SUq4lObt+Q4/nL+a8KHyWuL33fYd/cNqERT+Teos478UUrLlZJC5jtA ky4ATVymaJ+cs/8sMilsQPUaRGV+hFR7zCUeReOEaxPac5Wih6IzrtKYWac3MA== Message-ID: <0f27b64b-5bf3-4140-98b7-635e312e1796@vondra.me> Date: Mon, 16 Sep 2024 16:19:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: scalability bottlenecks with (many) partitions (and more) To: Jakub Wartak Cc: Robert Haas , PostgreSQL Hackers , Andres Freund 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> Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/16/24 15:11, Jakub Wartak wrote: > On Fri, Sep 13, 2024 at 1:45 AM 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=1000 > x86_64 (830kB -> ~5.1MB), and indeed: > > # without patch: > postgres@hive:~$ /usr/pgsql18/bin/postgres -D /tmp/pg18 -C > shared_memory_size_in_huge_pages > 177 > > # with patch: > postgres@hive:~$ /usr/pgsql18/bin/postgres -D /tmp/pg18 -C > shared_memory_size_in_huge_pages > 178 > > So playing Devil's advocate , the worst situation that could possibly > hurt (?) could be: > * memory size of PGPROC working set >> L2_cache (thus very high > max_connections), > * insane number of working sessions on CPU (sessions >> VCPU) - sadly > happens to some, > * those sessions wouldn't have to be competing for the same Oids - > just fetching this new big fpLockBits[] structure - so probing a lot > for lots of Oids, but *NOT* having to use futex() syscall [so not that > syscall price] > * no huge pages (to cause dTLB misses) > > 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. >>> I did look at docs if anything needs updating, but I don't think so. The > SGML docs only talk about fast-path locking at fairly high level, not > about how many we have etc. > > 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. regards -- Tomas Vondra