Pgbench: remove synchronous prepare

Started by Dmitrii Bondarabout 1 month ago2 messages
Jump to latest
#1Dmitrii Bondar
d.bondar@postgrespro.ru

Hi, Hackers!

I was testing a connection pooler with pgbench and pgbench froze. I
checked the traffic and noticed that pgbench just blocks the execution
while it is waiting the response to the prepare command.

To reproduce the problem, it is enough to run pgbouncer with the session
pooling mode and use more clients than the pool size. With the pool size
of 20:

pgbench -h localhost -p 6432 --client=21 --jobs=1 -S -T 1000 -P 1
postgres --protocol=prepared

Pgbench with the extended protocol flag does not have this issue because
pgbench sends the whole parse/bind/execute/sync packet sequence at once
and waits for the result asynchronously. I suggest implementing this
behavior for the prepared protocol too.

I attached the pgbouncer configuration to reproduce the issue and the
proposed fix. I prefer to add a new function to libpqfe instead of
changing the existing behavior or adding a new state to pgbench.
Although it is largely duplicated code, it looks to be as non-invasive
as possible. Implementation and naming need to be discussed.

Tests for pgbench passed. I made small changes to the expected output.

Regards,
Dmitrii Bondar.

Attachments:

pgbouncer.initext/plain; charset=UTF-8; name=pgbouncer.iniDownload
userlist.txttext/plain; charset=UTF-8; name=userlist.txtDownload
0001-Remove-synchronous-prepare-from-pgbench.patchtext/x-patch; charset=UTF-8; name=0001-Remove-synchronous-prepare-from-pgbench.patchDownload+74-6
#2Dmitrii Bondar
d.bondar@postgrespro.ru
In reply to: Dmitrii Bondar (#1)
Re: Pgbench: remove synchronous prepare

Add docs, fix a function number.

Show quoted text

On 1/27/26 10:34 AM, Dmitrii Bondar wrote:

Hi, Hackers!

I was testing a connection pooler with pgbench and pgbench froze. I
checked the traffic and noticed that pgbench just blocks the execution
while it is waiting the response to the prepare command.

To reproduce the problem, it is enough to run pgbouncer with the
session pooling mode and use more clients than the pool size. With the
pool size of 20:

pgbench -h localhost -p 6432 --client=21 --jobs=1 -S -T 1000 -P 1
postgres --protocol=prepared

Pgbench with the extended protocol flag does not have this
issue because pgbench sends the whole parse/bind/execute/sync packet
sequence at once and waits for the result asynchronously. I suggest
implementing this behavior for the prepared protocol too.

I attached the pgbouncer configuration to reproduce the issue and the
proposed fix. I prefer to add a new function to libpqfe instead of
changing the existing behavior or adding a new state to pgbench.
Although it is largely duplicated code, it looks to be as non-invasive
as possible. Implementation and naming need to be discussed.

Tests for pgbench passed. I made small changes to the expected output.

Regards,
Dmitrii Bondar.

Attachments:

0002-Remove-synchronous-prepare-from-pgbench.patchtext/x-patch; charset=UTF-8; name=0002-Remove-synchronous-prepare-from-pgbench.patchDownload+104-6