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 1kNic5-0000Pu-RE for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 20:22:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kNic4-0000c5-RL for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 20:22:08 +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 1kNic4-0000by-HX for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 20:22:08 +0000 Received: from virgil.koldfront.dk ([212.237.178.116]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNic0-0005je-VG for pgsql-general@postgresql.org; Wed, 30 Sep 2020 20:22:07 +0000 Received: from tullinup.koldfront.dk (tullinup.koldfront.dk [192.168.1.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by virgil.koldfront.dk (Postfix) with ESMTPS id AD1B116BF05A8; Wed, 30 Sep 2020 22:22:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 virgil.koldfront.dk AD1B116BF05A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koldfront.dk; s=mail; t=1601497321; bh=Ggf5Xsn6yb6nquJzl0a7L3rQ4LdTyAcRAiMIamySIxg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=SGSMgsVsSCHMhiLV7OQL5PLW0cDmvq0I2F+OUamnZCHErGZptk1p7ZEbvGceCOEEe wX/WDJSyiQb8EJdusJJqtlrr5Z2uNY96Psa607OS25EyhPQM0IZOKgojilHY5EDQmc TJKK6bTlsWx/L0c+of98fgYWh8l4DxkuVzbnlwoG8Lcd3z/dSTl/4njqmKn63EyzGB IZf769YIQBrosab8xTTLpxingTDMoKI2fPqgqOVp87cb+5/p8MHCnHygGAlSPvyYCV 606QIEJ6gu3LDh9rMZdbm3euBw+b3Aj1wus8FwKEPa0I3aVZswaj1iuJX2j5FYCAin qd/NlaH9/xk2Q== Received: by tullinup.koldfront.dk (Postfix, from userid 1000) id 9914E20176647; Wed, 30 Sep 2020 22:22:01 +0200 (CEST) From: =?utf-8?Q?Adam_Sj=C3=B8gren?= To: Tom Lane Cc: pgsql-general@postgresql.org, Stephen Frost Subject: Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Organization: koldfront - analysis & revolution, Copenhagen, Denmark 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> OpenPGP: id=476630590A231909B0A0961A49D0746121BDE416; url=https://asjo.koldfront.dk/gpg.asc X-Hashcash: 1:21:200930:sfrost@snowman.net::xBww1tXlQUZnuwDC:00000000000000000000000000000000000000000001pPs X-Hashcash: 1:21:200930:pgsql-general@postgresql.org::/z0hb3y2HAVNJ83O:0000000000000000000000000000000007VpR X-Hashcash: 1:21:200930:tgl@sss.pgh.pa.us::Tg2BaOLKZfXP6Oe6:00000000000000000000000000000000000000000000MLNl X-Face: )qY&CseJ?.:=8F#^~GcSA?F=9eu'{KAFfL1C3/A&:nE?PW\i65"ba0NS)97,Q(^@xk}n4Ou rPuR#V8I(J_@~H($[ym:`K_+]*kjvW>xH5jbgLBVFGXY:(#4P>zVBklLbdL&XxL\M)%T}3S/IS9lMJ ^St'=VZBR (Tom Lane's message of "Thu, 20 Aug 2020 12:43:47 -0400") Message-ID: <87zh57dnh2.fsf@tullinup.koldfront.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tom writes: > =3D?utf-8?Q?Adam_Sj=3DC3=3DB8gren?=3D 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: >> =C2=B7 https://koldfront.dk/misc/postgresql/pg_stat_activity_pg_locks-B= AD.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. 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 =3D 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 --=20 "That's one of the remarkable things about life. Adam Sj=C3=B8gr= en It's never so bad that it can't get worse." asjo@koldfront.dk