Skip to content

Commit fa604e0

Browse files
committed
pgbench: When using pipelining only do PQconsumeInput() when necessary.
Up to now we did a PQconsumeInput() for each pipelined query, asking the OS for more input - which it often won't have, as all results might already have been sent. That turns out to have a noticeable performance impact. Alvaro Herrera reviewed the idea to add the PQisBusy() check, but not this concrete patch. Author: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20210720180039.23rivhdft3l4mayn@alap3.anarazel.de Backpatch: 14, where libpq/pgbench pipelining was introduced.
1 parent e8086bd commit fa604e0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,14 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
34603460
*/
34613461
case CSTATE_WAIT_RESULT:
34623462
pg_log_debug("client %d receiving", st->id);
3463-
if (!PQconsumeInput(st->con))
3463+
3464+
/*
3465+
* Only check for new network data if we processed all data
3466+
* fetched prior. Otherwise we end up doing a syscall for each
3467+
* individual pipelined query, which has a measurable
3468+
* performance impact.
3469+
*/
3470+
if (PQisBusy(st->con) && !PQconsumeInput(st->con))
34643471
{
34653472
/* there's something wrong */
34663473
commandFailed(st, "SQL", "perhaps the backend died while processing");

0 commit comments

Comments
 (0)