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 1qdahc-0041y8-IG for psycopg@arkaria.postgresql.org; Tue, 05 Sep 2023 18:23:04 +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 1qdahb-00407G-FL for psycopg@arkaria.postgresql.org; Tue, 05 Sep 2023 18:23:03 +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 1qdaha-00406x-CL for psycopg@lists.postgresql.org; Tue, 05 Sep 2023 18:23:03 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qdahV-003FIp-6a for psycopg@postgresql.org; Tue, 05 Sep 2023 18:23:01 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 348485C0178; Tue, 5 Sep 2023 14:22:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 05 Sep 2023 14:22:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding: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=fm3; t= 1693938175; x=1694024575; bh=do4+SCc+hrUnMWwqW1Tapf8vAJwUkN0jDbk /F5dee/8=; b=tWKVrdzPumwzJS3B1IcsvwVs6pJNFGyY4WJSFtljwYlfEGAhzbI I8TtYIS93Gj9ceAi+lPpZ75k42RrENdYyiZCmgcsYGXlHFYX5ihZlebOPuWSiwkP mvB6uCYbhuXnT+A97/vhx45CRZmJOAfxt3esmyq33lWI99cCQAG0M2VaKT/ajFQA STjwkaqx8xHhYST9NNiCa0hdHuPFdjStp849jAkSrFAF+YekypyqKYg2SV/1d7Dp KjqvxytKgKro4C31ymGRO2hQ1UBkSnSG4xaqosb7SsFUv42l+yExZW97WQxJFWtB SrSCwDpP6zKPNW171lpQlcwyQPxDx/8miLQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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: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=1693938175; x= 1694024575; bh=do4+SCc+hrUnMWwqW1Tapf8vAJwUkN0jDbk/F5dee/8=; b=S q54WAv6p9TuhFgN115MU+dbCpz7DZwmtJJ4xCxS0EKgmtBuVAANTnaTziZOViN0y 0IObH9P00nXkFTRm7jftnoz1+5CCRDvMYqGudJtEsujuDI/XVAUpnVS8XpMgnorH t1oVvpwm+BPxagWkcySQWdezirOReLsNXiL3wfVjKVSsf/akKm4VVeq1zz/dWKLw BT2CaGtVuN/88Sh/1fIO/Nw23+leYcLbbFo8X9JQfa/l1aHWMpZobGw64GGUVTdg tiRAQ9thSxdGy+1Ga4EqLj8Ieima9gm12Mmydrc566byksWCtIenIv9nbJzFjoEY bcoP5UQiK7AceQKoteX6Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudehuddguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfhfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepuddtgeejjeffgfekfffggfegjefhieduudeifefg kedulefghfegvdehfeegvddvnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Sep 2023 14:22:54 -0400 (EDT) Message-ID: Date: Tue, 5 Sep 2023 11:22:52 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: CPU usage for queries, psycopg 2 vs 3 To: David Raymond , "psycopg@postgresql.org" References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/5/23 10:51 AM, David Raymond wrote: > I've noticed that CPU usage for queries seems to have drastically increased going from psycopg2 to psycopg3. > > In psycopg2 a connection would sit quietly while waiting for the results, using next to no CPU. > In psycopg it looks like the threads are using their core at full power, continuously checking for the result as fast as possible, and never sleeping or relaxing. > > See below for a simple example script. During the psycopg2 part while the 8 threads are waiting on results my processor usage sits at the normal idling 2-3%. But in the psycopg3 part, while the 8 threads are waiting on results my processor usage jumps up to 62-63% or so. > > Is there a setting or configuration I'm missing? Take a look at this: https://github.com/psycopg/psycopg/issues/448 It seems to be related. > This is on Windows, where I install with "pip install psycopg2-binary" and "pip install psycopg[binary]" > Current versions shown by pip list: > psycopg 3.1.10 (This gets installed even when telling it to install psycopg[binary]) > psycopg-binary 3.1.10 > psycopg2-binary 2.9.7 > > And their reported .__version__ > psycopg.__version__: 3.1.10 > psycopg2.__version__: 2.9.7 (dt dec pq3 ext lo64) > > I've got several scripts where I open up multiple connections to multiple servers and run a number of queries on them, where 98% of my machine's time should be just relaxing and waiting for the server to finish the next 1 to 15 minute long query. I don't need to continue the very microsecond the query completes. Is there anything I can do to bring CPU usage back down with psycopg (3) ? > > Thank you, > >