From: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
To: Craig Ringer <craig@2ndquadrant.com>
To: Andres Freund <andres@2ndquadrant.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: Pipelining executions to postgresql server
Date: Mon, 3 Nov 2014 23:56:22 +0000
Message-ID: <1415058981678.77807@nitorcreations.com> (raw)
In-Reply-To: <545790D8.9090201@2ndquadrant.com>
References: <1414850643686.34687@nitorcreations.com>
<20141101173116.GR13584@awork2.anarazel.de>
<1414930308808.49160@nitorcreations.com>
<20141102122320.GB28295@alap3.anarazel.de>
<1414934833900.88748@nitorcreations.com>
<545790D8.9090201@2ndquadrant.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
> Craig Ringer wrote:
> On 11/02/2014 09:27 PM, Mikko Tiihonen wrote:
> > Is the following summary correct:
> > - the network protocol supports pipelinings
> Yes.
>
> All you have to do is *not* send a Sync message and be aware that the
> server will discard all input until the next Sync, so pipelining +
> autocommit doesn't make a ton of sense for error handling reasons.
I do not quite grasp why not sending Sync is so important. My proof of concept setup was for queries with autocommit enabled.
When looking with wireshark I could observe that the client sent 3-10 P/B//D/E/S messages to server, before the server started sending the corresponding 1/2/T/D/C/Z replies for each request. Every 10 requests the test application waited for the all the replies to come to not overflow the network buffers (which is known to cause deadlocks with current pg jdbc driver).
If I want separate error handling for each execution then shouldn't I be sending separate sync for each pipelined operation?
> > - the server handles operations in order, starting the processing of next operation only after fully processing the previous one
> > - thus pipelining is invisible to the server
>
> As far as I know, yes. The server just doesn't care.
>
> > - libpq driver does not support pipelining, but that is due to internal limitations
>
> Yep.
>
> > - if proper error handling is done by the client then there is no reason why pipelining could be supported by any pg client
>
> Indeed, and most should support it. Sending batches of related queries
> would make things a LOT faster.
>
> PgJDBC's batch support is currently write-oriented. There is no
> fundamental reason it can't be expanded for reads. I've already written
> a patch to do just that for the case of returning generated keys.
>
> https://github.com/ringerc/pgjdbc/tree/batch-returning-support
>
> and just need to rebase it so I can send a pull for upstream PgJDBC.
> It's already linked in the issues documenting the limitatations in batch
>support.
Your code looked like good. Returning inserts are an important thing to optimize.
> If you want to have more general support for batches that return rowsets
> there's no fundamental technical reason why it can't be added. It just
> requires some tedious refactoring of the driver to either:
>
> - Sync and wait before it fills its *send* buffer, rather than trying
> to manage its receive buffer (the server send buffer), so it can
> reliably avoid deadlocks; or
>
> - Do async I/O in a select()-like loop over a protocol state machine,
> so it can simultaneously read and write on the wire.
I also think the async I/O is the way to go. Luckily that has already been done
in the pgjdbc-ng (https://github.com/impossibl/pgjdbc-ng), built on top
of netty java NIO library. It has quite good feature parity with the original
pgjdbc driver. I'll try next if I can enable the pipelining with it now that
I have tried the proof of concept with the originial pgjdbc driver.
> I might need to do some of that myself soon, but it's a big (and
> therefore error-prone) job I've so far avoided by making smaller, more
> targeted changes.
>
> For JDBC the JDBC batch interface is the right place to do this, and you
> should not IMO attempt to add pipelining outside that interface.
> (Multiple open resultsets from portals, yes, but not pipelining of queries).
I do not think the JDBC batch interface even allow doing updates to multiple
tables when using prepared statements?
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: Mikko.Tiihonen@nitorcreations.com, craig@2ndquadrant.com, andres@2ndquadrant.com, pgsql-hackers@postgresql.org
Subject: Re: Pipelining executions to postgresql server
In-Reply-To: <1415058981678.77807@nitorcreations.com>
References: <1414850643686.34687@nitorcreations.com> <20141101173116.GR13584@awork2.anarazel.de> <1414930308808.49160@nitorcreations.com> <20141102122320.GB28295@alap3.anarazel.de> <1414934833900.88748@nitorcreations.com> <545790D8.9090201@2ndquadrant.com> <1415058981678.77807@nitorcreations.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox