-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Josh,
On 10/30/2009 9:54 AM, Josh Gooding wrote: > While I asked a question about it on the sun forums and got slammed > for a class I wrote and posted about why a ConnectionPool would ever have to > implement ServletContextListener. basically I was told to write in > accordance with what the API's contract is,/ not implementation specific > behaviors. Heh. Obviously, someone hasn't worked in the real world. Did he realize that writing to the contract in this case could potentially bring-down the database server? > Thank goodness I archive the tomcat udev / user listing in my Gmail. You can always search the archives on markmail, too. There's no need to keep your own archive. > The main problem I was having was similar to what he was. I was able to > solve my problem by the following: > > maxActive="-1" maxIdle="5" maxWait="15" > removeAbandoned="true" removeAbandonedTimeout="15" > testWhileIdle="false" timeBetweenEvictionRunsMillis="900"/> 900ms is a /very/ short time for an eviction run. Given that you have a 15-second timeout, I would probably make your eviction runs somewhere in that range rather than in the sub-second range. Do you really want your DataSource waking up every second to check all the connections? > I changed up 4 parameters in the context.xml file. maxWait, > removeAbandonedTimeout, testWhileIdle, and timeBetweenEvictionRunsMIllis. > The problem was despite me closing the rs's in the program, MySQL & Tomcat > was still seeing the connections as active and would keep them open. Well, you have to close all your resources, not just ResultSets. Closing a ResultSet does not close the connection (nor does it return it to the pool, which may have been your whole problem). > I started by trying to tweak the wait timeout settings in the my.ini file, > but that really caused some jams especially if the connections would > timeout, then for some reason go to become active again, Tomcat would throw > me an error, so changing the settings on MySQL was not the answer. You really ought to use validationQuery="/* ping */ SELECT 1" as well. Any connection that has been closed while sitting in the pool will be re-checked before it's given-out to the caller. That means that you shouldn't get connection exceptions being thrown when this kind of thing happens. > The > problem was with how Tomcat was handling the time frame for recycling > connections. I cut the time that tomcat held on to the closed connections > and the problem remarkably went away. I could also monitor this from the > MySQL Administrator panel in real time when I ran heavy load queries to the > DB. Now every 15 seconds after a close, the connection is returned to the > pool. That seems to be about perfect, just long enough to run gc() and > continue on. Heh. I highly recommend reviewing you code: abandoned expirations and evictions can get you by in a pinch, but it's no way to live long-term. Fix your resource leaks and your server(s) will thank you by increasing their throughput. Good luck, - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrrBy8ACgkQ9CaO5/Lv0PBsHwCfUxbNB8s7haZMI9ZZwf3fhBtf NqoAoMPsCTZiH5NgB69d/iOk3BVcakkf =TfJV -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org