注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

流星永恒的博客

JSF,Facelets,Rich(Prime)Faces,和java的笔记

 
 
 

日志

 
 

JBoss AS 7 Performance tuning(2)  

2012-11-12 23:18:56|  分类: server |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
 

Tuning the database connection pool

Original link: http://www.mastertheboss.com/jboss-performance/jboss-as-7-performance-tuning

Establishing a JDBC connection with a DBMS can be quite slow. If your application requires database connections that are repeatedly opened and closed; this can become a significant performance issue. The connection pools in JBoss AS datasources offer an efficient solution to this problem.
What is important to stress out is that, when a client closes a connection from a data source, the connection is returned to the pool and becomes available for other clients; therefore, the connection itself is not closed. The cost of opening and closing pooled connections can be measured in terms of nanoseconds, so it's irrelevant in terms of performance.
In the following example, we are enhancing the datasource configuration exposed in Chapter 3, Configuring Enterprise Services with some connection pool configuration:

<datasource jndi-name="MySqlDS" pool-name="MySqlDS_Pool"      enabled="true" jta="true" use-java-context="true" use-ccm="true">      <connection-url>          jdbc:mysql://localhost:3306/MyDB      </connection-url>      <driver>mysql</driver>      <pool>          <min-pool-size>10</min-pool-size>          <max-pool-size>30</max-pool-size>          <prefill>true</prefill>      </pool>      <timeout>          <blocking-timeout-millis>30000</blocking-timeout-millis>          <idle-timeout-minutes>5</idle-timeout-minutes>      </timeout>  </datasource>
Here, we configured an initial pool capacity of ten connections which can grow up to thirty. As you can see from the following MySQL administration console, when you set the pre-fill element to true, the application server attempts to pre-fill the connection pool at the start-up. This can produce a performance hit, especially if your connections are costly to acquire.
JBoss AS 7 Performance tuning(2) - yyq2007aa - 流星永恒的博客
 If the application server is not able to serve any more connections because they are all in use, then it will wait up to the blocking-timeout-millis before throwing an exception to the client.
At the same time, connections which have been idle for some minutes over the parameter idle-timeout-minutes, they are forced to return to the pool.

Adjusting the pool size

To determine the proper sizing, you need to monitor your connection usage. This can be done in several ways. If you have access to the Command Line Interface you can monitor the runtime properties of your datasource. Here’s a sample output of our example application delivered in chapter 4:

 

[standalone@localhost:9999 /]/subsystem=datasources/data-source="java:/MySqlDS":read-resource(include-runtime=true)
{
"outcome" => "success",
"result" => {
"ActiveCount" => "10",
"AvailableCount" => "29",
"AverageBlockingTime" => "0",
"AverageCreationTime" => "56",
"CreatedCount" => "10",
"DestroyedCount" => "0",
"MaxCreationTime" => "320",
"MaxUsedCount" => "5",
"MaxWaitCount" => "0",
"MaxWaitTime" => "1",
. . . .
}
}


The output of this command is quite verbose however the most interesting attributes are located at the beginning of the output: in particular the ActiveCount attribute which displays the amount of connections which are currently active and the MaxUsedCountwhich is the peak of connections used by the application.


Beware: if you are prefilling the pool, as shown in the earlier section, these connection will all result Active. This could be misleading and lead you to assume they are actually busy.  
If you are not able to use the CLI or simply you want to make good use of your DBA certification there are some valid alternative as well: the first and most obvious is monitoring the database sessions. The following table shows some useful commands, which can be used to keep track of active database connections on different databases:

DatabaseCommand / Table
OracleQuery the V$SESSION view
MySQLUse the command SHOW FULL PROCESSLIST
Postgre-SQLQuery the PG_STAT_ACTIVITY table

Another option is using a tool like P6Spy which acts as a JDBC proxy driver. (I've blogged an article about it here).
Once you have found the peak of connection used by your application, just set the maximum at least 25-30% higher. Don't be concerned about setting the maximum too high, because if you don't need that many connections, the pool will shrink automatically, provided that you have set idle-timeout-minutes.
On the other hand, your server logs are still an invaluable help to check if your pool is running in trouble. For example, if you start seeing this exception in your server logs, there is a strong clue that you need to look at your connection pooling:

21:57:57,781 ERROR [stderr] (http-executor-threads - 7) Caused by: javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms]) 
21:57:57,782 ERROR [stderr] (http-executor-threads - 7)         at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnec
  评论这张
 
阅读(851)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017