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 1qbTXG-00C9dg-9V for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Aug 2023 22:19:39 +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 1qbTXE-002WPg-8l for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Aug 2023 22:19:36 +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 1qbTXC-002WPF-Kj for pgsql-hackers@lists.postgresql.org; Wed, 30 Aug 2023 22:19:35 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qbTX8-001r99-Ge for pgsql-hackers@postgresql.org; Wed, 30 Aug 2023 22:19:33 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id E6547320051E; Wed, 30 Aug 2023 18:19:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 30 Aug 2023 18:19:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1693433967; x=1693520367; bh=rO adLncZHRJ5EbrG3/w9CIfhrbF0a1Oqr19nnXOPFuc=; b=F/66p5QmYVCfWsiCbv 0HViJiLhld9Qsrhzt+YbvAyAv0g0KZYvDAVqi7ztykA7ZQzN/0VaWJT/1bHH78IU JsMQX50Mmt7kU+O6e2LqeE2Sw8ZScBtvL/POMgAvwAb4d1Ruaw4IixYhuK8e1SoK 1j66lqRlm/KMaZsjeMwYS83qq2QSNalFLTH4eNPfHsKFZ+nRYk6++Lh95N9p1DGU q3S9CavYRBnDLyMEg6ac/NDTq0FQVwZ97hACKPAnphVeO2HTMPYqgZQYtubptOKl Ka0d7nUgdpwksF5gx56Yb2zYG0tI9OKmnIhcpDLmLYNB6Ws3kerVtEDTCumFGrvt 54Lw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1693433967; x=1693520367; bh=rOadLncZHRJ5E brG3/w9CIfhrbF0a1Oqr19nnXOPFuc=; b=mDezkmvJli6kx0wSn1FofCBszQCgY wGrLlL4BzqTJ3oeKK1m9aFFj3kK1bng9H3ek4Efkdu+1RZn1dgn+5Bg3IDDUGBEh OCHOXmO6O2oM4KNMRhBzT9GNeGhnU31TFFr/BT9cC3RnoLyLjcjIzNkSJ3SmU483 bcVnhCJD3pfWWeZ1BkjbBAdd5F0fVk6e4/Ok0b+KOGW1QKT7gngQy5H9SSsJIeEI jsPM8WXajfvCeUCU+9Jz9wLlK+KbJ+zixh1nzrAUvmpkPxQ9imTjZRq3ZFo48L3c rMhDMTMy33suv5D3KgF+YmaqYEqRsLjh2cmufFwBmIYiqzAcmla0O8d5g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudefledgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepvdfffeevhfetveffgeeiteefhfdtvdffjeevhfeuteegleduheetvedu ieettddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 30 Aug 2023 18:19:26 -0400 (EDT) Date: Wed, 30 Aug 2023 15:19:26 -0700 From: Andres Freund To: Thomas Munro Cc: pgsql-hackers Subject: Re: Query execution in Perl TAP tests needs work Message-ID: <20230830221926.g3cprzh4cgmxnmya@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2023-08-28 17:29:56 +1200, Thomas Munro wrote: > Every time we run a SQL query, we fork a new psql process and a new > cold backend process. It's not free on Unix, and quite a lot worse on > Windows, at around 70ms per query. Take amcheck/001_verify_heapam for > example. It runs 272 subtests firing off a stream of queries, and > completes in ~51s on Windows (!), and ~6-9s on the various Unixen, on > CI. Whoa. > Here are some timestamps I captured from CI by instrumenting various > Perl and C bits: > > 0.000s: IPC::Run starts > 0.023s: postmaster socket sees connection > 0.025s: postmaster has created child process > 0.033s: backend starts running main() > 0.039s: backend has reattached to shared memory > 0.043s: backend connection authorized message > 0.046s: backend has executed and logged query > 0.070s: IPC::Run returns > > I expected process creation to be slow on that OS, but it seems like > something happening at the end is even slower. CI shows Windows > consuming 4 CPUs at 100% for a full 10 minutes to run a test suite > that finishes in 2-3 minutes everywhere else with the same number of > CPUs. It finishes in that time on linux, even with sanitizers enabled... > As an experiment, I hacked up a not-good-enough-to-share experiment > where $node->safe_psql() would automatically cache a BackgroundPsql > object and reuse it, and the times for that test dropped ~51 -> ~9s on > Windows, and ~7 -> ~2s on the Unixen. But even that seems non-ideal > (well it's certainly non-ideal the way I hacked it up anyway...). I > suppose there are quite a few ways we could do better: That's a really impressive win. Even if we "just" converted some of the safe_psql() cases and converted poll_query_until() to this, we'd win a lot. > 1. Don't fork anything at all: open (and cache) a connection directly > from Perl. One advantage of that is that the socket is entirely controlled by perl, so waiting for IO should be easy... > 2b. Maybe give psql or a new libpq-wrapper a new low level stdio/pipe > protocol that is more fun to talk to from Perl/machines? That does also seem promising - a good chunk of the complexity around some of the IPC::Run uses is that we end up parsing psql input/output... Greetings, Andres Freund