Since we have added C3P0 connection pooling to the application performance became slower. It is Oracle 10g database, Hibernate 3.1.3 and C3P0 0.9.0.4. WebSphere application server. I am very new to this things, so I don’t understand everything. Is this configuration could slow down the app performance? What should I change if so?
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <property name="hibernate.c3p0.min_size">1</property> <property name="hibernate.c3p0.max_size">50</property> <property name="hibernate.c3p0.timeout">5000</property> <property name="hibernate.c3p0.max_statements">50</property> <property name="hibernate.c3p0.idle_test_period">600</property> <property name="hibernate.c3p0.preferredTestQuery">select 1 from dual;</property>
Advertisement
Answer
c3p0-0.9.0.x is very, very old. Please update to 0.9.2.1 or the latest 0.9.5 prerelease. newer versions are drop-in replacements, you just need to update your dependencies, or if you including jar files manually, include the more recent c3p0 jar as well as the mchange-commons-java jar file that you’ll find included with the binary distribution.
Your performance issue most likely stems from setting max_statements to 50. That’s way too small for a pool that might have up to 50 active Connections. It means that on average each Connection caches a single Statement when the pool is at capacity, and forces the Statement cache to churn frequently. I’d recommend you start with max_statements set to 0, and see how that goes. Then, for better performance via Statement caching, think about 1) how many distinct PreparedStatements your application uses in an ongoing way (ie not just once on initialization, but repeatedly over the application lifetime) and 2) set hibernate.c3p0.maxStatementsPerConnection to approximately that value [or set global hibernate.c3p0.max_statements to (that value * expected_pool_size), but why not just use the easier-to-understand maxStatementsPerConnection?]