We have found the problem is in the org.h2.jdbcx.JdbcConnectionPool in
this method:
private Connection getConnectionNow() throws SQLException {
if (isDisposed) {
throw new IllegalStateException("Connection pool has been
disposed.");
}
PooledConnection pc;
if (!recycledConnections.empty()) {
pc = (PooledConnection) recycledConnections.pop();
} else {
pc = dataSource.getPooledConnection();
}
Connection conn = pc.getConnection(); // here
activeConnections++;
pc.addConnectionEventListener(poolConnectionEventListener);
return conn;
}
It calls PooledConnection.getConnection() on every connection client
request. The documentation of the Connection
javax.sql.PooledConnection.getConnection() throws SQLException is:
Creates and returns a Connection object that is a handle for the
physical connection that this PooledConnection object represents. The
connection pool manager calls this method when an application has
called the method DataSource.getConnection and there are no
PooledConnection objects available. See the interface description for
more information. Returns: a Connection object that is a handle to
this PooledConnection object Throws:
SQLException - if a database access error occurs;
SQLFeatureNotSupportedException - if the JDBC driver does not support
this method.
If I understand correctly this method should be called only if there
are no other connections in the pool. The implementation from H2 (and
the MiniConnectionPoolManager) calls this every time. Since the H2
implementation of the org.h2.jdbcx.JdbcXAConnection.getConnection
closes and reopens the connection its the cause of slowness -> every
request to the connection pool = close/create connection. In embedded
mode = close/open database files which is very slow.
I just wanted to give you the results from my investigation - maybe
you will be interested in (or maybe am I totally missing somehting).
Thanks for H2/MiniConnectionPoolManager anyway - great pieces of
software.
LZ
On 16 Říj, 14:32, Lukas Zapletal <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am reading from a one embedded table (one milion of records). I am
> doing very intensive small reads (1-10 records) of all records.
>
> When I am doing this in one connection I am done in 7 seconds.
>
> When I use the JdbcConnectionPool (with one thread - one connection)
> the very same thing is about 25 seconds.
>
> This is very strange. I understand that using connection pool is a bit
> slower than using one connection but three times? Since there is only
> one thread and one connection in the pool there should not be any
> blocking (waiting). Why am I getting these results?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---