Thread: [c3p0-users] NewProxyConnection.setReadOnly actually acquires connection?
Status: Beta
Brought to you by:
swaldman
From: dukehoops <ni...@do...> - 2009-01-31 03:17:50
|
I have a webapp with the following stack: Tomcat6/Spring/Hibernate/EhCache/c3p0 (0.9.1.2) Spring's HibernateTransactionManager is used. I noticed that requests that hit cache and never go to DB (no JDBC traffic), still acquire a connection from ComboPooledDataSource - as far as i can tell that should not be happening (I would expect a concrete connection to be acquired only when it is about to be used). Spring's DataSourceUtils.perpareConnectionForTransaction gets passed in a NewProxyConnection 'con'. However, when con.setReadOnly(true) is called, a concrete connection is checked out from BasicResourcePool. Is that the expected behavior? If so, why? I read through NewProxyConnectionGenerator but cannot tell whether the following means "get concrete instance": else if ( mname.equals("setReadOnly") ) { //do nothing with txn_known_resolved super.generateDelegateCode( intfcl, genclass, method, iw ); iw.println( "parentPooledConnection.markNewReadOnly( " + CodegenUtils.generatedArgumentName( 0 ) + " );"); } ----- ---------------- Nikita Tovstoles vside.com ---------------- -- View this message in context: http://www.nabble.com/NewProxyConnection.setReadOnly-actually-acquires-connection--tp21759481p21759481.html Sent from the c3p0 - users mailing list archive at Nabble.com. |
From: Steve W. <swa...@mc...> - 2009-01-31 03:39:42
|
Hi, The code you're looking at is a code generator. All that happens on setReadOnly() is that a flag gets set on the internal pooled Connection. The concrete Connection has already been checked out and is wrapped in your NewProxyConnection. smiles, Steve On Jan 30, 2009, at 10:17 PM, dukehoops wrote: > > I have a webapp with the following stack: > Tomcat6/Spring/Hibernate/EhCache/c3p0 (0.9.1.2) > > Spring's HibernateTransactionManager is used. > > I noticed that requests that hit cache and never go to DB (no JDBC > traffic), > still acquire a connection from ComboPooledDataSource - as far as i > can tell > that should not be happening (I would expect a concrete connection > to be > acquired only when it is about to be used). > > Spring's DataSourceUtils.perpareConnectionForTransaction gets passed > in a > NewProxyConnection 'con'. However, when con.setReadOnly(true) is > called, a > concrete connection is checked out from BasicResourcePool. Is that the > expected behavior? If so, why? > > I read through NewProxyConnectionGenerator but cannot tell whether the > following means "get concrete instance": > > else if ( mname.equals("setReadOnly") ) > { > //do nothing with txn_known_resolved > > super.generateDelegateCode( intfcl, genclass, method, > iw ); > > iw.println( "parentPooledConnection.markNewReadOnly( " + > CodegenUtils.generatedArgumentName( 0 ) + " );"); > } > > > > > ----- > ---------------- > Nikita Tovstoles > vside.com > ---------------- > > -- > View this message in context: http://www.nabble.com/NewProxyConnection.setReadOnly-actually-acquires-connection--tp21759481p21759481.html > Sent from the c3p0 - users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > c3p0-users mailing list > c3p...@li... > https://lists.sourceforge.net/lists/listinfo/c3p0-users ~oo~ Steve Waldman swa...@mc... |
From: dukehoops <ni...@do...> - 2009-01-31 21:03:30
|
Howdy, Thanks for a prompt response! So, if by the time NewProxyConnection.setReadyOnly() is executed a Connection has already been checked out then please help me clarify the following: - When NewProxyConnection is first instantiated a Connection is *not* checked out from the pool, correct? - I am assuming that calling certain methods of NewProxyConnection will NOT trigger acquisition of a Connection from the pool (hence the point of this proxy), while calling other will, correct? - I am having a bit of difficulty deciphering the codegen code in JdbcProxyGenerator.java - could you please point to an example of: a) NewProxyConnection method that will not force acquisition of connection, and b) one that will. Here's my underlying problem: I have service methods that are annotated with @Transactional that execute with 100% cache hit rate and do not go to DB at all. Yet, for some reason, a connection is still checked out/in from/to c3p0 pool on every invocation. Since checkout/in methods are synchronized they become hot spots under higher loads (50+ concurrent Tomcat threads) and result in HTTP threads being blocked. I would like to avoid connection check-out calls in this case. I am assuming c3p0 is designed to delay checking out of a Connection until some JDBC traffic is about to be sent - so that a connection is NOT acquired merely because HibernateTransactionManager asks for one (instead manager gets a proxy). thanks. -nikita Steve Waldman wrote: > > Hi, > > The code you're looking at is a code generator. All that happens on > setReadOnly() is that a flag gets set on the internal pooled > Connection. The concrete Connection has already been checked out and > is wrapped in your NewProxyConnection. > > smiles, > Steve > ----- ---------------- Nikita Tovstoles vside.com ---------------- -- View this message in context: http://www.nabble.com/NewProxyConnection.setReadOnly-actually-acquires-connection--tp21759481p21768236.html Sent from the c3p0 - users mailing list archive at Nabble.com. |
From: Steve W. <swa...@mc...> - 2009-01-31 21:13:51
|
nikita, I think c3p0 is not as clever as you want it to be. It does not defer Connection checkout to the first jdbc call on the proxy. (That's a good idea, but not implemented.) When you have a NewProxyConnection, you have a Connection that has been checked out from the pool. NewProxyConnection requires a Connection upon Construction. If your transaction does go to the DB, why is getConnection() called on a DataSource? That's the point at which a Connection is checked out. Why is there a Connection/pseudoConnection/Connection wrapper whatever around that gets setReadOnly() called? To make sense of the code, type any codegen (or just build the package), and check out the directory build/codegen. The NewProxyConnection is much more comprehensible when you look at its source rather than the source of the code generator. smiles, Steve On Jan 31, 2009, at 4:03 PM, dukehoops wrote: > > Howdy, > > Thanks for a prompt response! So, if by the time > NewProxyConnection.setReadyOnly() is executed a Connection has > already been > checked out then please help me clarify the following: > > - When NewProxyConnection is first instantiated a Connection is *not* > checked out from the pool, correct? > > - I am assuming that calling certain methods of NewProxyConnection > will NOT > trigger acquisition of a Connection from the pool (hence the point > of this > proxy), while calling other will, correct? > > - I am having a bit of difficulty deciphering the codegen code in > JdbcProxyGenerator.java - could you please point to an example of: a) > NewProxyConnection method that will not force acquisition of > connection, and > b) one that will. > > Here's my underlying problem: I have service methods that are > annotated with > @Transactional that execute with 100% cache hit rate and do not go > to DB at > all. Yet, for some reason, a connection is still checked out/in from/ > to c3p0 > pool on every invocation. Since checkout/in methods are synchronized > they > become hot spots under higher loads (50+ concurrent Tomcat threads) > and > result in HTTP threads being blocked. I would like to avoid connection > check-out calls in this case. > > I am assuming c3p0 is designed to delay checking out of a Connection > until > some JDBC traffic is about to be sent - so that a connection is NOT > acquired > merely because HibernateTransactionManager asks for one (instead > manager > gets a proxy). > > thanks. > > -nikita > > > > Steve Waldman wrote: >> >> Hi, >> >> The code you're looking at is a code generator. All that happens on >> setReadOnly() is that a flag gets set on the internal pooled >> Connection. The concrete Connection has already been checked out and >> is wrapped in your NewProxyConnection. >> >> smiles, >> Steve >> > > ----- > ---------------- > Nikita Tovstoles > vside.com > ---------------- > > -- > View this message in context: http://www.nabble.com/NewProxyConnection.setReadOnly-actually-acquires-connection--tp21759481p21768236.html > Sent from the c3p0 - users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > c3p0-users mailing list > c3p...@li... > https://lists.sourceforge.net/lists/listinfo/c3p0-users ~oo~ Steve Waldman swa...@mc... |
From: dukehoops <ni...@do...> - 2009-02-01 02:30:38
|
Bummer. getConnection() is called indirectly by spring's HibernateTransactionManager when the latter is told that a given method is demarcated with a TransactionDefinition. At that point tm get a connection and applied to it configuration specified by tx definition (such as the read-only flag). I am unsure why spring's tx manager is not doing the same smart thing there. I am surprised this use case hasn't been raised before - will do some research with spring users and report back. Thanks for your help, -nikita Steve Waldman wrote: > > nikita, > > I think c3p0 is not as clever as you want it to be. It does not defer > Connection checkout to the first jdbc call on the proxy. (That's a > good idea, but not implemented.) When you have a NewProxyConnection, > you have a Connection that has been checked out from the pool. > NewProxyConnection requires a Connection upon Construction. > > If your transaction does go to the DB, why is getConnection() called > on a DataSource? That's the point at which a Connection is checked > out. Why is there a Connection/pseudoConnection/Connection wrapper > whatever around that gets setReadOnly() called? > > To make sense of the code, type any codegen (or just build the > package), and check out the directory build/codegen. The > NewProxyConnection is much more comprehensible when you look at its > source rather than the source of the code generator. > > smiles, > Steve > > > On Jan 31, 2009, at 4:03 PM, dukehoops wrote: > >> >> Howdy, >> >> Thanks for a prompt response! So, if by the time >> NewProxyConnection.setReadyOnly() is executed a Connection has >> already been >> checked out then please help me clarify the following: >> >> - When NewProxyConnection is first instantiated a Connection is *not* >> checked out from the pool, correct? >> >> - I am assuming that calling certain methods of NewProxyConnection >> will NOT >> trigger acquisition of a Connection from the pool (hence the point >> of this >> proxy), while calling other will, correct? >> >> - I am having a bit of difficulty deciphering the codegen code in >> JdbcProxyGenerator.java - could you please point to an example of: a) >> NewProxyConnection method that will not force acquisition of >> connection, and >> b) one that will. >> >> Here's my underlying problem: I have service methods that are >> annotated with >> @Transactional that execute with 100% cache hit rate and do not go >> to DB at >> all. Yet, for some reason, a connection is still checked out/in from/ >> to c3p0 >> pool on every invocation. Since checkout/in methods are synchronized >> they >> become hot spots under higher loads (50+ concurrent Tomcat threads) >> and >> result in HTTP threads being blocked. I would like to avoid connection >> check-out calls in this case. >> >> I am assuming c3p0 is designed to delay checking out of a Connection >> until >> some JDBC traffic is about to be sent - so that a connection is NOT >> acquired >> merely because HibernateTransactionManager asks for one (instead >> manager >> gets a proxy). >> >> thanks. >> >> -nikita >> >> >> >> Steve Waldman wrote: >>> >>> Hi, >>> >>> The code you're looking at is a code generator. All that happens on >>> setReadOnly() is that a flag gets set on the internal pooled >>> Connection. The concrete Connection has already been checked out and >>> is wrapped in your NewProxyConnection. >>> >>> smiles, >>> Steve >>> >> >> ----- >> ---------------- >> Nikita Tovstoles >> vside.com >> ---------------- >> >> -- >> View this message in context: >> http://www.nabble.com/NewProxyConnection.setReadOnly-actually-acquires-connection--tp21759481p21768236.html >> Sent from the c3p0 - users mailing list archive at Nabble.com. >> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by: >> SourcForge Community >> SourceForge wants to tell your story. >> http://p.sf.net/sfu/sf-spreadtheword >> _______________________________________________ >> c3p0-users mailing list >> c3p...@li... >> https://lists.sourceforge.net/lists/listinfo/c3p0-users > > ~oo~ > Steve Waldman > swa...@mc... > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > c3p0-users mailing list > c3p...@li... > https://lists.sourceforge.net/lists/listinfo/c3p0-users > > ----- ---------------- Nikita Tovstoles vside.com ---------------- -- View this message in context: http://www.nabble.com/NewProxyConnection.setReadOnly-actually-acquires-connection--tp21759481p21770986.html Sent from the c3p0 - users mailing list archive at Nabble.com. |
From: dukehoops <ni...@do...> - 2009-02-01 22:31:06
|
For those interested, please see related Spring forum post here: http://forum.springsource.org/showthread.php?p=224490 -nikita ----- ---------------- Nikita Tovstoles vside.com ---------------- -- View this message in context: http://www.nabble.com/NewProxyConnection.setReadOnly-actually-acquires-connection--tp21759481p21781082.html Sent from the c3p0 - users mailing list archive at Nabble.com. |