X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B28D111F671B for ; Mon, 17 Apr 2006 04:49:17 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.103 X-Spam-Level: X-Spam-Status: No, score=0.103 required=5 tests=[AWL=0.103] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 9uaZ90M5PoHC for ; Mon, 17 Apr 2006 04:49:11 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by postgresql.org (Postfix) with SMTP id 46DC011F6937 for ; Mon, 17 Apr 2006 04:49:12 -0300 (ADT) Received: (qmail 32530 invoked by uid 1112); 17 Apr 2006 07:49:12 -0000 Date: Mon, 17 Apr 2006 02:49:12 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary2.csoft.net To: Michael Barker cc: pgsql-jdbc@postgresql.org, Andy Oliver Subject: Re: [PATCH] Support for ping method. In-Reply-To: Message-ID: References: <1144305529.2955.11.camel@corona> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-895719990-1145260152=:30846" X-Archive-Number: 200604/114 X-Sequence-Number: 15048 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-895719990-1145260152=:30846 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed > On Thu, 6 Apr 2006, Michael Barker wrote: > >> Attached is a patch that adds support for a ping method on the >> AbstractJdbc2Connection. This is useful for JBoss (and other >> containers) where the container needs to check if the connection is >> alive before passing it to the caller. Currently JBoss does a "SELECT >> 1", but using the new ping method there is a boost in performance. >> Opening and closing 1000 connections from a datasource: >> > > There are a number of problems with this patch. In no particular order... > 6) I'm not sure what guarantees ping is trying to make. Is it solely to ensure that the backend is still connected or is it to ensure that the connection state is ready to receive new commands. Consider the following as the attached test case demonstrates: conn.setAutoCommit(false); conn.createStatement().execute("SELECT 1/0"); // Forces transaction abort conn.ping(); // Returns 0 saying connection is "good". conn.createStatement().execute("SELECT 1"); // Fails b/c in aborted txn. If you need the stronger guarantee of transaction state validity then I think you could try the V2 EmptyQuery attempt on the V3 protocol as well. When JDK1.6 comes out I imagine that this will be replaced by the Connection.isValid method which does not seem to require anything beyond a current backend connection. http://download.java.net/jdk6/docs/api/java/sql/Connection.html#isValid(int) Kris Jurka --0-895719990-1145260152=:30846 Content-Type: TEXT/PLAIN; charset=US-ASCII; name=PingTest.java Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=PingTest.java aW1wb3J0IGphdmEuc3FsLio7DQoNCnB1YmxpYyBjbGFzcyBQaW5nVGVzdCB7 DQoNCglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmcgYXJnc1tdKSB0 aHJvd3MgRXhjZXB0aW9uIHsNCgkJQ2xhc3MuZm9yTmFtZSgib3JnLnBvc3Rn cmVzcWwuRHJpdmVyIik7DQoNCgkJQ29ubmVjdGlvbiBjb25uID0gRHJpdmVy TWFuYWdlci5nZXRDb25uZWN0aW9uKCJqZGJjOnBvc3RncmVzcWw6Ly9sb2Nh bGhvc3Q6NTgyMC9qdXJrYSIsImp1cmthIiwiIik7DQoNCgkJY29ubi5zZXRB dXRvQ29tbWl0KGZhbHNlKTsNCgkJU3RhdGVtZW50IHN0bXQgPSBjb25uLmNy ZWF0ZVN0YXRlbWVudCgpOw0KCQl0cnkgew0KCQkJc3RtdC5leGVjdXRlKCJT RUxFQ1QgMS8wIik7DQoJCX0gY2F0Y2ggKFNRTEV4Y2VwdGlvbiBzcWxlKSB7 DQoJCQlzcWxlLnByaW50U3RhY2tUcmFjZSgpOw0KCQl9DQoNCgkJU3lzdGVt Lm91dC5wcmludGxuKCgob3JnLnBvc3RncmVzcWwuamRiYzIuQWJzdHJhY3RK ZGJjMkNvbm5lY3Rpb24pY29ubikucGluZygpKTsNCg0KCQlzdG10LmV4ZWN1 dGUoIlNFTEVDVCAxIik7DQoJfQ0KfQ0K --0-895719990-1145260152=:30846--