Re: Issues Scaling Postgres Concurrency

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Harrison Borges <harrison(at)rlly(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Issues Scaling Postgres Concurrency
Date: 2023-03-14 21:47:43
Message-ID: b64a4d9fbc2ed8604886ba7994629f708c7d4e00.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 2023-03-13 at 12:24 -0400, Harrison Borges wrote:
> I’m running into severe performance problems with Postgres as I increase the number
> of concurrent requests against my backend. I’ve identified that the bottleneck is
> Postgres, and to simplify the test case, I created an endpoint that only does a
> count query on a table with ~500k rows. At 5 concurrent users, the response time
> was 33ms, at 10 users it was 60ms, and at 20 users it was 120ms.
>
> As the number of concurrent users increases, the response time for the count query
> also increases significantly, indicating that Postgres may not be scaling well to
> handle the increasing load. 
>
> This manifests in essentially a server meltdown on production. As the concurrent
> requests stack up, our server is stuck waiting for more and more queries.
> Eventually requests begin timing out as they start taking over 30 seconds to respond.
>
> Am I doing something obviously wrong? Does this sound like normal behavior?

That sounds like quite normal and expected behavior.

A query that counts the number of rows in a table of half a million rows is
quite expensive and keeps a CPU core busy for a while (provided everything is
cached). At some degree of parallelism, your CPU is overloaded, which leads
to non-linear slowdown.

The thing you are doing wrong is that you are putting too much load on this
system.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2023-03-14 22:05:05 Re: Issues Scaling Postgres Concurrency
Previous Message Alan Hodgson 2023-03-14 18:01:35 Re: Issues Scaling Postgres Concurrency