-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
javax.sql.ConnectionPoolDataSource support #54
Comments
The HikariCP generated proxies do quite a bit more than simply making a The HikariCP generated For example, if you blindly reset the transaction isolation level, even if it was not modified some drivers will still send traffic over the wire to the database -- and is an expensive operation for many databases. Resetting 5 or 6 such attributes can generate a lot of chatter to the database which decreases the pool throughput (sometimes substantially). If HikariCP forgoes generating proxies, and simply relies on the two provided listener methods, essentially all of its value as a high-performance pool and its entire reason for existence is lost. |
are you 100% shure this "reset" is not a part of public static void main(String[] args) throws Throwable{
DB2ConnectionPoolDataSource ds = new DB2ConnectionPoolDataSource();
ds.setServerName("db2linux");
ds.setPortNumber(50001);
ds.setDatabaseName("SAMPLE");
ds.setUser("db2inst1");
ds.setPassword("zaq1xsw2");
ds.setDriverType(4);
PooledConnection pooledConnection = ds.getPooledConnection();
Connection cn = pooledConnection.getConnection();
boolean initialAutoCommit = cn.getAutoCommit();
System.out.printf("initialAutoCommit=%s%n", initialAutoCommit);
cn.setAutoCommit(!initialAutoCommit);
System.out.printf("now cn.getAutoCommit() is: %s%n", cn.getAutoCommit());
cn.close();
System.out.println("connection `released`");
cn = pooledConnection.getConnection();
System.out.println("connection `reobtained`");
System.out.printf("cn.getAutoCommit()==initialAutoCommit : %s%n", cn.getAutoCommit()==initialAutoCommit);
cn.close();
} will produce:
Seems like every According SoC (Separation of Concerns) |
btw. "reset" correctness may be broken just by using SQL instead Connection methods Connection.setSchema("foo") method or by executing SET CURRENT_SCHEMA=foo So your attempts to perform 100% correct reset just by intercepting Connection methods is obsolete... The only one who have a chance to deal with such cause is "native" |
Ok, I'll investigate it. BTW, HikariCP documentation states that using SQL to modify connection state rather than the JDBC-defined methods will result in unpredictable connection state management. |
unfortunately this is not 100% controllable when you using third-party components... |
generic object pooling benchmarks: |
StormpotBlazePool is 20x faster!
|
Re: connection state management, we don't particularly care if HikariCP solves every use case for every user, there are many pools for users to choose from if HikariCP does not work in their environment. Solutions that try to be all things to all people will by their nature offer mediocre performance. If someone is using a third-party component that, while being JDBC-based, is explicitly not using JDBC APIs to modify connection state, I'd say either stop using that component, or choose a pool that will blindly reset all connection state. |
You reject people to use your perfect solution just bcz this one feature. Isn't better to make it configurable? |
btw I'm playing now with different object pools, this one https://gist.github.com/dimzon/9958603#file-easypool-java is very easy to read/understand and outperforms ConcurrentBug ten times (32 concurrent threads, pool size=4) |
Please post a public fork of https://github.com/chrisvest/object-pool-benchmarks which contains your code addition of the ConcurrentBag. |
Just a note on ConnectionPoolDataSource, I looked at the PostgreSQL driver's implementation of ConnectionPoolDataSource, and the returned PooledConnections do not perform any state reset at all other than |
BTW, running JMH with more threads than CPU cores will generally generate less reliable results, unless you actually have 32-cores:
|
https://github.com/dimzon/object-pool-benchmarks
this really doesn't matter since your generated
this allow multiple combinations like 1+A, 2+A, 1+B, 2+B - the freedom of choice |
So I propose to split by 2 parts
developers can use any part separatly or together - at their choice
this means you need to create a ticket|issue for PostgreSQL driver's developers. |
I'm sorry, I don't like the idea of splitting the implementation. Ordinary users cannot make an informed choice between the implementations. As I did, user's would need to understand whether their JDBC driver ConnectionPoolDataSource implementation properly resets connection state or not in order to choose it. While this is possible with open source drivers, it is not possible with closed source drivers. And in the end, what is the "win"? The "win" is simply the removal of generated proxies. Frankly, I don't care. It's not worth it to me either in terms of code complexity, or dealing with user issues because they misconfigured their pool. Javassist is practically ubiquitous in server stack dependencies these days, and we haven't had any users clamoring for its removal. |
Re: Stormpot. While it is quite impressive, it is also unsuitable for HikariCP. The That being said, it is possible that we can borrow concepts from the BlazePool implementation and bring them into HikariCP. Those will need to be investigated. |
What about EasyPool?
|
You still misunderstood me. Keep generated proxy just make them implement
|
I would like to weight in on that and share recent experience of my own. One of our Java applications use HikariCP and MS SQL JDBC driver. Application just calls stored procedures on MS SQL and returns the result to the user. As mentioned in related mssql-jdbc link above, the driver itself doesn't "reset" the connection before every call. And as mentioned in this ticket, HikariCP doesn't implement You could say that driver itself should implement connection "reset". Probably, but that would be very inefficient because without Pooling API returned from pooling implementation they don't know when the connection is reused. They would need then to send "reset" after every SQL call. Some older JDBC drivers did exactly that, but I see the trend that now more and more drivers start to rely on That's why I kindly ask to reconsider this issue. |
Current HikariCP solution contains of 2 parts
java.sql.Connection
to something likejavax.sql.PooledConnection
Some JDBC drivers provide
javax.sql.ConnectionPoolDataSource
out-of the box. So bytecode generation isn't requred. I propose to split HikariCP for 2 lose-coupled parts:javax.sql.DataSource
to exactjavax.sql.ConnectionPoolDataSource
adapterjavax.sql.ConnectionPoolDataSource
api.In this case you can use both parts if JDBC driver doesn't support
javax.sql.ConnectionPoolDataSource
and only second part otherwise...The text was updated successfully, but these errors were encountered: