Re: Init connection time grows quadratically - Mailing list pgsql-hackers

From Matthias van de Meent
Subject Re: Init connection time grows quadratically
Date
Msg-id CAEze2WiHFA43SvV7SdQKjKyMjrSSdW+O6meaV+vk+YuwHr1UQg@mail.gmail.com
Whole thread Raw
List pgsql-hackers
On Tue, 27 May 2025 at 12:45, Потапов Александр
<a.potapov@postgrespro.ru> wrote:
>
> Hello!
>
> I ran some experiments with pgbench to measure the initialization time and found that the time increases
quadraticallywith the number of clients. It was surprising to me and I would like to understand a reason of such
behavior.
>
> Some details on how it was done:
>
[...]
>
> It turned out that the results correspond to a quadratic dependence like y ~ 0.0002x^2 where x is a number of clients
andy is init time (ms). 
> Here there is a question: is it expected behavior or a bug? What do you think? I appreciate any comments and
opinions.

Note that the value of "initial connection time" is based on the time
it takes from about the start of the pg_bench process until the moment
all N expected connections have been established, *not* the average
time it took pg_bench to connect to PostgreSQL. This does also not
exclude other known measurable delays (like spawning threads,
synchronization, etc), so the actual per-connection connection time is
probably closer to O(n) than O(n^2).

Q: Did you check that pgbench or the OS does not have
O(n_active_connections) or O(n_active_threads) overhead per worker
during thread creation or connection establishment, e.g. by varying
the number of threads used to manage these N clients? I wouldn't be
surprised if there are inefficiencies in e.g. the threading- or
synchronization model that cause O(N) per-thread overhead, or O(N^2)
overall when you have one thread per connection.

Kind regards,

Matthias van de Meent
Neon (https://neon.tech)



pgsql-hackers by date:

Previous
From: Потапов Александр
Date:
Subject: Re: Init connection time grows quadratically
Next
From: Laurenz Albe
Date:
Subject: Re: All supported PostgreSQL 17 extensions list