`

非常有用的proxool属性详细解说

 
阅读更多
Proxool连接池是sourceforge下的一个开源项目,这个项目提供一个健壮、易用的连接池,最为关键的是这个连接池提供监控的功能,方便易用,便于发现连接泄漏的情况。开源项目地址是: http://proxool.sourceforge.net/

Proxool提供了很多配置属性,其属性意义如下,当然还是建议直接查看官方文档http://proxool.sourceforge.net/properties.html:

simultaneous-build-throttle:
This is the maximum number of connections we can be building at any one time. That is, the number of new connections that have been requested but aren’t yet available for use. Because connections can be built using more than one thread (for instance, when they are built on demand) and it takes a finite time between deciding to build the connection and it becoming available we need some way of ensuring that a lot of threads don’t all decide to build a connection at once. (We could solve this in a smarter way – and indeed we will one day) Default is 10.
是指在任一时刻,可以(同时)建立的最大连接数,也就是说,就是已经请求的、但还没可用的新连接数量。因为连接可以用多线程建立,从决定要建立连接到连接 可用是需要一定时间的,所以我们需要一些方式来避免大量的线程想同时建立连接。(我们本应该找一个更聪明的方式来解决这个问题,总有一天我们会找到的)默 认值是10
当我使用140个用户,进行压力测试时,发现偶尔,会有多于10个要求同时建立连接的请求,当请求数量超过限定的数值时,会出现连接失败的情况。
因此结论就是,当数据库并发连接可能会比较高的应用,这个值应该适当的设大一点。
如果并发请求很高,可能出现的bug为

Caused by: java.sql.SQLException: We are already in the process of making 11 connections and the number of simultaneous builds has been throttled to 10

maximum-active-time:
If the housekeeper comes across a thread that has been active for longer than this then it will kill it. So make sure you set this to a number bigger than your slowest expected response! Default is 5 minutes.
如果一个线程活动时间超过这个数值,线程会被杀死。所以要确保这个数值设置得比最慢的响应时间长。默认是5分钟。守护进程会把连接池中多余的可用线程(未 用的、超过这个时间的)杀死,最终保留的连接数量就是minimum-connection-count规定的数量。守护进程会根据house- keeping-sleep-time参数设置的时间隔定时检查。

maximum-connection-lifetime:
The maximum amount of time that a connection exists for before it is killed (milliseconds). Default is 4 hours.
指一个连接最大的存活时间(毫秒为单位),超过这个时间,连接会被杀死。默认值是4小时。

overload-without-refusal-lifetime:
This helps us determine the pool status. If we have refused a connection within this threshold (milliseconds) then we are overloaded. Default is 60 seconds.
这个参数帮助我们确定连接池的状态,如果在这个时间阀值内(单位为毫秒)拒绝了一个连接,就认为是过载了。默认值是60。

alias:数据源的别名

driver-url:url连接串,须确定用户名和密码

driver-class:驱动名

username:用户名(proxool没有使用,但是不能没有)

password:密码(proxool没有使用,但是不能没有)

maximum-new-connections:没有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受

test-before-use:

If you set this to true then each connection is tested (with whatever is defined in house-keeping-test-sql) before being served. If a connection fails then it is discarded and another one is picked. If all connections fail a new one is built. If that one fails then you get an SQLException saying so.

如果连接池在运行当中,出现网络或者数据库故障而无法连接到数据库,在恢复正常以后,由于连接是在连接池中持久保存的,会出现连接仍然不可用的情况,这时连接池里的连接实际上都是坏连接,怎么让连接池可以自动重连清除这些坏连接呢? 只要配置了test-before-use 参数,即每次取出连接都检查连接是否可用,就可以做到让连接池实现在故障恢复后自动重连接

需要注意一点,对于Mysql数据库还必须在连接参数里加上autoReconnect=true 参数,否则即使打开了test-before-use 参数,仍然不能重连接!

fatal-sql-exception:

它是一个逗号分割的信息片段.当一个SQL异常发生时,他的异常信息将与这个信息片段进行比较.如果在片段中存在,那么这个异常将被认为是个致命错 误(Fatal SQL Exception ).这种情况下,数据库连接将要被放弃.无论发生什么,这个异常将会被重掷以提供给消费者.用户最好自己配置一个不同的异常来抛出.

fatal-sql-exception-wrapper-class:

正如上面所说,你最好配置一个不同的异常来重掷.利用这个属性,用户可以包装SQLException,使他变成另外一个异常.这个异常或者继承 SQLException或者继承字RuntimeException.proxool自带了2个实 现:’org.logicalcobwebs.proxool.FatalSQLException’ 和’org.logicalcobwebs.proxool.FatalRuntimeException’ .后者更合适.

house-keeping-sleep-time:

proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒)

house keeper 保留线程处于睡眠状态的最长时间,house keeper 的职责就是检查各个连接的状态,并判断是否需要销毁或者创建.

house-keeping-test-sql:

如果发现了空闲的数据库连接.house keeper 将会用这个语句来测试.这个语句最好非常快的被执行.如果没有定义,测试过程将会被忽略。

一般mysql可用select SYSDATE ,Oracle可用 select sysdate from dual 或者 select 1 from dual

injectable-connection-interface: 允许proxool实现被代理的connection对象的方法.

injectable-statement-interface: 允许proxool实现被代理的Statement 对象方法.

injectable-prepared-statement-interface: 允许proxool实现被代理的PreparedStatement 对象方法.

injectable-callable-statement-interface: 允许proxool实现被代理的CallableStatement 对象方法.

jmx: 略

jmx-agent-id: 略

jndi-name: 数据源的名称

maximum-active-time: 如果housekeeper 检测到某个线程的活动时间大于这个数值.它将会杀掉这个线程.所以确认一下你的服务器的带宽.然后定一个合适的值.默认是5分钟.

maximum-connection-count:

The maximum number of connections to the database. Default is 15.

最大的数据库连接数.默认是15

minimum-connection-count: 最小的数据库连接数,默认是5

prototype-count:

If there are fewer than this number of connections available then we will build some more (assuming the maximum-connection-count is not exceeded). For example. Of we have 3 active connections and 2 available, but our prototype-count is 4 then it will attempt to build another 2. This differs from minimum-connection-count because it takes into account the number of active connections. minimum-connection-count is absolute and doesn’t care how many are in use. prototype-count is the number of spare connections it strives to keep over and above the ones that are currently active. Default is 0.

连接池中可用的连接数量.如果当前的连接池中的连接少于这个数值.新的连接将被建立(假设没有超过最大可用数).例如.我们有3个活动连接2个可用 连接,而我们的prototype-count是4,那么数据库连接池将试图建立另外2个连接.这和 minimum-connection-count不同. minimum-connection-count把活动的连接也计算在内.prototype-count 是spare connections 的数量.

recently-started-threshold: 略

statistics: 连接池使用状况统计。 参数“10s,1m,1d”

statistics-log-level: 日志统计跟踪类型。 参数“ERROR”或 “INFO”

test-after-use: 略

trace: 如果为true,那么每个被执行的SQL语句将会在执行期被log记录(DEBUG LEVEL).你也可以注册一个ConnectionListener (参看ProxoolFacade)得到这些信息.

verbose: 详细信息设置。 参数 bool 值
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics