测试各种数据库连接池的性能

testcase

  1. Connection conn = dataSource.getConnection();
  2. conn.close();

Java6 Environment

OSOS X 10.8.2
CPUintel i7 2GHz 4 core
JVMjava version "1.6.0_37"

Java6 Benchmark Result

Jdbc Connection Pool1 thread2 threads5 threads10 threads20 threads50 threads
Druid1,1021,5091,889 1,904 2,0271,977
tomcat-jdbc1,3991,3782,2572,2892,3052,503
DBCP3,1443,8346,2766,4086,5636,783
BoneCP4,3273,5983,8005,2429,40219,066
jboss-datasource4,9123,0496,8686,51240,14643,748
C3P018,57019,46715,27019,29428,19566,677
Proxool16,22114,45524,68838,90548,087(Exception)58,238(Exception)

Java7 Environment

OSOS X 10.8.2
CPUintel i7 2GHz 4 core
JVMjava version "1.7.0_05"

Java7 Benchmark Result

Jdbc Connection Pool1 thread2 threads5 threads10 threads20 threads50 threads
Druid8981,1911,3241,3621,3251,459
tomcat-jdbc1,2691,3782,0292,1031,8792,025
DBCP2,3245,0555,4465,4715,5245,415
BoneCP3,7383,1503,1945,68111,01823,125
jboss-datasource4,3772,9883,6803,98032,70837,742
C3P010,84113,63710,68211,05514,49720,351
Proxool16,33716,18718,310(Exception)25,94533,706(Exception)39,501 (Exception)

结论

  • Druid是性能最好的数据库连接池,tomcat-jdbc和druid性能接近。
  • proxool在激烈并发时会抛异常,完全不靠谱。
  • c3p0和proxool都相当慢,慢到影响sql执行效率的地步。
  • bonecp性能并不优越,采用LinkedTransferQueue并没有能够获得性能提升。
  • 除了bonecp,其他的在JDK 7上跑得比JDK 6上快
  • jboss-datasource虽然稳定,但是性能很糟糕