修正evict的bug

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@522 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-07-26 05:52:52 +00:00
parent 0e4d3d00d2
commit 0fdd23b6c6
7 changed files with 233 additions and 29 deletions
@@ -13,7 +13,7 @@ import junit.framework.TestCase;
import com.alibaba.druid.TestUtil;
import com.alibaba.druid.pool.DruidDataSource;
public class CaseKylin_mysql_idle extends TestCase {
public class CaseKylin_mysql_idle_1 extends TestCase {
private String jdbcUrl;
private String user;
@@ -27,7 +27,7 @@ public class CaseKylin_mysql_idle extends TestCase {
private String validationQuery = null; // "SELECT 1";
private int threadCount = 15;
private int TEST_COUNT = 3;
final int LOOP_COUNT = 1000 * 1;
final int LOOP_COUNT = 1000 * 10;
private boolean testWhileIdle = true;
private boolean testOnBorrow = false;
private boolean testOnReturn = false;
@@ -0,0 +1,143 @@
package com.alibaba.druid.pool.benckmark;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.NumberFormat;
import java.util.concurrent.CountDownLatch;
import javax.sql.DataSource;
import junit.framework.TestCase;
import com.alibaba.druid.TestUtil;
import com.alibaba.druid.mock.MockDriver;
import com.alibaba.druid.pool.DruidDataSource;
public class CaseKylin_mysql_idle_2 extends TestCase {
private String jdbcUrl;
private String user;
private String password;
private String driverClass;
private int initialSize = 1;
private int minIdle = 1;
private int maxIdle = 20;
private int maxActive = 20;
private int maxWait = 60000;
private String validationQuery = null; // "SELECT 1";
private int threadCount = 15;
private int TEST_COUNT = 3;
final int LOOP_COUNT = 10 * 1;
private boolean testWhileIdle = true;
private boolean testOnBorrow = false;
private boolean testOnReturn = false;
private boolean removeAbandoned = true;
private int removeAbandonedTimeout = 180;
private long timeBetweenEvictionRunsMillis = 60 * 10;
private long minEvictableIdleTimeMillis = 1800 * 10;
private int numTestsPerEvictionRun = 20;
protected void setUp() throws Exception {
jdbcUrl = "jdbc:fake:dragoon_v25masterdb";
user = "dragoon25";
password = "dragoon25";
driverClass = "com.alibaba.druid.mock.MockDriver";
MockDriver.instance.setIdleTimeCount(50 * 60 * 10);
// jdbcUrl = "jdbc:mysql://10.20.141.150:8066/amoeba";
// user = "root";
// password = "12345";
// driverClass = "com.mysql.jdbc.Driver";
// jdbcUrl = "jdbc:oracle:thin:@10.20.149.85:1521:ocnauto";
// user = "alibaba";
// password = "ccbuauto";
// driverClass = "oracle.jdbc.driver.OracleDriver";
}
public void test_perf() throws Exception {
druid();
}
public void druid() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setInitialSize(initialSize);
dataSource.setMaxActive(maxActive);
dataSource.setMaxIdle(maxIdle);
dataSource.setMinIdle(minIdle);
dataSource.setMaxWait(maxWait);
dataSource.setPoolPreparedStatements(true);
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(jdbcUrl);
dataSource.setPoolPreparedStatements(true);
dataSource.setUsername(user);
dataSource.setPassword(password);
dataSource.setValidationQuery(validationQuery);
dataSource.setTestOnBorrow(testOnBorrow);
dataSource.setTestOnBorrow(testWhileIdle);
dataSource.setTestOnBorrow(testOnReturn);
dataSource.setRemoveAbandoned(removeAbandoned);
dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
p0(dataSource, "druid", threadCount);
long startMillis = System.currentTimeMillis();
for (int i = 0; i < 1000; ++i) {
p0(dataSource, "druid", threadCount);
long seconds = (System.currentTimeMillis() - startMillis) / 1000L;
System.out.println("seconds : " + seconds);
}
System.out.println();
}
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(threadCount);
for (int i = 0; i < threadCount; ++i) {
Thread thread = new Thread() {
public void run() {
try {
startLatch.await();
for (int i = 0; i < LOOP_COUNT; ++i) {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT 1");
ResultSet rs = stmt.executeQuery();
rs.next();
rs.getInt(1);
rs.close();
stmt.close();
conn.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
endLatch.countDown();
}
};
thread.start();
}
long startMillis = System.currentTimeMillis();
long startYGC = TestUtil.getYoungGC();
long startFullGC = TestUtil.getFullGC();
startLatch.countDown();
endLatch.await();
long millis = System.currentTimeMillis() - startMillis;
long ygc = TestUtil.getYoungGC() - startYGC;
long fullGC = TestUtil.getFullGC() - startFullGC;
System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC);
}
}