Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XlRUN-0005pL-BD for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2014 23:56:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XlRUM-00044M-Ra for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2014 23:56:46 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XlRUL-00041Q-AM; Mon, 03 Nov 2014 23:56:45 +0000 Received: from mail-am1on0634.outbound.protection.outlook.com ([2a01:111:f400:fe00::634] helo=emea01-am1-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XlRUF-0002Ik-Q2; Mon, 03 Nov 2014 23:56:43 +0000 Received: from AM2PR07MB0659.eurprd07.prod.outlook.com (25.160.55.150) by AM2PR07MB0657.eurprd07.prod.outlook.com (25.160.55.149) with Microsoft SMTP Server (TLS) id 15.1.11.14; Mon, 3 Nov 2014 23:56:22 +0000 Received: from AM2PR07MB0659.eurprd07.prod.outlook.com ([25.160.55.150]) by AM2PR07MB0659.eurprd07.prod.outlook.com ([25.160.55.150]) with mapi id 15.01.0011.000; Mon, 3 Nov 2014 23:56:22 +0000 From: Mikko Tiihonen To: Craig Ringer , Andres Freund CC: "pgsql-hackers@postgresql.org" , "pgsql-jdbc@postgresql.org" Subject: Re: Pipelining executions to postgresql server Thread-Topic: [HACKERS] Pipelining executions to postgresql server Thread-Index: AQHP9doTvFE5xFKaR0KPR7jlrL4JypxMB5MAgAEyENiAAAo8AIAAAUG7gAGzzACAAGMpDw== Date: Mon, 3 Nov 2014 23:56:22 +0000 Message-ID: <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> In-Reply-To: <545790D8.9090201@2ndquadrant.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [89.27.31.97] x-microsoft-antispam: BCL:0;PCL:0;RULEID:;SRVR:AM2PR07MB0657; x-exchange-antispam-report-test: UriScan:; x-forefront-prvs: 0384275935 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(51704005)(24454002)(189002)(199003)(479174003)(377454003)(76176999)(20776003)(54356999)(50986999)(92726001)(107046002)(40100003)(64706001)(46102003)(95666004)(31966008)(15975445006)(21056001)(101416001)(105586002)(19580395003)(106356001)(106116001)(117636001)(92566001)(62966003)(77156002)(66066001)(15202345003)(4396001)(97736003)(122556002)(87936001)(120916001)(99396003)(77096003)(36756003)(2656002)(93886004)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR07MB0657; H:AM2PR07MB0659.eurprd07.prod.outlook.com; FPR:; MLV:sfv; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nitorcreations.com X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org > Craig Ringer wrote: > On 11/02/2014 09:27 PM, Mikko Tiihonen wrote: > > Is the following summary correct: > > - the network protocol supports pipelinings > Yes. >=20 > 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 conc= ept 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 correspondi= ng 1/2/T/D/C/Z replies for each request. Every 10 requests the test applica= tion waited for the all the replies to come to not overflow the network buf= fers (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 se= nding separate sync for each pipelined operation? > > - the server handles operations in order, starting the processing of ne= xt operation only after fully processing the previous one=20 > > - thus pipelining is invisible to the server >=20 > As far as I know, yes. The server just doesn't care. >=20 > > - libpq driver does not support pipelining, but that is due to internal= limitations >=20 > Yep. >=20 > > - if proper error handling is done by the client then there is no reaso= n why pipelining could be supported by any pg client >=20 > Indeed, and most should support it. Sending batches of related queries > would make things a LOT faster. >=20 > 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 >=20 > 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 opt= imize. > 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: >=20 > - 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 >=20 > - 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 origin= al 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. >=20 > 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 querie= s). 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 --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers