虫二的专栏~~在路上~~~

河流之所以能够到达目的地,是因为它懂得怎样避开障碍。走过路过,别忘留言支持呀。...

Druid、C3P0、Tomcat Pool的性能测试与选型

    数据库连接池是每个使用数据库项目需要选择的,但是现在有C3P0、Druid、Tomcat Jdbc Pool,三种类型。为了测试一下每种连接池的性能,写了一个小程序,对数据库进行测试。

     C3P0      c3p0-0.9.1.2.jar

     Druid      druid-1.0.11.jar

     Tomcat Jdbc Pool      commons-pool-1.2.jar

     为了保证测试的公正性,配置信息尽量保持一致(个别数据源的个别配置不太一样,就单独设置了一下)。

package test.dbpool.test2;

public class DbConfigParam {
	// 数据库驱动名称
	public static String driver = "com.mysql.jdbc.Driver";
	// 数据库连接地址
	public static String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/mysql?useUnicode=true&characterEncoding=UTF8&connectTimeout=1000&socketTimeout=3000";
	// 数据库用户名
	public static String user = "root";
	// 数据库密码
	public static String passwd = "";
	// 连接池初始化大小
	public static int initialSize = 5;
	// 连接池最小空闲
	public static int minPoolSize = 10;
	// 连接池最大连接数量
	public static int maxPoolSize = 50;
	// 最小逐出时间,100秒
	public static int maxIdleTime = 100000;
	// 连接失败重试次数
	public static int retryAttempts = 10;
	// 当连接池连接耗尽时获取连接数
	public static int acquireIncrement = 5;

	private DbConfigParam() {
	}

}


     因为需要从各个数据源进行测试,所以编写数据源测试接口。

package test.dbpool.test2;

import java.sql.SQLException;

import javax.sql.DataSource;

import test.dbpool.test2.impl.TestDAO;

public interface ITestDataSource {
	/**
	 * 数据源测试
	 * 
	 * @param testDAO
	 * @param ds
	 * @param count
	 * @throws SQLException
	 * @throws InterruptedException
	 */
	public long queryDs(TestDAO testDAO, DataSource ds, int count) throws SQLException, InterruptedException;
}

        编写第一个测试实现

package test.dbpool.test2.impl;

import java.sql.SQLException;

import javax.sql.DataSource;

import test.dbpool.test2.ITestDataSource;

public class TestDataSource implements ITestDataSource {
	/**
	 * DS测试
	 * 
	 * @param testDAO
	 * @param ds
	 * @param count
	 * @throws SQLException
	 */
	public long queryDs(TestDAO testDAO, DataSource ds, int count) throws SQLException {
		// [预热数据库连接池] 查询10次以初始化连接池
		for (int i = 0; i < 10; i++) {
			testDAO.query(ds.getConnection());
		}
		// 开始时间
		long startMillis = System.currentTimeMillis();
		// 循环查询
		for (int i = 0; i < count; i++) {
			testDAO.query(ds.getConnection());
		}
		// 结束时间
		long endMillis = System.currentTimeMillis();
		// 输出结束时间
		long runMillis = endMillis - startMillis;
		return runMillis;
	}
}

    好了,测试用例编写好了,测试的查询SQL也编写一下,从字面上可以看到每次查询mysql数据库中的一条记录,遍历一遍然后关闭。

package test.dbpool.test2.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestDAO {

	public void query(Connection conn) throws SQLException {
		if (conn != null) {
			Statement statement = conn.createStatement();
			ResultSet rs = statement.executeQuery("select * from user limit 1,5");
			while (rs.next()) {
				String username = rs.getString(2);
				//System.out.println(username);
			}
			rs.close();
			statement.close();
			conn.close();
		}
	}

}

    下面编写数据源获取类

package test.dbpool.test2.impl;

import java.beans.PropertyVetoException;

import org.apache.tomcat.jdbc.pool.DataSource;
import org.logicalcobwebs.proxool.ProxoolDataSource;

import test.dbpool.test2.DbConfigParam;

import com.alibaba.druid.pool.DruidDataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;

public class AllDataSource {
	/**
	 * 获取c3p0数据源
	 * 
	 */
	public static ComboPooledDataSource getC3p0DataSource() {
		// 设置参数
		ComboPooledDataSource cpds = new ComboPooledDataSource();
		try {
			cpds.setDriverClass(DbConfigParam.driver);
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		}
		cpds.setJdbcUrl(DbConfigParam.jdbcUrl);
		cpds.setUser(DbConfigParam.user);
		cpds.setPassword(DbConfigParam.passwd);
		cpds.setInitialPoolSize(DbConfigParam.initialSize);
		cpds.setMinPoolSize(DbConfigParam.minPoolSize);
		cpds.setMaxPoolSize(DbConfigParam.maxPoolSize);
		cpds.setMaxIdleTime(DbConfigParam.maxIdleTime);
		cpds.setAcquireRetryAttempts(DbConfigParam.retryAttempts);
		cpds.setAcquireIncrement(DbConfigParam.acquireIncrement);
		cpds.setTestConnectionOnCheckin(false);
		cpds.setTestConnectionOnCheckout(false);
		return cpds;
	}

