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 1kNije-0000fc-Af for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 20:29:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kNijd-0005HJ-4l for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 20:29:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNijb-0005HA-70 for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 20:29:56 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNijU-0005na-3I for pgsql-general@postgresql.org; Wed, 30 Sep 2020 20:29:54 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id E53BBF51; Wed, 30 Sep 2020 16:29:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 30 Sep 2020 16:29:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=H iO39ienG/qkANWO7Yti/FXNoJMn5zlx4VvI5I/PsKU=; b=Nx7Cnh7/HjGnRGSl7 M9cXC/uQdAkDvSTxHJWdt0muJ3WUk6+J0zA4GlEyutm6ehkfiOp3ou7AHe349NmW V/0UaMGoq0nlivNci5MopotP2Us48I6QAnD7dg4v3EabOY2AKD4CTbXmss+otgrj 9xlXlfLKMdxNmHJjQWVXQZWnP460PCvFLKQ7YxtU1QqFDqAbZi+DLnJJZUvT6b47 SXs5doSeovCW+MIuPLNHZDBZcaWH8u7y0mVwmrnU595jTLOAGOcNrMNTFvzqYXHT KoHkZLEyyWBEWG7YoEgnpdLqyaCyzCtH13iQoZEWOqWuKgFfg26X8PRklRS+eUw2 jl77g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=HiO39ienG/qkANWO7Yti/FXNoJMn5zlx4VvI5I/Ps KU=; b=joOBz/hXZR0YEtSEDNC382oalJj1rWJWLxk0ahytr+3pKHuB/irqcFQ4O NNURGfPloRsKvCrllIpQgevQ9I45xp9B4K8RTJztdTqXeeUG4Cn1rnXUUicp/FBb mhu6Jwg0WcVM8DKjdStXLD4EL9kRMwlPdGWG3uQ8O98MtsoQuwPjiDQI+rHYcvGF QqyxwA+M52MO5ipA7qCObXbpuarLdrAJ3PJgeZvJkK5Bw5dO8JofnHyledHxEE0+ bjhQCUJxFnyHLfTh2KYrZkl7SELBpd7feig4r8Asg2Z5/Cx2TVD0AVX+60uxcDXR +jTu74ePSnpXhU22Sq/b+9sAzXNQg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrfedvgddugeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeegvedugfdvhfegfeeugfeivdfffefhkeeiudduueeh gfeukeduudeuledtgedvleenucffohhmrghinhepkhholhgufhhrohhnthdrughknecukf hppeejhedrudejvddrhedrvdefudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hm X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id BDB2B328005D; Wed, 30 Sep 2020 16:29:43 -0400 (EDT) Subject: Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) To: =?UTF-8?Q?Adam_Sj=c3=b8gren?= , Tom Lane Cc: pgsql-general@postgresql.org, Stephen Frost References: <87364kdsim.fsf@tullinup.koldfront.dk> <20200818143351.GA29590@tamriel.snowman.net> <1204950.1597762449@sss.pgh.pa.us> <87tuwyojsu.fsf@tullinup.koldfront.dk> <1416265.1597851073@sss.pgh.pa.us> <87lfi9pvyw.fsf@tullinup.koldfront.dk> <1605690.1597941827@sss.pgh.pa.us> <87zh57dnh2.fsf@tullinup.koldfront.dk> From: Adrian Klaver Message-ID: Date: Wed, 30 Sep 2020 13:29:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <87zh57dnh2.fsf@tullinup.koldfront.dk> 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: Precedence: bulk On 9/30/20 1:22 PM, Adam Sjøgren wrote: > Tom writes: > >> =?utf-8?Q?Adam_Sj=C3=B8gren?= writes: >>> Tom writes: >>>> ... which implies that the problem is unexpectedly high contention for the >>>> ProcArrayLock. >> >>> One thing I should have mentioned, but forgot, is that the database is >>> configured to do logical replication to another machine - could that >>> have an effect on the lock contention? >>> A colleague pointed out that in the pg_locks output, the replication >>> processes are waiting on the ProcArray lock: >>> · https://koldfront.dk/misc/postgresql/pg_stat_activity_pg_locks-BAD.txt.gz >> >> Yeah, that is *mighty* interesting. For the archives' sake, I'll point >> out that this shows 16 walsender processes, of which 6 are in >> WalSenderWaitForWAL waits (ie, basically idle) and all of the other 10 >> are waiting for the ProcArrayLock. > > Sorry for not returning on this before now. > > I have seen the slow login problem - ProcArrayLock contention - happen > with replication turned off, so I think that can be ruled out as the > cause. > > I just observed something interesting right now, however. > > Just to recap the scene: the basic setup is that we have a table with a > queue of jobs to be processed, and we have a number of programs (say 10) > on 6 other machines grabbing those jobs, doing calculations and > reporting back. I don't have an answer. Not even sure if this is relevant to the problem, but how are the jobs getting into the queue? > > The number of jobs at any given time can fluctuate from none to > millions. Typically millions of jobs take some days to a week to get > through. > > Now, I happened to have a psql prompt open when the problem of new > logins being slow appeared - and I ran a query that counted the number > of jobs by job-type. > > Before the slow login problem, that query took around 70-80 ms, but when > the slow login appeared, it took 20+ seconds to run the query. > > EXPLAIN ANALYZE showed that it was running a parallel query. > > So I tried turning parallel queries off - with SET > max_parallel_workers_per_gather = 0; - and now the query took around 150 > ms consistenly, despite logins still being (variably) slow. > > So that confirms the ProcArrayLock contention, I think. > > My next thought is: I have 6*10 programs making connections and doing > parallel queries over the job queue, to get new jobs. If the jobs happen > to be very "easy", those programs will be doing a lot of queries for > jobs. And when the queue is large enough (I'm guessing), those queries > will be parallel, so they will be creating new processes that need to be > added and removed from the ProcArray. > > So am I shooting myself in the foot here, by creating lock contention > when trying to get jobs quickly from a largeish table? > > I think my next step will be to modify the programs that grab the jobs > to avoid parallel queries when looking up the next job to run. > > You anticipated this, it just took me until now to get a little closer: > >> It's also evident that there's some parallel query activity going on, >> as some sessions are in BgWorkerShutdown waits; so parallel worker >> entry/exit might be contributing to the overall load on ProcArrayLock. > > > Best regards, > > Adam > -- Adrian Klaver adrian.klaver@aklaver.com