通过Proxool辅助数据库优化

1. 首先在Tomcat下的context.xml里配置数据源
       <Resource name="jdbc/b2b" auth="Container" type="javax.sql.DataSource"
        factory="org.logicalcobwebs.proxool.ProxoolDataSource" proxool.alias="zyw_com"
                proxool.maximum-connection-count="3000" proxool.minimum-connection-count="3" 
                proxool.maxinum-connection-lifetime="18000000" proxool.maximum-active-time="60000"
                proxool.house-keeping-sleep-time="30000"    proxool.simultaneous-build-throttle="40"
             proxool.trace="true"  user="zyw.com" password="zyw.lizz" delegateProperties="foo=bar"
             proxool.prototype-count="10"
             proxool.statistics-log-level="INFO" proxool.statistics="10s"
                proxool.driver-url="jdbc:oracle:thin:@192.168.1.99:1599:zyw"
          proxool.driver-class="oracle.jdbc.driver.OracleDriver"  />
2.然后把这三个包(proxool-0.9.1.jar,proxool-cglib.jar,commons-logging.jar)分别放在tomcat/common/lib下和工程下的lib目录;
3.配置log4j.properties
log4j.logger.org.logicalcobwebs.proxool=DEBUG, proxool   
  
log4j.appender.proxool=org.apache.log4j.DailyRollingFileAppender   
log4j.appender.proxool.File=${catalina.home}/logs/proxool.log   
log4j.appender.proxool.layout=org.apache.log4j.PatternLayout   
log4j.appender.proxool.layout.ConversionPattern=%d{DATE} [%-5p] %c {%F:%L} - %m%n   
log4j.appender.proxool.DatePattern='.'yyyy-MM-dd 
 
4.然后就可以在控制台和日志文件输出proxool日志内容,日志里语句会自动把参数填充进去,并在最后输出该语句执行多少毫秒;
这个对于数据库优化非常有帮助
5.隔一天把服务器上的proxool.log载下来,写个程序把执行时间超过3000毫秒的SQL语句过滤出来,然后进行SQL优化,这样相信可以减轻不少服务器负载

你可能感兴趣的:(proxool)