Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 90D001337B4A for ; Mon, 1 Nov 2010 06:16:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 08531-03 for ; Mon, 1 Nov 2010 09:16:18 +0000 (UTC) X-Greylist: delayed 00:06:38.267986 by SQLgrey-1.7.6 Received: from elitecore.com (mailhost.elitecore.com [203.88.135.194]) by mail.postgresql.org (Postfix) with ESMTP id 817E51337B3E for ; Mon, 1 Nov 2010 06:16:16 -0300 (ADT) Received: (qmail 14789 invoked from network); 1 Nov 2010 09:09:35 -0000 Received: from unknown (HELO sumitlenovo) (sumit.pandya@[192.168.2.57]) (envelope-sender ) by elitecore.com (qmail-ldap-1.03) with SMTP for ; 1 Nov 2010 09:09:35 -0000 From: "Sumit Pandya" To: "'Emanuel Freitas'" , References: Subject: Re: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state Date: Mon, 1 Nov 2010 14:41:51 +0530 Message-ID: <000301cb79a4$d1e7fbf0$3902a8c0@elitecore.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0004_01CB79D2.EBA2A8F0" X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3664 In-Reply-To: Thread-Index: Act3dKDtlaU9xGOPQhiRxADAobjhmgCL+X8Q X-Cyberoam-smtpxy-version: 1.0.6.3 X-Cyberoam-AV-Policy: Default Rule X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.907 tagged_above=-10 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, NORMAL_HTTP_TO_IP=0.001, T_RP_MATCHES_RCVD=-0.01, WEIRD_PORT=0.001 X-Spam-Level: X-Archive-Number: 201011/1 X-Sequence-Number: 21122 This is a multi-part message in MIME format. ------=_NextPart_000_0004_01CB79D2.EBA2A8F0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Dear Emanuel, You should try with JDBC Connection Pooling. There are great tutorials are available. Using Connection Pool generally improves performance by 3x. _____ From: Emanuel Freitas [mailto:ejsfreitas@gmail.com] Sent: Friday, October 29, 2010 7:52 PM To: pgsql-jdbc@postgresql.org Subject: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state Hello, I'm running a server that receives approximately 300 requests per second. For each request I need to do some operations in a database. So, when I receive a request i check if there is any active connection to the database and if not i create one. The code for create the connection is something like this: private Connection initConn() { try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException cnfe) { System.err.println("Error on Driver"); return null; } try { Connection db = DriverManager.getConnection("jdbc:postgresql://192.168.1.2:5432/test?loginTi meout=3", "test", "1234"); return db; } catch (SQLException sqle) { System.err.println("Error on Connection"); return null; } } If the database host is accessible the getConnection method works and I return the connection, on the other hand, if for some reason the host is not accessible I get a SQLException after 3 seconds (loginTimeout). That's exactly what i want to do. The problem is, for each time it executes the "getConnection" method one connection to the database is created and if the host is not accessible the connection stays in SYN_SENT state for alot of time... As I receive alot of requests per second these connections are created until it reaches the max connections allowed by the SO (linux). Can you tell me what I'm doing wrong or what can I do to prevent this? Thank You! ------=_NextPart_000_0004_01CB79D2.EBA2A8F0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Dear = Emanuel,

      =       You should try with JDBC Connection Pooling. There are great tutorials are available. Using = Connection Pool generally improves performance by 3x.

 


From: = Emanuel Freitas [mailto:ejsfreitas@gmail.com]
Sent: Friday, October 29, = 2010 7:52 PM
To: = pgsql-jdbc@postgresql.org
Subject: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND = state

 

Hello,

 

I'm running a server that receives approximately 300 requests = per second. For each request I need to do some operations in a database. So, = when I receive a request i check if there is any active connection to the = database and if not i create one. The code for create the connection is something = like this:

 

private Connection initConn() {

       &nbs= p;    try {

       &nbs= p;            = ;    = Class.forName("org.postgresql.Driver");

       &nbs= p;    } catch (ClassNotFoundException cnfe) {

       &nbs= p;            = ;    System.err.println("Error on Driver");

       &nbs= p;            = ;    return null;

    }

       &nbs= p;   

       &nbs= p;    try {

       &nbs= p;            = ;    Connection db =3D DriverManager.getConnection("jdbc:postgresql://192.168.1.2:5432/t= est?loginTimeout=3D3", "test", "1234");

       &nbs= p;            = ;    return db;

       &nbs= p;   

       &nbs= p;    } catch (SQLException sqle) {

       &nbs= p;            = ;            =     System.err.println("Error on Connection");

       &nbs= p;            = ;            =     return null;

       &nbs= p;            = ;    }

}

 

 

If the database host is accessible the getConnection method = works and I return the connection, on the other hand, if for some reason = the host is not accessible I get a SQLException after 3 seconds (loginTimeout). That's exactly what i want to = do. 

The problem is, for each time it executes the = "getConnection" method one connection to the database is created and if the = host is not accessible the connection stays in SYN_SENT state for alot of time... 

As I receive alot of requests per second these connections are = created until it reaches the max connections allowed by the SO = (linux). 

 

Can you tell me what I'm doing wrong or what can I do to prevent = this?

 

Thank You!

 

 

------=_NextPart_000_0004_01CB79D2.EBA2A8F0--