Proxool配置详解

from: http://javathinker.blog.ccidnet.com/blog-htm-itemid-10837556-uid-36384-do-showone-type-blog.html

 

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 值  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值