	/**
	 * 获取Druid数据源
	 * 
	 */
	public static DruidDataSource getDruidDataSource() {
		DruidDataSource dds = new DruidDataSource();
		dds.setUsername(DbConfigParam.user);
		dds.setUrl(DbConfigParam.jdbcUrl);
		dds.setPassword(DbConfigParam.passwd);
		dds.setDriverClassName(DbConfigParam.driver);
		dds.setInitialSize(DbConfigParam.initialSize);
		dds.setMaxActive(DbConfigParam.maxPoolSize);
		dds.setMaxWait(DbConfigParam.maxIdleTime);
		dds.setTestWhileIdle(false);
		dds.setTestOnReturn(false);
		dds.setTestOnBorrow(false);
		return dds;
	}

	/**
	 * 获取Proxool数据源
	 * 
	 */
	public static ProxoolDataSource getProxoolDataSource() {
		ProxoolDataSource pds = new ProxoolDataSource();
		pds.setAlias("mysql");
		pds.setUser(DbConfigParam.user);
		pds.setPassword(DbConfigParam.passwd);
		pds.setDriverUrl(DbConfigParam.jdbcUrl);
		pds.setDriver(DbConfigParam.driver);
		pds.setMaximumActiveTime(DbConfigParam.maxIdleTime);
		pds.setMaximumConnectionCount(DbConfigParam.maxPoolSize);
		pds.setMinimumConnectionCount(DbConfigParam.initialSize);
		pds.setPrototypeCount(DbConfigParam.minPoolSize);
		pds.setTestBeforeUse(false);
		pds.setTestAfterUse(false);
		return pds;
	}

	/**
	 * 获取Apache tomcat jdbc pool数据源
	 * 
	 */
	public static DataSource getTomcatDataSource() {
		DataSource ds = new DataSource();
		ds.setUrl(DbConfigParam.jdbcUrl);
		ds.setUsername(DbConfigParam.user);
		ds.setPassword(DbConfigParam.passwd);
		ds.setDriverClassName(DbConfigParam.driver);
		ds.setInitialSize(DbConfigParam.initialSize);
		ds.setMaxIdle(DbConfigParam.minPoolSize);
		ds.setMaxActive(DbConfigParam.maxPoolSize);
		ds.setTestWhileIdle(false);
		ds.setTestOnBorrow(false);
		ds.setTestOnConnect(false);
		ds.setTestOnReturn(false);
		return ds;
	}
}

     好了,准备工作全部做完了,写一个测试方法的入口吧。

package test.dbpool.test2;

import java.io.IOException;
import java.sql.SQLException;

import javax.sql.DataSource;

import test.dbpool.test2.impl.AllDataSource;
import test.dbpool.test2.impl.TestDAO;
import test.dbpool.test2.impl.TestDataSource;

public class TestMain {

	/**
	 * 测试方式: 每种数据源配置信息尽量相同,以求结果更加准确
	 * 每种数据源做10次、100次、500次、1000次、2000次、4000次、8000次查询操作 每种查询重复100次,查看100次执行时间的波动图
	 * 
	 * @param args
	 * @throws IOException
	 * @throws SQLException
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws IOException, SQLException, InterruptedException {
		// 准备数据源
		TestDAO testDAO = new TestDAO();
		ITestDataSource testDataSource = null;
		{
			System.out.println("===========单线程执行===============");
			testDataSource = new TestDataSource();
			batchTestRunMillis(testDAO, testDataSource);
		}
	}

	/**
	 * @param testDAO
	 * @param testDataSource
	 * @throws SQLException
	 * @throws InterruptedException
	 */
	private static void batchTestRunMillis(TestDAO testDAO, ITestDataSource testDataSource) throws SQLException,
			InterruptedException {
		// testDataSource = new TestDataSourceByThread();
		// 查询次数
		int count = 5000;
		long c3p0Millis = 0l, druidMillis = 0l, proxoolMillis = 0l, tomcatMillis = 0l;
		{// Proxool数据源
			DataSource dataSource = AllDataSource.getProxoolDataSource();
			proxoolMillis = testDataSource(testDataSource, "Proxool", dataSource, testDAO, count);
			dataSource = null;
		}
		{
			// c3p0数据源
			DataSource dataSource = AllDataSource.getC3p0DataSource();
			c3p0Millis = testDataSource(testDataSource, "C3P0", dataSource, testDAO, count);
			dataSource = null;
		}
		{// Druid数据源
			DataSource dataSource = AllDataSource.getDruidDataSource();
			druidMillis = testDataSource(testDataSource, "Druid", dataSource, testDAO, count);
			dataSource = null;
		}
		{// Tomcat Jdbc Pool数据源
			DataSource dataSource = AllDataSource.getTomcatDataSource();
			tomcatMillis = testDataSource(testDataSource, "Tomcat Jdbc Pool", dataSource, testDAO, count);
			dataSource = null;
		}

		System.out.println("统计结果:[C3P0]平均耗时" + c3p0Millis + "ms");
		System.out.println("统计结果:[Druid]平均耗时" + druidMillis + "ms");
		System.out.println("统计结果:[Proxool]平均耗时" + proxoolMillis + "ms");
		System.out.println("统计结果:[Tomcat]平均耗时" + tomcatMillis + "ms");
	}

