pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Alexander Pyhalov <alp@sfedu.ru>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: LWLock optimization
Date: Tue, 23 Jul 2019 12:53:39 -0700
Message-ID: <20190723195339.hgnldeep7kvihfc4@alap3.anarazel.de> (raw)
In-Reply-To: <VI1PR05MB620666631A41186ACC3FC91ACFC70@VI1PR05MB6206.eurprd05.prod.outlook.com>
References: <VI1PR05MB620666631A41186ACC3FC91ACFC70@VI1PR05MB6206.eurprd05.prod.outlook.com>

Hi,

On 2019-07-23 16:28:52 +0000, Alexander Pyhalov wrote:
> I was asked to bring up this topic on maling lists after asking question on IRC. 
> 
> The issue is the following.
> On one of our servers (10.5), I see a lot of queries with wait_event_type='LWLock', wait_event='lock_manager' 

Could you qualify this a bit more?  What does "a lot" mean, in
comparison to the total number of queries/session?


> This is a stat gathering/analyzing application with tables which have
> > 100 partitions.

Hm, what kind of partitioning scheme is this? The "new"-ish partitioning
support isn't yet always that good to only perform the minimal amount of
metadata lookups (which in turn require locks). Especially in 10.

Are you using prepared statements?


> The queries itself are mostly simple (select by pkey, update by primary key and so on).
> 
>  select count(*) from pg_locks shows about 40K  records (all granted) and 
> 
>  select count(*) from (select distinct locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid from pg_locks) 
> 
> is varying from about 1K to 25K (I haven't stored this value in monitoring system, just observed manually).

I think to know what exactly is going on, we'd need a cpu profile, and
then perhaps a followup profile for also getting the callsites for lock
waits.  Could you take a perf profile?

https://wiki.postgresql.org/wiki/Profiling_with_perf

> Currently I was adviced to increase LOG2_NUM_LOCK_PARTITIONS at
> compile time. If it bothers us enough, we would likely do it, but I
> have a question, if this (or NUM_LOCK_PARTITIONS) value should be
> increased by default or set tunable?

I'm not quite sure what you're asking precisely here. Are you wondering
whether postgres should increase the default value for
LOG2_NUM_LOCK_PARTITIONS should be increased? And whether it should be
runtime configurable?  I'm fairly sure we don't want to make it runtime
configurable, that'd add overhead to some pretty central code.
Increasing the default would need a lot of benchmarks, to prove it
doesn't cause regressions in other common scenarios.

Greetings,

Andres Freund





view thread (2+ messages)

Message-ID: <20190723195339.hgnldeep7kvihfc4@alap3.anarazel.de>
Permalink:  ../20190723195339.hgnldeep7kvihfc4@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20190723195339.hgnldeep7kvihfc4@alap3.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andres@anarazel.de, alp@sfedu.ru
  Subject: Re: LWLock optimization
  In-Reply-To: <20190723195339.hgnldeep7kvihfc4@alap3.anarazel.de>
  References: <VI1PR05MB620666631A41186ACC3FC91ACFC70@VI1PR05MB6206.eurprd05.prod.outlook.com> <20190723195339.hgnldeep7kvihfc4@alap3.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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