简体   繁体   English

Hibernate C3P0 设置性能问题

[英]Hibernate C3P0 settings performance issues

Since we have added C3P0 connection pooling to the application performance became slower.由于我们向应用程序添加了 C3P0 连接池,因此性能变慢了。 It is Oracle 10g database, Hibernate 3.1.3 and C3P0 0.9.0.4.它是 Oracle 10g 数据库、Hibernate 3.1.3 和 C3P0 0.9.0.4。 WebSphere application server. WebSphere 应用程序服务器。 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>
  1. c3p0-0.9.0.x is very, very old. c3p0-0.9.0.x 非常非常古老。 Please update to 0.9.2.1 or the latest 0.9.5 prerelease.请更新到 0.9.2.1 或最新的 0.9.5 预发布版。 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 .较新的版本是直接替换,您只需要更新您的依赖项,或者如果您手动包含 jar 文件,请包含更新的 c3p0 jar 以及您会发现包含在二进制文件中的 mchange-commons-java jar 文件分布

  2. 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.您的性能问题很可能源于将 max_statements 设置为 50。对于可能有多达 50 个活动连接的池来说,这太小了。 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.我建议您从将 max_statements 设置为 0 开始,然后看看情况如何。 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?]然后,为了通过语句缓存获得更好的性能,请考虑 1) 您的应用程序以持续方式使用了多少不同的 PreparedStatements(即不仅在初始化时使用一次,而是在应用程序生命周期中重复使用)和 2) 将 hibernate.c3p0.maxStatementsPerConnection 设置为大约该值[或将全局 hibernate.c3p0.max_statements 设置为(该值 * expected_pool_size),但为什么不使用更易于理解的 maxStatementsPerConnection?]

如果它是一个非常繁忙的应用程序,您可能需要增加 c3p0.numHelperThreads 的设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM