From: Scott Harrington <scotth01@sns-usa.com>
To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: [JDBC] Pipelining executions to postgresql server
Date: Sun, 2 Nov 2014 18:05:09 -0500 (Eastern Standard Time)
Message-ID: <alpine.WNT.2.11.1411021633360.4832@sitra> (raw)
In-Reply-To: <1414934833900.88748@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>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
>>>> On 2014-11-01 14:04:05 +0000, Mikko Tiihonen wrote:
>>>>> I created a proof of concecpt patch for postgresql JDBC driver that
>>>>> allows the caller to do pipelining of requests within a
>>>>> transaction. The pipelining here means same as for HTTP: the client
>>>>> can send the next execution already before waiting for the response of
>>>>> the previous request to be fully processed.
>>>>
>>>> Slightly confused here. To my knowledge the jdbc driver already employs
>>>> some pipelining? There's some conditions where it's disabled (IIRC
>>>> RETURNING for DML is one of them), but otherwise it's available.
>>>>
>>>> I'm very far from a pgjdbc expert, but that's what I gathered from the
>>>> code when investigating issues a while back and from my colleague Craig.
>>>
>>> Most DB interfaces make the server operations look synchronous.
>>
>> You IIRC can use jdbc's batch interface.
>
> Yes, there is a limited batch interface for inserts and updates. But for
> example when using prepared statements you can only do batches of same
> statement (with different parameters of course).
Hi Mikko,
I am very interested in this.
Indeed JDBC makes you wait for N round-trip delays. If my transaction
needs to to INSERT rows to tables A and B and UPDATE rows in tables C and
D (and then COMMIT), then I'm looking at 4-5 round trips, even with
executeBatch which as you mentioned is made to "look synchronous". If DB
is localhost it's OK, but gets painful if DB is across a LAN hop, and
unusable across a WAN.
As you've observed, there is no corresponding limitation in the FE/BE
protocol, if we can delay sending Sync until after we've sent all the
overlapping Binds and Executes.
I looked over your patch. Your list of ResultHandlerHolders seems to be
the right direction, but as Tom Lane mentioned there may need to be some
way to ensure the statements are all in the same transaction.
Off the top of my head I've sketched out an interface below (using
PGStatement & PGConnection so we don't have to downcast quite as far).
After the "sync" call you could call the original Statement.executeQuery
but it would return immediately. If you attempted to re-use a Statement
(or make additional addBatch calls) between the async() and sync() calls
then you would get an IllegalStateException. This avoids the need for a
Future, and avoids the client having to loop/sleep until done.
/**
* This interface defines the public PostgreSQL extensions to
* java.sql.Statement. All Statements constructed by the PostgreSQL
* driver implement PGStatement.
*/
public interface PGStatement
{
// ...
/** Like {@link PreparedStatement#executeQuery()} but no results until {@link PGConnection#sync}. */
void asyncExecuteQuery();
/** Like {@link PreparedStatement#executeUpdate()} but no results until {@link PGConnection#sync}. */
void asyncExecuteUpdate();
/** Like {@link Statement#executeBatch()} but no results until {@link PGConnection#sync}. */
void asyncExecuteBatch();
}
/**
* This interface defines the public PostgreSQL extensions to
* java.sql.Connection. All Connections returned by the PostgreSQL driver
* implement PGConnection.
*/
public interface PGConnection
{
// ...
/** Wait for all the asynchronous statements to complete. */
void sync();
/** Commit the current transaction, and wait for all the asynchronous statements to complete. */
void commitAndSync();
}
--
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: scotth01@sns-usa.com, Mikko.Tiihonen@nitorcreations.com, pgsql-hackers@postgresql.org
Subject: Re: [JDBC] Pipelining executions to postgresql server
In-Reply-To: <alpine.WNT.2.11.1411021633360.4832@sitra>
References: <1414850643686.34687@nitorcreations.com> <20141101173116.GR13584@awork2.anarazel.de> <1414930308808.49160@nitorcreations.com> <20141102122320.GB28295@alap3.anarazel.de> <1414934833900.88748@nitorcreations.com> <alpine.WNT.2.11.1411021633360.4832@sitra>
* 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