R2链接池1.7版与proxool比较

来源:互联网 发布:linux 硬盘的dd命令 编辑:程序博客网 时间:2024/06/05 11:10

比较方法:建立两个jsp页面,分别使用r2和proxool链接池读取数据库,执行select 1,两链接池均配置最大50个线程;分别使用jmeter用50个并发读取r2的jsp页面和proxool的jsp,得到如下数据:



从测试结果可以看出在最大链接数范围内r2的平均执行效率是proxool的10倍。错误率r2为0,但proxool较高报错率较高,后台报错误:

严重: Servlet.service() for servlet jsp threw exception

java.sql.SQLException: Couldn't get connection because we are at maximum connection count (50/50) and there are none available


下图为proxool配置成500个最大链接数时的结果:

(平均响应仍为50个最大链接数的R2的十倍,仍有少量的错误)



经过比较,R2在性能和稳定性上都要高于proxool。


jsp页面代码:

r2.jsp

<%

Connection conn = R2PoolUtil.getStaticPool().getConnection();

try{

PreparedStatement pstmt = conn.prepareStatement("select 1");

ResultSet rs = pstmt.executeQuery();

while(rs.next()){

%><%=rs.getInt(1)%><%

}

rs.close();

pstmt.close();

}catch(Exception e){

}finally{

try{

if(conn!=null)conn.close();

}catch(Exception e){

}

}

%>


proxool.jsp

<%!

private ProxoolDataSource dataSource =null;


private Connection getConnection()throws Exception{

if(dataSource==null){

dataSource =new ProxoolDataSource();

dataSource.setAlias("proxool1");

dataSource.setDriver("com.mysql.jdbc.Driver");

dataSource.setDriverUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false");

dataSource.setUser("root");

dataSource.setPassword("aaaaa");

dataSource.setSimultaneousBuildThrottle(500);

dataSource.setMaximumConnectionCount(500);

dataSource.setMinimumConnectionCount(500);

dataSource.setDelegateProperties("user=root,password=123qwe");

dataSource.setTestAfterUse(true);

}

return dataSource.getConnection();

}

%>

<%

Connection conn = getConnection();

try{

PreparedStatement pstmt = conn.prepareStatement("select 1");

ResultSet rs = pstmt.executeQuery();

while(rs.next()){

%><%=rs.getInt(1)%><%

}

rs.close();

pstmt.close();

}catch(Exception e){

}finally{

try{

if(conn!=null)conn.close();

}catch(Exception e){

}

}

%>


proxool.jsp在访问一次页面,初始化dataSource后启动jmeter测试。
原创粉丝点击