Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 60874 invoked from network); 26 Mar 2010 15:00:50 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 Mar 2010 15:00:50 -0000 Received: (qmail 63485 invoked by uid 500); 26 Mar 2010 15:00:49 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 63345 invoked by uid 500); 26 Mar 2010 15:00:49 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 63329 invoked by uid 99); 26 Mar 2010 15:00:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Mar 2010 15:00:49 +0000 X-ASF-Spam-Status: No, hits=-1144.0 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Mar 2010 15:00:48 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 19660234C4EB for ; Fri, 26 Mar 2010 15:00:28 +0000 (UTC) Message-ID: <953954047.510531269615628102.JavaMail.jira@brutus.apache.org> Date: Fri, 26 Mar 2010 15:00:28 +0000 (UTC) From: "Nick Brachet (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (DBCP-328) exponential wait when requesting connections while the database is down In-Reply-To: <1987097850.510431269615267341.JavaMail.jira@brutus.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DBCP-328?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Nick Brachet updated DBCP-328: ------------------------------ Description: 2 problems in one but they are very related: 1- When the database is down (the actual server/machine, not the MySQL instance) the JDBC driver will wait connectTimeout before timing out. BasicDataSource.createDataSource(), which calls validateConnectionFactory() when it initializes, is synchronized. So each threads are waiting on the synchronize lock so they can all then wait connectTimeout before finally timing out. Imagine a 5sec connectTimeout and 10 concurrent theads, the last thread will timeout after roughly 50 seconds. 2- Similarly when the database dies (again the actual server/machine, not the instance), after BasicDataSource has initialized, the JDBC driver will again wait connectTimeout before timing out when new connections are created to grown the pool. PoolableConnectionFactory#makeObject(), which calls createConnection(), is also synchronized causing the same exponential wait for any threads requesting a connection from the pool. Maybe I should explain that Connector/J closes the actual connection when it detects a communication failure with the database, and the connection is then removed from the pool. So when the database server dies the pool gets depleted and new connections need to be created. I am not sure how to address #1 but #2 can be addressed by calling createConnection() outside of any locks. For example: {noformat} public Object makeObject() throws Exception { ConnectionFactory connFactory; KeyedObjectPoolFactory stmtPoolFactory; ObjectPool pool; synchronized (this) { connFactory = _connFactory; stmtPoolFactory = _stmtPoolFactory; pool = _pool; } Connection conn = connFactory.createConnection(); if(null != stmtPoolFactory) { KeyedObjectPool stmtpool = stmtPoolFactory.createPool(); conn = new PoolingConnection(conn,stmtpool); stmtpool.setFactory((PoolingConnection)conn); } return new PoolableConnection(conn,pool,_config); } {noformat} Although there may be some problem if the pool is swapped while creating a connection... See also dbcp-300. was: 2 problems in one but they are very related: 1- When the database is down (the actual server/machine, not the MySQL instance) the JDBC driver will wait connectTimeout before timing out. BasicDataSource.createDataSource(), which calls validateConnectionFactory() when it initializes, is synchronized. So each threads are waiting on the synchronize lock so they can all then wait connectTimeout before finally timing out. Imagine a 5sec connectTimeout and 10 concurrent theads, the last thread will timeout after roughly 50 seconds. 2- Similarly when the database dies (again the actual server/machine, not the instance), after BasicDataSource has initialized, the JDBC driver will again wait connectTimeout before timing out when new connections are created to grown the pool. PoolableConnectionFactory#makeObject(), which calls createConnection(), is also synchronized causing the same exponential wait for any threads requesting a connection from the pool. Maybe I should explain that Connector/J closes the actual connection when it detects a communication failure with the database, and the connection is then removed from the pool. So when the database server dies the pool gets depleted and new connections need to be created. I am not sure how to address #1 but #2 can be addressed by calling createConnection() outside of any locks. For example: public Object makeObject() throws Exception { ConnectionFactory connFactory; KeyedObjectPoolFactory stmtPoolFactory; ObjectPool pool; synchronized (this) { connFactory = _connFactory; stmtPoolFactory = _stmtPoolFactory; pool = _pool; } Connection conn = connFactory.createConnection(); if(null != stmtPoolFactory) { KeyedObjectPool stmtpool = stmtPoolFactory.createPool(); conn = new PoolingConnection(conn,stmtpool); stmtpool.setFactory((PoolingConnection)conn); } return new PoolableConnection(conn,pool,_config); } Although there may be some problem if the pool is swapped while creating a connection... See also dbcp-300. > exponential wait when requesting connections while the database is down > ----------------------------------------------------------------------- > > Key: DBCP-328 > URL: https://issues.apache.org/jira/browse/DBCP-328 > Project: Commons Dbcp > Issue Type: Bug > Affects Versions: 1.2.2 > Environment: Tomcat Apache 5.5.28 > MySQL 5.1 / Connector/J 5.1.5 > JDK 1.5.0_22 > Reporter: Nick Brachet > > 2 problems in one but they are very related: > 1- When the database is down (the actual server/machine, not the MySQL instance) the JDBC driver will wait connectTimeout before timing out. BasicDataSource.createDataSource(), which calls validateConnectionFactory() when it initializes, is synchronized. So each threads are waiting on the synchronize lock so they can all then wait connectTimeout before finally timing out. > Imagine a 5sec connectTimeout and 10 concurrent theads, the last thread will timeout after roughly 50 seconds. > 2- Similarly when the database dies (again the actual server/machine, not the instance), after BasicDataSource has initialized, the JDBC driver will again wait connectTimeout before timing out when new connections are created to grown the pool. PoolableConnectionFactory#makeObject(), which calls createConnection(), is also synchronized causing the same exponential wait for any threads requesting a connection from the pool. > Maybe I should explain that Connector/J closes the actual connection when it detects a communication failure with the database, and the connection is then removed from the pool. So when the database server dies the pool gets depleted and new connections need to be created. > I am not sure how to address #1 but #2 can be addressed by calling createConnection() outside of any locks. > For example: > {noformat} > public Object makeObject() throws Exception { > ConnectionFactory connFactory; > KeyedObjectPoolFactory stmtPoolFactory; > ObjectPool pool; > synchronized (this) { > connFactory = _connFactory; > stmtPoolFactory = _stmtPoolFactory; > pool = _pool; > } > Connection conn = connFactory.createConnection(); > if(null != stmtPoolFactory) { > KeyedObjectPool stmtpool = stmtPoolFactory.createPool(); > conn = new PoolingConnection(conn,stmtpool); > stmtpool.setFactory((PoolingConnection)conn); > } > return new PoolableConnection(conn,pool,_config); > } > {noformat} > Although there may be some problem if the pool is swapped while creating a connection... > See also dbcp-300. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.