pgbench: When using pipelining only do PQconsumeInput() when necessary.
authorAndres Freund
Thu, 5 Aug 2021 02:19:44 +0000 (19:19 -0700)
committerAndres Freund
Thu, 5 Aug 2021 02:19:58 +0000 (19:19 -0700)
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 
Discussion: https://postgr.es/m/20210720180039[email protected]
Backpatch: 14, where libpq/pgbench pipelining was introduced.

src/bin/pgbench/pgbench.c

index 364b5a2e47d01885d746fb83ed15798a9696d523..129cf2ed61d1499f49ad83e1eee66e70d59181e4 100644 (file)
@@ -3460,7 +3460,14 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
                 */
            case CSTATE_WAIT_RESULT:
                pg_log_debug("client %d receiving", st->id);
-               if (!PQconsumeInput(st->con))
+
+               /*
+                * Only check for new network data if we processed all data
+                * fetched prior. Otherwise we end up doing a syscall for each
+                * individual pipelined query, which has a measurable
+                * performance impact.
+                */
+               if (PQisBusy(st->con) && !PQconsumeInput(st->con))
                {
                    /* there's something wrong */
                    commandFailed(st, "SQL", "perhaps the backend died while processing");