java - Why is it impossible to serve connections from pool according to the prepared statement already executed with them? -
i've been researching around web efficient way design connection pool , tried analyze details available libraries (hikaricp, bonecp, etc.).
our application heavy-load consumer webapp , of time users working on similar business objects (thus underlying sql queries executed same, still there numerous). designed work different dbms (oracle , ms sql server especially).
so simplified use case :
- user goes on particular jsp page (e.g. enterprise).
- a corresponding bean created.
- each time realizes action (e.g.
getemployees()
,computeturnover()
), bean asks pool connection , returns when done.
if want take advantage of prepared statement caching of underlying jdbc driver (as pstatements attached connection - jtds doc.), understand optimal way of doing :
- analyze kind of sql query particular bean want execute before providing available connection pool.
- find connection same prepared statement has been executed if possible.
- serve connection accordingly (and use benefits of cache/precompiled statement).
- return connection pool , start over.
am missing important point here (like jdbc drivers capable of reusing cached statements regardless of connection) or analysis correct ?
the different sources found state not possible, why ?
for scheme work, you'd need able connection has statement prepared.
this falls foul on 2 points:
- in jdbc obtain connection first,
- cached prepared statements (if driver or connection pool supports that) aren't exposed in standardized way (if @ all) nor able introspect them.
the performance overhead of finding right connection (and subsequent contention on few connections have prepared) undo benefit of reusing prepared statement.
also note database systems have serverside cache prepared statements (meaning has plan etc available), limiting overhead new prepare client.
if think performance benefit big enough, should consider using data source specific functionality (so guaranteed connection have statement in cache).
Comments
Post a Comment