	/**
	 * @param c3p0DataSource
	 * @param testDAO
	 * @param count
	 * @throws SQLException
	 * @throws InterruptedException
	 */
	private static long testDataSource(ITestDataSource testDataSource, String dataSourceName,
			DataSource c3p0DataSource, TestDAO testDAO, int count) throws SQLException, InterruptedException {
		System.out.println();
		System.out.println("查询次数为:" + count);
		System.out.println("==========================" + dataSourceName + " 测试开始==========================");
		// 测试c3p0
		long[] runMillis = new long[100];
		for (int i = runMillis.length - 1; i >= 0; i--) {
			runMillis[i] = testDataSource.queryDs(testDAO, c3p0DataSource, count);
			System.out.print("|" + i + "=" + runMillis[i] + "ms");
			if (i % 10 == 0) {
				System.out.println();
			}
		}
		// 开始统计平均值
		long avgMillis = 0l;
		for (int i = runMillis.length - 1; i >= 0; i--) {
			avgMillis += runMillis[i];
		}
		avgMillis = avgMillis / runMillis.length;
		System.out.println();
		System.out.println("==========================" + dataSourceName + " 测试结束==========================");
		System.out.println("平均耗时:" + avgMillis + "ms");
		return avgMillis;
	}

}


至此,测试用例全部编写完了,已经实现对多个数据源连接池进行串行测试,并对测试结果进行汇总。


===========单线程执行===============
log4j:WARN No appenders could be found for logger (com.mchange.v2.log.MLog).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
查询次数为:1000

==========================C3P0 测试开始==========================
|99=1085ms|98=972ms|97=966ms|96=977ms|95=960ms|94=911ms|93=929ms|92=959ms|91=982ms|90=950ms
|89=933ms|88=915ms|87=913ms|86=944ms|85=929ms|84=925ms|83=955ms|82=981ms|81=990ms|80=929ms
|79=905ms|78=909ms|77=931ms|76=922ms|75=936ms|74=952ms|73=914ms|72=961ms|71=921ms|70=965ms
|69=918ms|68=906ms|67=937ms|66=1053ms|65=933ms|64=970ms|63=948ms|62=932ms|61=937ms|60=929ms
|59=929ms|58=938ms|57=887ms|56=943ms|55=1000ms|54=920ms|53=955ms|52=934ms|51=925ms|50=939ms
|49=922ms|48=906ms|47=941ms|46=931ms|45=918ms|44=950ms|43=930ms|42=917ms|41=946ms|40=920ms
|39=941ms|38=930ms|37=913ms|36=904ms|35=931ms|34=938ms|33=936ms|32=903ms|31=898ms|30=982ms
|29=919ms|28=938ms|27=933ms|26=880ms|25=924ms|24=934ms|23=915ms|22=937ms|21=945ms|20=975ms
|19=994ms|18=1010ms|17=1031ms|16=935ms|15=899ms|14=931ms|13=943ms|12=930ms|11=921ms|10=928ms
|9=909ms|8=939ms|7=951ms|6=904ms|5=910ms|4=890ms|3=932ms|2=959ms|1=909ms|0=939ms

==========================C3P0 测试结束==========================
平均耗时:938ms
查询次数为:1000

==========================Druid 测试开始==========================
|99=956ms|98=897ms|97=897ms|96=901ms|95=869ms|94=874ms|93=860ms|92=889ms|91=914ms|90=869ms
|89=900ms|88=871ms|87=871ms|86=871ms|85=876ms|84=901ms|83=983ms|82=877ms|81=911ms|80=888ms
|79=890ms|78=905ms|77=928ms|76=932ms|75=921ms|74=920ms|73=893ms|72=881ms|71=879ms|70=905ms
|69=872ms|68=875ms|67=894ms|66=868ms|65=901ms|64=874ms|63=892ms|62=896ms|61=881ms|60=901ms
|59=871ms|58=903ms|57=884ms|56=888ms|55=899ms|54=933ms|53=939ms|52=966ms|51=866ms|50=887ms
|49=854ms|48=902ms|47=909ms|46=895ms|45=910ms|44=899ms|43=890ms|42=891ms|41=899ms|40=874ms
|39=890ms|38=856ms|37=885ms|36=908ms|35=889ms|34=893ms|33=893ms|32=865ms|31=898ms|30=889ms
|29=898ms|28=899ms|27=864ms|26=905ms|25=887ms|24=905ms|23=910ms|22=882ms|21=898ms|20=899ms
|19=880ms|18=895ms|17=896ms|16=883ms|15=906ms|14=893ms|13=938ms|12=898ms|11=876ms|10=873ms
|9=892ms|8=864ms|7=886ms|6=880ms|5=889ms|4=866ms|3=876ms|2=885ms|1=874ms|0=872ms

==========================Druid 测试结束==========================
平均耗时:892ms
查询次数为:1000

==========================Proxool 测试开始==========================
|99=1070ms|98=1083ms|97=986ms|96=972ms|95=980ms|94=1004ms|93=992ms|92=1026ms|91=1012ms|90=978ms
|89=1050ms|88=1133ms|87=1148ms|86=1012ms|85=981ms|84=973ms|83=1021ms|82=1054ms|81=1024ms|80=1005ms
|79=1001ms|78=979ms|77=992ms|76=997ms|75=975ms|74=992ms|73=1052ms|72=1039ms|71=988ms|70=1007ms
|69=994ms|68=1005ms|67=1021ms|66=990ms|65=973ms|64=1000ms|63=1014ms|62=968ms|61=998ms|60=1012ms
|59=1004ms|58=1130ms|57=1033ms|56=960ms|55=989ms|54=1001ms|53=969ms|52=997ms|51=979ms|50=1020ms
|49=982ms|48=1010ms|47=979ms|46=989ms|45=995ms|44=1013ms|43=997ms|42=1007ms|41=1008ms|40=965ms
|39=993ms|38=1003ms|37=981ms|36=1051ms|35=1097ms|34=1071ms|33=1035ms|32=1004ms|31=974ms|30=1096ms
|29=1136ms|28=1062ms|27=1099ms|26=1150ms|25=1128ms|24=1129ms|23=1123ms|22=1094ms|21=1112ms|20=1158ms
|19=1232ms|18=1139ms|17=1098ms|16=1149ms|15=1125ms|14=1110ms|13=1016ms|12=977ms|11=1010ms|10=960ms
|9=1001ms|8=1049ms|7=1026ms|6=1042ms|5=1046ms|4=970ms|3=1002ms|2=1069ms|1=1122ms|0=991ms

==========================Proxool 测试结束==========================
平均耗时:1031ms
查询次数为:1000

==========================Tomcat Jdbc Pool 测试开始==========================
|99=929ms|98=1035ms|97=1007ms|96=939ms|95=903ms|94=880ms|93=899ms|92=910ms|91=906ms|90=880ms
|89=924ms|88=892ms|87=926ms|86=923ms|85=910ms|84=907ms|83=876ms|82=906ms|81=893ms|80=886ms
|79=918ms|78=894ms|77=960ms|76=873ms|75=969ms|74=913ms|73=882ms|72=1003ms|71=927ms|70=946ms
|69=907ms|68=867ms|67=944ms|66=944ms|65=997ms|64=917ms|63=892ms|62=900ms|61=872ms|60=897ms
|59=903ms|58=878ms|57=910ms|56=892ms|55=916ms|54=899ms|53=903ms|52=881ms|51=897ms|50=896ms
|49=901ms|48=901ms|47=950ms|46=964ms|45=920ms|44=901ms|43=925ms|42=899ms|41=907ms|40=888ms
|39=899ms|38=903ms|37=877ms|36=895ms|35=901ms|34=878ms|33=890ms|32=892ms|31=911ms|30=931ms
|29=885ms|28=890ms|27=900ms|26=911ms|25=989ms|24=903ms|23=905ms|22=952ms|21=938ms|20=977ms
|19=906ms|18=895ms|17=910ms|16=885ms|15=904ms|14=903ms|13=908ms|12=987ms|11=897ms|10=928ms
|9=981ms|8=969ms|7=908ms|6=955ms|5=900ms|4=905ms|3=936ms|2=942ms|1=958ms|0=964ms

==========================Tomcat Jdbc Pool 测试结束==========================
平均耗时:916ms
统计结果:[C3P0]平均耗时938ms
统计结果:[Druid]平均耗时892ms
统计结果:[Proxool]平均耗时1031ms
统计结果:[Tomcat]平均耗时916ms


这个测试真的十分痛苦,需要等好久好久,而且我们实际使用过程中,数据库连接池是串行运行的,所以还是写一个并发执行的数据源测试用例比较靠谱。这里扩展一个并发测试的测试用例

TestDataSourceByThread.java
[这个卖一个关子,需要的到文章最下面的连接路径下载吧。解压缩密码也有呀,O(∩_∩)O]

重新编写一下测试入口


package test.dbpool.test2;

import java.io.IOException;
import java.sql.SQLException;

import javax.sql.DataSource;

import test.dbpool.test2.impl.AllDataSource;
import test.dbpool.test2.impl.TestDAO;
import test.dbpool.test2.impl.TestDataSource;
import test.dbpool.test2.impl.TestDataSourceByThread;

public class TestMain {

	/**
	 * 测试方式: 每种数据源配置信息尽量相同,以求结果更加准确
	 * 每种数据源做10次、100次、500次、1000次、2000次、4000次、8000次查询操作 每种查询重复100次,查看100次执行时间的波动图
	 * 
	 * @param args
	 * @throws IOException
	 * @throws SQLException
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws IOException, SQLException, InterruptedException {
		// 准备数据源
		TestDAO testDAO = new TestDAO();
		ITestDataSource testDataSource = null;
		{
			System.out.println("===========单线程执行===============");
			testDataSource = new TestDataSource();
			batchTestRunMillis(testDAO, testDataSource);
		}
		{
			System.out.println("===========多线程执行===============");
			testDataSource = new TestDataSourceByThread();
			batchTestRunMillis(testDAO, testDataSource);
		}
	}

	/**
	 * @param testDAO
	 * @param testDataSource
	 * @throws SQLException
	 * @throws InterruptedException
	 */
	private static void batchTestRunMillis(TestDAO testDAO, ITestDataSource testDataSource) throws SQLException,
			InterruptedException {
		// testDataSource = new TestDataSourceByThread();
		// 查询次数
		int count = 5000;
		long c3p0Millis = 0l, druidMillis = 0l, proxoolMillis = 0l, tomcatMillis = 0l;
		// {// Proxool数据源
		// DataSource dataSource = AllDataSource.getProxoolDataSource();
		// proxoolMillis = testDataSource(testDataSource, "Proxool", dataSource,
		// testDAO, count);
		// dataSource = null;
		// }
		{
			// c3p0数据源
			DataSource dataSource = AllDataSource.getC3p0DataSource();
			c3p0Millis = testDataSource(testDataSource, "C3P0", dataSource, testDAO, count);
			dataSource = null;
		}
		{// Druid数据源
			DataSource dataSource = AllDataSource.getDruidDataSource();
			druidMillis = testDataSource(testDataSource, "Druid", dataSource, testDAO, count);
			dataSource = null;
		}
		{// Tomcat Jdbc Pool数据源
			DataSource dataSource = AllDataSource.getTomcatDataSource();
			tomcatMillis = testDataSource(testDataSource, "Tomcat Jdbc Pool", dataSource, testDAO, count);
			dataSource = null;
		}

		System.out.println("统计结果:[C3P0]平均耗时" + c3p0Millis + "ms");
		System.out.println("统计结果:[Druid]平均耗时" + druidMillis + "ms");
		System.out.println("统计结果:[Proxool]平均耗时" + proxoolMillis + "ms");
		System.out.println("统计结果:[Tomcat]平均耗时" + tomcatMillis + "ms");
	}

	/**
	 * @param c3p0DataSource
	 * @param testDAO
	 * @param count
	 * @throws SQLException
	 * @throws InterruptedException
	 */
	private static long testDataSource(ITestDataSource testDataSource, String dataSourceName,
			DataSource c3p0DataSource, TestDAO testDAO, int count) throws SQLException, InterruptedException {
		System.out.println();
		System.out.println("查询次数为:" + count);
		System.out.println("==========================" + dataSourceName + " 测试开始==========================");
		// 测试c3p0
		long[] runMillis = new long[100];
		for (int i = runMillis.length - 1; i >= 0; i--) {
			runMillis[i] = testDataSource.queryDs(testDAO, c3p0DataSource, count);
			System.out.print("|" + i + "=" + runMillis[i] + "ms");
			if (i % 10 == 0) {
				System.out.println();
			}
		}
		// 开始统计平均值
		long avgMillis = 0l;
		for (int i = runMillis.length - 1; i >= 0; i--) {
			avgMillis += runMillis[i];
		}
		avgMillis = avgMillis / runMillis.length;
		System.out.println();
		System.out.println("==========================" + dataSourceName + " 测试结束==========================");
		System.out.println("平均耗时:" + avgMillis + "ms");
		return avgMillis;
	}

}

运行结果如下,你想自己测试的话,自己去跑。

===========单线程执行===============
log4j:WARN No appenders could be found for logger (com.mchange.v2.log.MLog).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
查询次数为:1000

