pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Database logins taking longer and longer, showing up as "authentication" in ps(1)
5+ messages / 3 participants
[nested] [flat]

* Re: Database logins taking longer and longer, showing up as "authentication" in ps(1)
@ 2020-09-30 20:22 Adam Sjøgren <asjo@koldfront.dk>
  2020-09-30 20:29 ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Adam Sjøgren @ 2020-09-30 20:22 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@postgresql.org, Stephen Frost <sfrost@snowman.net>

Tom writes:

> =?utf-8?Q?Adam_Sj=C3=B8gren?= <asjo@koldfront.dk> 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.

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

-- 
 "That's one of the remarkable things about life.           Adam Sjøgren
  It's never so bad that it can't get worse."          asjo@koldfront.dk





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Database logins taking longer and longer, showing up as "authentication" in ps(1)
  2020-09-30 20:22 Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
@ 2020-09-30 20:29 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2020-09-30 21:30   ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
  0 siblings, 1 reply; 5+ messages in thread

From: Adrian Klaver @ 2020-09-30 20:29 UTC (permalink / raw)
  To: Adam Sjøgren <asjo@koldfront.dk>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@postgresql.org, Stephen Frost <sfrost@snowman.net>

On 9/30/20 1:22 PM, Adam Sjøgren wrote:
> Tom writes:
> 
>> =?utf-8?Q?Adam_Sj=C3=B8gren?= <asjo@koldfront.dk> 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





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Database logins taking longer and longer, showing up as "authentication" in ps(1)
  2020-09-30 20:22 Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
  2020-09-30 20:29 ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-09-30 21:30   ` Adam Sjøgren <asjo@koldfront.dk>
  2020-09-30 21:41     ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Adam Sjøgren @ 2020-09-30 21:30 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general@postgresql.org, Stephen Frost <sfrost@snowman.net>

Adrian writes:

> 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?

Plain INSERTs - often a lot at the same time. I inserted 400K jobs to
clean up after a bug earlier today, for instance.

What were you suspecting?


  Best regards,

    Adam

-- 
 "Don't think twice                                         Adam Sjøgren
  It's all right"                                      asjo@koldfront.dk





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Database logins taking longer and longer, showing up as "authentication" in ps(1)
  2020-09-30 20:22 Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
  2020-09-30 20:29 ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adrian Klaver <adrian.klaver@aklaver.com>
  2020-09-30 21:30   ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
@ 2020-09-30 21:41     ` Adrian Klaver <adrian.klaver@aklaver.com>
  2020-09-30 22:15       ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Michael Lewis <mlewis@entrata.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Adrian Klaver @ 2020-09-30 21:41 UTC (permalink / raw)
  To: Adam Sjøgren <asjo@koldfront.dk>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general@postgresql.org, Stephen Frost <sfrost@snowman.net>

On 9/30/20 2:30 PM, Adam Sjøgren wrote:
> Adrian writes:
> 
>> 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?
> 
> Plain INSERTs - often a lot at the same time. I inserted 400K jobs to
> clean up after a bug earlier today, for instance.
> 
> What were you suspecting?

Honestly a fishing expedition. All the discussion, as far as I could 
remember, had to do with the retrieval part of the process. Just thought 
for completeness it might be useful to flesh out the insertion portion 
of the process. Though it does get one to wondering how the appearance 
of a large number of jobs at once affects the those programs looking for 
new jobs?

> 
> 
>    Best regards,
> 
>      Adam
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Database logins taking longer and longer, showing up as "authentication" in ps(1)
  2020-09-30 20:22 Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
  2020-09-30 20:29 ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adrian Klaver <adrian.klaver@aklaver.com>
  2020-09-30 21:30   ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
  2020-09-30 21:41     ` Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adrian Klaver <adrian.klaver@aklaver.com>
@ 2020-09-30 22:15       ` Michael Lewis <mlewis@entrata.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Michael Lewis @ 2020-09-30 22:15 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Adam Sjøgren <asjo@koldfront.dk>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general; Stephen Frost <sfrost@snowman.net>

On Wed, Sep 30, 2020 at 3:41 PM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

> On 9/30/20 2:30 PM, Adam Sjøgren wrote:
> > Adrian writes:
> >
> >> 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?
> >
> > Plain INSERTs - often a lot at the same time. I inserted 400K jobs to
> > clean up after a bug earlier today, for instance.
> >
> > What were you suspecting?
>
> Honestly a fishing expedition. All the discussion, as far as I could
> remember, had to do with the retrieval part of the process. Just thought
> for completeness it might be useful to flesh out the insertion portion
> of the process. Though it does get one to wondering how the appearance
> of a large number of jobs at once affects the those programs looking for
> new jobs?
>

Is autovacuum/analyze keeping up with the changes to allow the planner to
make prudent choices? With so many updates/deletes, I would hope so but if
still using the 20% or 10% default values for scale_factor, and at times
the table has many millions of rows, perhaps not.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2020-09-30 22:15 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 20:22 Re: Database logins taking longer and longer, showing up as "authentication" in ps(1) Adam Sjøgren <asjo@koldfront.dk>
2020-09-30 20:29 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-09-30 21:30   ` Adam Sjøgren <asjo@koldfront.dk>
2020-09-30 21:41     ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-09-30 22:15       ` Michael Lewis <mlewis@entrata.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox