X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id 5FD0B11F6294 for ; Mon, 17 Apr 2006 10:37:22 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -2.599 X-Spam-Level: X-Spam-Status: No, score=-2.599 required=5 tests=[BAYES_00=-2.599] Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id 83Ws6HjEgvT8 for ; Mon, 17 Apr 2006 10:37:14 -0300 (ADT) X-Greylist: delayed 00:13:17.630836 by SQLgrey- Received: from [127.0.0.1] (superlinksoftware.com [71.29.62.31]) by postgresql.org (Postfix) with ESMTP id 0DC1511F6724 for ; Mon, 17 Apr 2006 10:37:09 -0300 (ADT) Received: from [192.168.1.100] (cpe-024-211-135-006.nc.res.rr.com 24.211.135.6) by set.superlinksoftware.com/JBossMail 1.0M4-preX (71.29.62.31) with SMTP id 114528016011354.97161747689313; Mon, 17 Apr 2006 09:22:40 -0400 (EDT) Message-ID: <444396DE.1020904@jboss.org> Date: Mon, 17 Apr 2006 09:23:42 -0400 From: Andrew Oliver User-Agent: Thunderbird 1.5 (Macintosh/20051201) MIME-Version: 1.0 To: Kris Jurka CC: Michael Barker , pgsql-jdbc@postgresql.org, Andy Oliver Subject: Re: [PATCH] Support for ping method. References: <1144305529.2955.11.camel@corona> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200604/115 X-Sequence-Number: 15049 In a connection pool, generally what has happened is someone or something takes the database down for maintenance and then every single dependency downstream takes a long time to recover, or the maximum time you're allowed to hold it has expired, or some network event has occurred. The JBoss connection validators let the connection pool bounce back from database outages rather quickly. We don't want the server to do any undue processing (faster is better). Mostly we'd like to send a byte or two and get a byte or two. If there is a more serious outage than an invalid connection then it is likely we'll rightly get an exception when the connection is used or re-established and that's okay. -Andy Kris Jurka wrote: > > >> 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 > > > ------------------------------------------------------------------------ > > import java.sql.*; > > public class PingTest { > > public static void main(String args[]) throws Exception { > Class.forName("org.postgresql.Driver"); > > Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5820/jurka","jurka",""); > > conn.setAutoCommit(false); > Statement stmt = conn.createStatement(); > try { > stmt.execute("SELECT 1/0"); > } catch (SQLException sqle) { > sqle.printStackTrace(); > } > > System.out.println(((org.postgresql.jdbc2.AbstractJdbc2Connection)conn).ping()); > > stmt.execute("SELECT 1"); > } > }