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 1pc8Xc-0007Kt-1T for pgsql-general@arkaria.postgresql.org; Tue, 14 Mar 2023 17:34:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pc8Xa-0000qs-LW for pgsql-general@arkaria.postgresql.org; Tue, 14 Mar 2023 17:34:26 +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 1pc8Xa-0000qj-An for pgsql-general@lists.postgresql.org; Tue, 14 Mar 2023 17:34:26 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pc8XX-0006x6-HI for pgsql-general@lists.postgresql.org; Tue, 14 Mar 2023 17:34:25 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 7C1815C095B; Tue, 14 Mar 2023 13:34:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 14 Mar 2023 13:34:22 -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=fm1; t= 1678815262; x=1678901662; bh=jckxTeCr49opHOHrbhkXaAM5Du2kHajTzEV 5nn31xww=; b=c2Wy1CFy3+dWkEmGlkFJSf76V+I6BY+IvdUlTneBjHPnMoMWQ5Q Vs1gODNvU+5H929U1Kh2o5oBOWzoRKuyXZbGI95rbwIyRGOBOpqxxXtu2iwyWnew BOIjrVorsccmpjLmaaW1PEW8zXmVrZauGJd1J/UX/D0lNW1GMHt9Xm202fBk4mNG mPQwLtW0Ubb3qopRnBuGTOKV9J/EuS5gyhMoPjcIp/QNmPEiGAmRs0KOHvLLvU/0 B9NPH85dU+LKXzcGDz58EJcmD2KzDBWzefld0G5SuUfWHnAgJTJLudOqrlVg9lJ5 8FJLMMLBMsSSVv+b1oSYL3d6WhF95LtY9PA== 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=fm2; t=1678815262; x= 1678901662; bh=jckxTeCr49opHOHrbhkXaAM5Du2kHajTzEV5nn31xww=; b=m MuuRG8LP25FqqDPOXP7jZMRr0/YiFUlvH+xM+kB5a7TOgQbj3+WR/sv9wacaoSUY Bojk+/a8x0VR9ethq0iUTYgGHqT0NyzBZx9/16wjdLdNvLoknQZ3pyuXP1X/J+XX 7zMjeVJ+qQJbJDxICWoH7F9GIdkNLus5syhYvMXfU/BJYaiBA9RHipV0mvb0u3ok hLmu7qYbW4T1I7fpqtDOKvUuXJqMBa0preFy2tIFLikzfdVeMdc2CNb+RvuXBvrZ Wrgq2ELsGkcRsHgTvzqqMBy/VD1QUvSszTI9OX8oSMcDv1JhgfNyuefc2MIvTpJM QcoUJL0e61Uj7lKW+ygtA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddviedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepuddufeejteevffehgfduhedthfdvteekieeuheef veevudetkeelueehgeduhefhnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrgh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughr ihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Mar 2023 13:34:21 -0400 (EDT) Subject: Re: Issues Scaling Postgres Concurrency To: Harrison Borges , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <8a233037-4a87-a67d-af1c-0c0d5fdc31d5@aklaver.com> Date: Tue, 14 Mar 2023 10:34:20 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/13/23 9:24 AM, Harrison Borges wrote: > Hello everyone. > > I’m running into severe performance problems with Postgres as I increase > the number of concurrent requests against my backend. I’ve identified > that the bottleneck is Postgres, and to simplify the test case, I > created an endpoint that only does a count query on a table with ~500k > rows. At 5 concurrent users, the response time was 33ms, at 10 users it > was 60ms, and at 20 users it was 120ms. > > As the number of concurrent users increases, the response time for the > count query also increases significantly, indicating that Postgres may > not be scaling well to handle the increasing load. > > This manifests in essentially a server meltdown on production. As the > concurrent requests stack up, our server is stuck waiting for more and > more queries. Eventually requests begin timing out as they start taking > over 30 seconds to respond. > > Am I doing something obviously wrong? Does this sound like normal > behavior? I'm not very experienced at DB ops so I'm not 100% sure what > to expect here, but I have worked as a Software Engineer for over 10 > years and I've not encountered problems like this before. 1) https://wiki.postgresql.org/wiki/Slow_Counting 2) Are you using connection pooling? > > I would appreciate any insights or advice on how to optimize Postgres > for high concurrency scenarios. Thank you in advance for your help! -- Adrian Klaver adrian.klaver@aklaver.com