JBOSS数据库连接池配置及优化

一 JBOSS数据库连接池配置项
  数据源JNDI名称 jndi-name jdbc/tam
  数据库用户名称 user-name tamadmin
  数据库密码 password tamadmin
  驱动名称 driver-class com.edb.Driver
  JDBC连接串 connection-url jdbc:edb://10.6.159.154:5445/edb
  JDBC连接属性 connection-property 可以设置jdbc全局变量大小,如fetch、      tcpSndBuf等
  连接池最小空闲 min-pool-size 5
  连接池最大使用连接数量 max-pool-size 20
  最小逐出时间 idle-timeout-minutes 3
  测试有效用的SQL Query check-valid-connection-sql select 1
  连接初始化SQL new-connection-sql 暂不需要
  Statement缓存大小 prepared-statement-cache-size 推荐使用,数值大小和机器内存大小有关
  获取连接最大等待时间 blocking-time-millis 90000
  FatalException处理 exception-sorter-class-name 暂不需要
  调用原生方法检测连接是否有效 valid-connection-checker-class-name 不知道EDB  是否有相应的class,暂不需要
  检测未关闭Statement track-statements true
  类型映射配置 type-mapping PostgreSQL
  事务隔离级别 transaction-isolation TRANSACTION_READ_UNCOMMITTED
                                                   TRANSACTION_READ_COMMITTED
                                                   TRANSACTION_REPEATABLE_READ
                                                   TRANSACTION_SERIALIZABLE
                                                   TRANSACTION_NONE
                                                   未设置则为数据库提供的事务隔离级别
二 数据库自动重连
<!--
an sql statement that is executed before it is checked out from the pool (see <validate-on-match>) to make sure it is still valid. If the sql fails, the connection is closed and new ones created. Also it will be used by <background-validation>
-->
<check-valid-connection-sql>select 1</check-valid-connection-sql>
  
  如果不配置此配置项,则在数据库连接出现问题(如数据库down或者网络异常),TAM不能正常使用。数据库恢复正常后TAM仍不能正常使用(无法登陆),必须重新启动TAM。
  配置参数在数据库恢复后,TAM与数据库会自动重新建立连接,TAM能正常使用。
三 性能优化
1)释放空闲连接
<!--
indicates the maximum time a connection may be idle before being closed. Setting to 0 disables it.  Default is 15 minutes.
-->
<idle-timeout-minutes>3</idle-timeout-minutes>

  每idle-timeout-minutes/2分钟扫描一次空闲的连接,如果连接空闲时间超过idle-timeout-minutes则释放掉。
2)SQL执行优化
<!--
the number of prepared statements per connection to be kept open and reused in subsequent requests. They are stored in a LRU cache. The default is 0 (zero), meaning no cache.
-->
<prepared-statement-cache-size>20</prepared-statement-cache-size>
  
  在使用绑定变量的SQL语句时,首先会创建一个PreparedStatement对象,用于发送使用绑定变量的SQL语句到数据库中。SQL语句能够被预编译,并且存储到一个PreparedStatement对象中。这个对象,可以在多次执行这个SQL语句的块景中被高效的使用。
  PreparedStatementCache即用于保存与数据库交互的prepareStatement对象。PreparedStatementCache使用了一个本地缓存的LRU链表来减少SQL的预编译,减少SQL的预编译,意味着可以减少一次网络的交互和数据库的解析(有可能在session cursor cache hits中命中,也可能是share pool中命中),这对应用的DAO响应延时是很大的提升。每次DAO响应可能减少0.6-0.8ms的执行时间。
  但是由于cache需要占用内存,所以具体数值的大小需要根据应用和服务器环境具体分析。
四 参考资料
http://www.dbafree.net/?p=287
http://www.dbafree.net/?p=458
http://code.alibabatech.com/wiki/pages/viewpage.action?pageId=6947005

猜你喜欢

转载自xhlmy.iteye.com/blog/1840181