==========================C3P0 测试开始==========================
|99=1085ms|98=972ms|97=966ms|96=977ms|95=960ms|94=911ms|93=929ms|92=959ms|91=982ms|90=950ms
|89=933ms|88=915ms|87=913ms|86=944ms|85=929ms|84=925ms|83=955ms|82=981ms|81=990ms|80=929ms
|79=905ms|78=909ms|77=931ms|76=922ms|75=936ms|74=952ms|73=914ms|72=961ms|71=921ms|70=965ms
|69=918ms|68=906ms|67=937ms|66=1053ms|65=933ms|64=970ms|63=948ms|62=932ms|61=937ms|60=929ms
|59=929ms|58=938ms|57=887ms|56=943ms|55=1000ms|54=920ms|53=955ms|52=934ms|51=925ms|50=939ms
|49=922ms|48=906ms|47=941ms|46=931ms|45=918ms|44=950ms|43=930ms|42=917ms|41=946ms|40=920ms
|39=941ms|38=930ms|37=913ms|36=904ms|35=931ms|34=938ms|33=936ms|32=903ms|31=898ms|30=982ms
|29=919ms|28=938ms|27=933ms|26=880ms|25=924ms|24=934ms|23=915ms|22=937ms|21=945ms|20=975ms
|19=994ms|18=1010ms|17=1031ms|16=935ms|15=899ms|14=931ms|13=943ms|12=930ms|11=921ms|10=928ms
|9=909ms|8=939ms|7=951ms|6=904ms|5=910ms|4=890ms|3=932ms|2=959ms|1=909ms|0=939ms

==========================C3P0 测试结束==========================
平均耗时:938ms
查询次数为:1000

==========================Druid 测试开始==========================
|99=956ms|98=897ms|97=897ms|96=901ms|95=869ms|94=874ms|93=860ms|92=889ms|91=914ms|90=869ms
|89=900ms|88=871ms|87=871ms|86=871ms|85=876ms|84=901ms|83=983ms|82=877ms|81=911ms|80=888ms
|79=890ms|78=905ms|77=928ms|76=932ms|75=921ms|74=920ms|73=893ms|72=881ms|71=879ms|70=905ms
|69=872ms|68=875ms|67=894ms|66=868ms|65=901ms|64=874ms|63=892ms|62=896ms|61=881ms|60=901ms
|59=871ms|58=903ms|57=884ms|56=888ms|55=899ms|54=933ms|53=939ms|52=966ms|51=866ms|50=887ms
|49=854ms|48=902ms|47=909ms|46=895ms|45=910ms|44=899ms|43=890ms|42=891ms|41=899ms|40=874ms
|39=890ms|38=856ms|37=885ms|36=908ms|35=889ms|34=893ms|33=893ms|32=865ms|31=898ms|30=889ms
|29=898ms|28=899ms|27=864ms|26=905ms|25=887ms|24=905ms|23=910ms|22=882ms|21=898ms|20=899ms
|19=880ms|18=895ms|17=896ms|16=883ms|15=906ms|14=893ms|13=938ms|12=898ms|11=876ms|10=873ms
|9=892ms|8=864ms|7=886ms|6=880ms|5=889ms|4=866ms|3=876ms|2=885ms|1=874ms|0=872ms

==========================Druid 测试结束==========================
平均耗时:892ms
查询次数为:1000

==========================Proxool 测试开始==========================
|99=1070ms|98=1083ms|97=986ms|96=972ms|95=980ms|94=1004ms|93=992ms|92=1026ms|91=1012ms|90=978ms
|89=1050ms|88=1133ms|87=1148ms|86=1012ms|85=981ms|84=973ms|83=1021ms|82=1054ms|81=1024ms|80=1005ms
|79=1001ms|78=979ms|77=992ms|76=997ms|75=975ms|74=992ms|73=1052ms|72=1039ms|71=988ms|70=1007ms
|69=994ms|68=1005ms|67=1021ms|66=990ms|65=973ms|64=1000ms|63=1014ms|62=968ms|61=998ms|60=1012ms
|59=1004ms|58=1130ms|57=1033ms|56=960ms|55=989ms|54=1001ms|53=969ms|52=997ms|51=979ms|50=1020ms
|49=982ms|48=1010ms|47=979ms|46=989ms|45=995ms|44=1013ms|43=997ms|42=1007ms|41=1008ms|40=965ms
|39=993ms|38=1003ms|37=981ms|36=1051ms|35=1097ms|34=1071ms|33=1035ms|32=1004ms|31=974ms|30=1096ms
|29=1136ms|28=1062ms|27=1099ms|26=1150ms|25=1128ms|24=1129ms|23=1123ms|22=1094ms|21=1112ms|20=1158ms
|19=1232ms|18=1139ms|17=1098ms|16=1149ms|15=1125ms|14=1110ms|13=1016ms|12=977ms|11=1010ms|10=960ms
|9=1001ms|8=1049ms|7=1026ms|6=1042ms|5=1046ms|4=970ms|3=1002ms|2=1069ms|1=1122ms|0=991ms

