问题描述
听取了大家的建议,于前天(2008-06-28)替换掉了以前tomcat自带的DBCP连接池,改为了C3P0,配置如下:<property name="c3p0.min_size">10</property><!--连接池的最小连接数--><property name="c3p0.max_size">50</property><!--最大连接数--><property name="c3p0.timeout">100</property><!--连接超时时间--><!--每隔100秒检测连接是否可正常使用 --><property name="c3p0.idle_test_period">100</property><!--当池中的连接耗尽的时候,一次性增加的连接数量,默认为3--><property name="hibernate.c3p0.acquire_increment">3</property><!--statemnets缓存大小--><property name="c3p0.max_statements">150</property>原来的DBCP配置<Resource maxActive="200"maxIdle="60"maxWait="-1"/>今天(2008-06-30)访问量达到了200,并且某一瞬间并发查询达到了150左右。出现了用DBCP时未出现过的问题:瞬间打开页面很慢,并有部分用户超时掉线,我估计是我C3P0设置的问题。请大家给予回答!问题补充:引用
解决方案
看下这个官方文档里面写的Basic Pool Configuration c3p0 Connection pools are very easy to configure via the following basic parameters: acquireIncrement initialPoolSize maxPoolSize maxIdleTime minPoolSize initialPoolSize, minPoolSize, maxPoolSize define the number of Connections that will be pooled. Please ensure that minPoolSize <= maxPoolSize. Unreasonable values of initialPoolSize will be ignored, and minPoolSize will be used instead. Within the range between minPoolSize and maxPoolSize, the number of Connections in a pool varies according to usage patterns. The number of Connections increases whenever a Connection is requested by a user, no Connections are available, and the pool has not yet reached maxPoolSize in the number of Connections managed. Since Connection acquisition is very slow, it is almost always useful to increase the number of Connections eagerly, in batches, rather than forcing each client to wait for a new Connection to provoke a single acquisition when the load is increasing. acquireIncrement determines how many Connections a c3p0 pool will attempt to acquire when the pool has run out of Connections. (Regardless of acquireIncrement, the pool will never allow maxPoolSize to be exceeded.) The number of Connections in a pool decreases whenever a pool tests a Connection and finds it to be broken (see Configuring Connection Testing below), or when a Connection is expired by the pool after sitting idle for a period of time, or for being too old (See Managing Pool Size and Connection Age.)
解决方案二:
你可仔细看一下这一段就明白了
解决方案三:
是不是最大连接数50太少了,你说一瞬间打到了150并发<property name="c3p0.max_size">50</property><!--最大连接数-->你原来dbcp的maxActive是200啊