听取了大家的建议,于前天(2008-06-28)替换掉了以前tomcat自带的DBCP连接池,改为了C3P0,配置如
下:
[code]
10<!--连接池的最小连接数-->
50<!--最大连接数-->
100<!--连接超时时间-->
<!--每隔100秒检测连接是否可正常使用 -->
100
<!--当池中的连接耗尽的时候,一次性增加的连接数量,默认为3-->
3
<!--statemnets缓存大小-->
150
[/code]
原来的DBCP配置
[code]
maxActive="200"
maxIdle="60"
maxWait="-1"
/>
[/code]
今天(2008-06-30)访问量达到了200,并且某一瞬间并发查询达到了150左右。出现了用DBCP时未出现过的
问题:瞬间打开页面很慢,并有部分用户超时掉线,我估计是我C3P0设置的问题。请大家
给予回答!
[b]问题补充:[/b]
[quote]
是不是最大连接数50太少了,你说一瞬间打到了150并发
[/quote]
我的理解是:c3p0.max_size达到最大后会自动新建线程,对吗?
看下这个官方文档里面写的
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. ([color=red]Regardless of acquireIncrement, the pool will never allow maxPoolSize to be exceeded.[/color])
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并发
50<!--最大连接数-->
你原来dbcp的maxActive是200啊
你可仔细看一下这一段就明白了