事务时间直方图

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@847 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-19 02:00:12 +00:00
parent 7d60b388da
commit 9d0c7d6ee7
3 changed files with 138 additions and 37 deletions
@@ -53,6 +53,7 @@ import com.alibaba.druid.stat.JdbcDataSourceStat;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.util.ConcurrentIdentityHashMap;
import com.alibaba.druid.util.DruidLoaderUtils;
import com.alibaba.druid.util.Histogram;
import com.alibaba.druid.util.JdbcUtils;
/**
@@ -122,7 +123,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
System.out);
protected List<Filter> filters = new ArrayList<Filter>();
protected ExceptionSorter exceptionSorter = null;
protected ExceptionSorter exceptionSorter = null;
protected Driver driver;
@@ -175,6 +176,17 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
protected final AtomicLong startTransactionCount = new AtomicLong();
protected final AtomicLong rollbackCount = new AtomicLong();
protected final Histogram transactionHistogram = new Histogram(
10,
100,
1000,
10 * 1000,
100 * 1000);
public Histogram getTransactionHistogram() {
return transactionHistogram;
}
public long getCommitCount() {
return commitCount.get();
}
@@ -1342,4 +1354,5 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
public abstract int getRawDriverMinorVersion();
public abstract String getProperties();
}
@@ -140,6 +140,7 @@ public class PoolableConnection implements PooledConnection, Connection {
this.holder = null;
conn = null;
startTransactionTimeMillis = 0;
}
// ////////////////////
@@ -566,12 +567,16 @@ public class PoolableConnection implements PooledConnection, Connection {
public void commit() throws SQLException {
checkOpen();
holder.getDataSource().incrementCommitCount();
DruidAbstractDataSource dataSource = holder.getDataSource();
dataSource.incrementCommitCount();
try {
conn.commit();
} catch (SQLException ex) {
handleException(ex);
} finally {
long transactionMillis = System.currentTimeMillis() - startTransactionTimeMillis;
dataSource.getTransactionHistogram().recode(transactionMillis);
startTransactionTimeMillis = 0;
}
}
@@ -584,14 +589,62 @@ public class PoolableConnection implements PooledConnection, Connection {
public void rollback() throws SQLException {
checkOpen();
holder.getDataSource().incrementRollbackCount();
DruidAbstractDataSource dataSource = holder.getDataSource();
dataSource.incrementRollbackCount();
try {
conn.rollback();
} catch (SQLException ex) {
handleException(ex);
} finally {
long transactionMillis = System.currentTimeMillis() - startTransactionTimeMillis;
dataSource.getTransactionHistogram().recode(transactionMillis);
startTransactionTimeMillis = 0;
}
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
checkOpen();
return conn.setSavepoint(name);
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
checkOpen();
DruidAbstractDataSource dataSource = holder.getDataSource();
dataSource.incrementRollbackCount();
try {
conn.rollback(savepoint);
} catch (SQLException ex) {
handleException(ex);
} finally {
long transactionMillis = System.currentTimeMillis() - startTransactionTimeMillis;
dataSource.getTransactionHistogram().recode(transactionMillis);
startTransactionTimeMillis = 0;
}
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
checkOpen();
try {
conn.releaseSavepoint(savepoint);
} catch (SQLException ex) {
handleException(ex);
}
}
@Override
public Clob createClob() throws SQLException {
checkOpen();
return conn.createClob();
}
@Override
public boolean isClosed() throws SQLException {
if (holder == null) {
@@ -699,40 +752,6 @@ public class PoolableConnection implements PooledConnection, Connection {
return conn.setSavepoint();
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
checkOpen();
return conn.setSavepoint(name);
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
checkOpen();
try {
conn.rollback(savepoint);
} catch (SQLException ex) {
handleException(ex);
}
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
checkOpen();
try {
conn.releaseSavepoint(savepoint);
} catch (SQLException ex) {
handleException(ex);
}
}
@Override
public Clob createClob() throws SQLException {
checkOpen();
return conn.createClob();
}
@Override
public Blob createBlob() throws SQLException {
checkOpen();