==========================Proxool 测试结束==========================
平均耗时:1031ms
查询次数为:1000

==========================Tomcat Jdbc Pool 测试开始==========================
|99=929ms|98=1035ms|97=1007ms|96=939ms|95=903ms|94=880ms|93=899ms|92=910ms|91=906ms|90=880ms
|89=924ms|88=892ms|87=926ms|86=923ms|85=910ms|84=907ms|83=876ms|82=906ms|81=893ms|80=886ms
|79=918ms|78=894ms|77=960ms|76=873ms|75=969ms|74=913ms|73=882ms|72=1003ms|71=927ms|70=946ms
|69=907ms|68=867ms|67=944ms|66=944ms|65=997ms|64=917ms|63=892ms|62=900ms|61=872ms|60=897ms
|59=903ms|58=878ms|57=910ms|56=892ms|55=916ms|54=899ms|53=903ms|52=881ms|51=897ms|50=896ms
|49=901ms|48=901ms|47=950ms|46=964ms|45=920ms|44=901ms|43=925ms|42=899ms|41=907ms|40=888ms
|39=899ms|38=903ms|37=877ms|36=895ms|35=901ms|34=878ms|33=890ms|32=892ms|31=911ms|30=931ms
|29=885ms|28=890ms|27=900ms|26=911ms|25=989ms|24=903ms|23=905ms|22=952ms|21=938ms|20=977ms
|19=906ms|18=895ms|17=910ms|16=885ms|15=904ms|14=903ms|13=908ms|12=987ms|11=897ms|10=928ms
|9=981ms|8=969ms|7=908ms|6=955ms|5=900ms|4=905ms|3=936ms|2=942ms|1=958ms|0=964ms

==========================Tomcat Jdbc Pool 测试结束==========================
平均耗时:916ms
统计结果:[C3P0]平均耗时938ms
统计结果:[Druid]平均耗时892ms
统计结果:[Proxool]平均耗时1031ms
统计结果:[Tomcat]平均耗时916ms
===========多线程执行===============
查询次数为:1000

==========================C3P0 测试开始==========================
|99=286ms|98=457ms|97=282ms|96=290ms|95=276ms|94=292ms|93=279ms|92=277ms|91=293ms|90=279ms
|89=282ms|88=277ms|87=276ms|86=277ms|85=277ms|84=287ms|83=286ms|82=278ms|81=281ms|80=276ms
|79=277ms|78=274ms|77=271ms|76=274ms|75=278ms|74=278ms|73=276ms|72=279ms|71=274ms|70=273ms
|69=280ms|68=277ms|67=278ms|66=271ms|65=282ms|64=275ms|63=281ms|62=274ms|61=274ms|60=282ms
|59=278ms|58=280ms|57=277ms|56=275ms|55=283ms|54=276ms|53=287ms|52=276ms|51=291ms|50=285ms
|49=282ms|48=294ms|47=290ms|46=285ms|45=277ms|44=272ms|43=274ms|42=275ms|41=280ms|40=280ms
|39=289ms|38=278ms|37=275ms|36=277ms|35=271ms|34=274ms|33=271ms|32=279ms|31=288ms|30=274ms
|29=282ms|28=281ms|27=274ms|26=278ms|25=278ms|24=277ms|23=272ms|22=271ms|21=272ms|20=275ms
|19=276ms|18=276ms|17=276ms|16=272ms|15=276ms|14=272ms|13=273ms|12=278ms|11=280ms|10=276ms
|9=274ms|8=285ms|7=283ms|6=279ms|5=272ms|4=276ms|3=276ms|2=274ms|1=272ms|0=272ms

==========================C3P0 测试结束==========================
平均耗时:280ms
查询次数为:1000

==========================Druid 测试开始==========================
|99=269ms|98=271ms|97=268ms|96=268ms|95=271ms|94=276ms|93=272ms|92=271ms|91=267ms|90=271ms
|89=270ms|88=274ms|87=270ms|86=271ms|85=272ms|84=270ms|83=268ms|82=268ms|81=269ms|80=275ms
|79=273ms|78=271ms|77=273ms|76=306ms|75=289ms|74=269ms|73=270ms|72=270ms|71=270ms|70=270ms
|69=269ms|68=273ms|67=291ms|66=271ms|65=270ms|64=277ms|63=274ms|62=296ms|61=353ms|60=284ms
|59=284ms|58=274ms|57=274ms|56=269ms|55=271ms|54=268ms|53=268ms|52=274ms|51=273ms|50=272ms
|49=279ms|48=273ms|47=271ms|46=268ms|45=269ms|44=271ms|43=270ms|42=272ms|41=273ms|40=270ms
|39=272ms|38=268ms|37=270ms|36=275ms|35=269ms|34=287ms|33=308ms|32=313ms|31=317ms|30=274ms
|29=272ms|28=270ms|27=271ms|26=270ms|25=271ms|24=276ms|23=276ms|22=269ms|21=270ms|20=270ms
|19=271ms|18=271ms|17=272ms|16=271ms|15=271ms|14=269ms|13=271ms|12=269ms|11=270ms|10=270ms
|9=272ms|8=277ms|7=270ms|6=274ms|5=268ms|4=271ms|3=271ms|2=271ms|1=270ms|0=270ms

