pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <rjpeace@earthlink.net>
To: Alan Stange <stange@rentec.com>
To: pgsql-performance@postgresql.org
Subject: Re: limit number of concurrent callers to a stored
Date: Wed, 17 Aug 2005 23:19:04 -0400
Message-ID: <6.2.3.4.0.20050817224934.05c09228@pop.earthlink.net> (raw)
In-Reply-To: <4303E704.4030200@rentec.com>
References: <4303E704.4030200@rentec.com>

At 09:40 PM 8/17/2005, Alan Stange wrote:

>is there a simple way to limit the number of concurrent callers to a 
>stored proc?
>
>The problem we have is about 50 clients come and perform the same 
>operation at nearly the same time.  Typically, this query takes a 
>few seconds to run, but in the case of this thundering herd the 
>query time drops to 70 seconds or much more.  The query can return 
>up to 15MB of data.

I'm assuming there is some significant write activity going on at 
some point as a result of the query, since MVCC should not care about 
concurrent read activity?

Is that "a few seconds each query" or "a few seconds total if we run 
50 queries sequentially but 70+ seconds per query if we try to run 50 
queries concurrently"?

A) If the former, "a few seconds" * 50 can easily be 70+ seconds, and 
things are what you should expect.  Getting higher performance in 
that situation means reducing per query times, which may or may not 
be easy.  Looking at the stored procedure code with an eye towards 
optimization would be a good place to start.

B) If the later, then table access contention is driving performance 
into the ground, and there are a few things you can try:
1= lock the table(s) under these circumstances so only one query of 
the 50 can be acting on it at a time.  If the table(s) is/are small 
enough to be made RAM resident, this may be a particularly low-cost, 
low-effort, reasonable solution.

2= put a queue into place and only let some small number n of queries 
run against the table(s) concurrently.  Adjust n until you get best 
performance.  There are a few ways this could be done.

3= Buy a SSD and put the table(s) in question on it.  IIRC, 3.5" 
format SSDs that can "drop in" replace HDs are available in up to 
147GB capacities.


>The machine is a dual opteron, 8 GB memory, lots of fiber channel 
>disk, Linux 2.6, etc.
>
>So, I'm thinking that a semaphore than will block more than N 
>clients from being in the core of the function at one time would be 
>a good thing.

This will only help in case "B" above.  If you go the "hard" route of 
using systems programming, you will have a lot of details that must 
be paid attention to correctly or Bad Things (tm) will 
happen.  Putting the semaphore in place is the tip of the iceberg.


Hope this helps,
Ron Peacetree






view thread (5+ messages)  latest in thread

Message-ID: <6.2.3.4.0.20050817224934.05c09228@pop.earthlink.net>
Permalink:  ../6.2.3.4.0.20050817224934.05c09228@pop.earthlink.net/
Also on:    postgresql.org/message-id/6.2.3.4.0.20050817224934.05c09228@pop.earthlink.net

 · 

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-performance@postgresql.org
  Cc: rjpeace@earthlink.net, stange@rentec.com
  Subject: Re: limit number of concurrent callers to a stored
  In-Reply-To: <6.2.3.4.0.20050817224934.05c09228@pop.earthlink.net>
  References: <4303E704.4030200@rentec.com> <6.2.3.4.0.20050817224934.05c09228@pop.earthlink.net>

* 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