Re: PATCH: Batch/pipelining support for libpq
Daniel Verite <daniel@manitou-mail.org>
From: "Daniel Verite" <daniel@manitou-mail.org>
To: "Andres Freund" <andres@anarazel.de>
Cc: "Craig Ringer" <craig@2ndquadrant.com>,"Vaishnavi Prabakaran"
<vaishnaviprabakaran@gmail.com>,"Michael Paquier"
<michael.paquier@gmail.com>,"David Steele"
<david@pgmasters.net>,"Prabakaran, Vaishnavi"
<VaishnaviP@fast.au.fujitsu.com>,"Haribabu Kommi"
<kommi.haribabu@gmail.com>,"Tsunakawa, Takayuki"
<tsunakawa.takay@jp.fujitsu.com>,"Dmitry Igrishin"
<dmitigr@gmail.com>,"PostgreSQL Hackers"
<pgsql-hackers@postgresql.org>,"Manuel Kniep"
<m.kniep@web.de>,"fujita.etsuro@lab.ntt.co.jp"
<fujita.etsuro@lab.ntt.co.jp>,"Iwata, Aya" <iwata.aya@jp.fujitsu.com>
Date: 2017-06-22T11:43:35Z
Lists: pgsql-hackers
Andres Freund wrote:
- if (pqFlush(conn) < 0)
- goto sendFailed;
+ if (conn->batch_status == PQBATCH_MODE_OFF)
+ {
+ /*
+ * Give the data a push. In nonblock mode, don't complain if
we're unable
+ * to send it all; PQgetResult() will do any additional
flushing needed.
+ */
+ if (pqFlush(conn) < 0)
+ goto sendFailed;
+ }
Seems to be responsible for roughly an 1.7x speedup in tps and equivalent
decrease in latency, based on the "progress" info.
I wonder how much of that corresponds to a decrease in the number of
packets versus the number of syscalls. Both matter, I guess.
But OTOH there are certainly batch workloads where it will be preferrable
for the first query to reach the server ASAP, rather than waiting to be
coalesced with the next ones.
libpq is not going to know what's best.
One option may be to leave that decision to the user by providing a
PQBatchAutoFlush(true|false) property, along with a PQBatchFlush()
function. Maybe we could even let the user set the size of the sending
buffer, so those who really want to squeeze performance may tune it
for their network and workload.
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
Commits
-
Add libpq pipeline mode support to pgbench
- 9aa491abbf07 14.0 landed
-
Implement pipeline mode in libpq
- acb7e4eb6b1c 14.0 landed