==========================Druid 测试结束==========================
平均耗时:274ms
查询次数为:1000

==========================Proxool 测试开始==========================
|99=289ms|98=280ms|97=278ms|96=276ms|95=278ms|94=284ms|93=282ms|92=287ms|91=279ms|90=279ms
|89=283ms|88=292ms|87=283ms|86=282ms|85=296ms|84=285ms|83=280ms|82=279ms|81=282ms|80=283ms
|79=290ms|78=281ms|77=281ms|76=280ms|75=283ms|74=279ms|73=285ms|72=467ms|71=281ms|70=278ms
|69=282ms|68=285ms|67=274ms|66=279ms|65=282ms|64=279ms|63=273ms|62=278ms|61=282ms|60=275ms
|59=286ms|58=280ms|57=280ms|56=285ms|55=288ms|54=284ms|53=278ms|52=281ms|51=289ms|50=279ms
|49=282ms|48=288ms|47=282ms|46=278ms|45=276ms|44=282ms|43=275ms|42=279ms|41=275ms|40=308ms
|39=292ms|38=303ms|37=286ms|36=278ms|35=279ms|34=281ms|33=274ms|32=274ms|31=281ms|30=280ms
|29=283ms|28=275ms|27=278ms|26=273ms|25=278ms|24=279ms|23=286ms|22=285ms|21=284ms|20=282ms
|19=281ms|18=279ms|17=282ms|16=281ms|15=274ms|14=276ms|13=278ms|12=279ms|11=277ms|10=279ms
|9=286ms|8=280ms|7=288ms|6=318ms|5=334ms|4=318ms|3=285ms|2=283ms|1=279ms|0=286ms

==========================Proxool 测试结束==========================
平均耗时:284ms
查询次数为:1000

==========================Tomcat Jdbc Pool 测试开始==========================
|99=277ms|98=274ms|97=277ms|96=274ms|95=287ms|94=1198ms|93=272ms|92=270ms|91=272ms|90=278ms
|89=278ms|88=298ms|87=282ms|86=293ms|85=273ms|84=271ms|83=273ms|82=276ms|81=366ms|80=306ms
|79=272ms|78=271ms|77=356ms|76=305ms|75=284ms|74=275ms|73=270ms|72=267ms|71=271ms|70=271ms
|69=276ms|68=273ms|67=274ms|66=271ms|65=269ms|64=271ms|63=271ms|62=270ms|61=328ms|60=355ms
|59=273ms|58=269ms|57=281ms|56=278ms|55=273ms|54=269ms|53=272ms|52=270ms|51=271ms|50=272ms
|49=271ms|48=272ms|47=269ms|46=272ms|45=272ms|44=269ms|43=270ms|42=271ms|41=275ms|40=272ms
|39=278ms|38=272ms|37=271ms|36=273ms|35=272ms|34=272ms|33=272ms|32=275ms|31=269ms|30=268ms
|29=271ms|28=270ms|27=269ms|26=274ms|25=269ms|24=272ms|23=270ms|22=271ms|21=273ms|20=273ms
|19=273ms|18=272ms|17=270ms|16=270ms|15=269ms|14=269ms|13=273ms|12=272ms|11=274ms|10=272ms
|9=273ms|8=268ms|7=268ms|6=269ms|5=271ms|4=277ms|3=272ms|2=273ms|1=268ms|0=269ms

==========================Tomcat Jdbc Pool 测试结束==========================
平均耗时:285ms
统计结果:[C3P0]平均耗时280ms
统计结果:[Druid]平均耗时274ms
统计结果:[Proxool]平均耗时284ms
统计结果:[Tomcat]平均耗时285ms

      总结:多次测试后发现Druid的性能优于C3P0,但是如果数据库是本地数据库127.0.0.1的时候,不知道为什么tomcat的连接池性能最好(没时间研究,谁知道告诉我也行,估计tomcat对这个做了什么优化?)。

    写了真多,写个评语吧:推荐项目使用Druid连接池,实在不行,你用Tomcat连接池也可以,如果你们的项目真的很老,那就用C3P0算了。

 


写了这么多,你还是那么懒,算了,好人做到底:http://download.csdn.net/detail/xzknet/9181089

下载下去,直接可用。哦,对了解压缩密码:test-dbpool

呵呵。




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xzknet/article/details/49127701
个人分类: Java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