optimized memory used

This commit is contained in:
wenshao
2012-10-08 09:27:08 +08:00
parent 5088fa8a34
commit f551328636
10 changed files with 451 additions and 231 deletions
@@ -18,6 +18,7 @@ package com.alibaba.druid.stat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import javax.management.JMException;
@@ -37,189 +38,189 @@ import com.alibaba.druid.util.JMXUtils;
*/
public final class JdbcSqlStat implements JdbcSqlStatMBean {
private final String sql;
private long id;
private String dataSource;
private long executeLastStartTime;
private final String sql;
private long id;
private String dataSource;
private long executeLastStartTime;
private volatile long executeBatchSizeTotal;
private volatile long executeBatchSizeMax;
private volatile long executeBatchSizeTotal;
private volatile int executeBatchSizeMax;
private volatile long executeSuccessCount;
private volatile long executeSpanNanoTotal;
private volatile long executeSpanNanoMax;
private volatile long runningCount;
private volatile long concurrentMax;
private volatile long resultSetHoldTimeNano;
private volatile long executeAndResultSetHoldTime;
private volatile long executeSuccessCount;
private volatile long executeSpanNanoTotal;
private volatile long executeSpanNanoMax;
private volatile int runningCount;
private volatile int concurrentMax;
private volatile long resultSetHoldTimeNano;
private volatile long executeAndResultSetHoldTime;
final static AtomicLongFieldUpdater<JdbcSqlStat> executeBatchSizeTotalUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeBatchSizeTotal");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeBatchSizeMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeBatchSizeMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeBatchSizeTotalUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeBatchSizeTotal");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> executeBatchSizeMaxUpdater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeBatchSizeMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeSuccessCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeSuccessCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeSpanNanoTotalUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeSpanNanoTotal");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeSpanNanoMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeSpanNanoMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> runningCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"runningCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> concurrentMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"concurrentMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> resultSetHoldTimeNanoUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"resultSetHoldTimeNano");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultSetHoldTimeUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultSetHoldTime");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeSuccessCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeSuccessCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeSpanNanoTotalUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeSpanNanoTotal");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeSpanNanoMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeSpanNanoMax");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> runningCountUpdater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"runningCount");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> concurrentMaxUpdater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"concurrentMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> resultSetHoldTimeNanoUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"resultSetHoldTimeNano");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultSetHoldTimeUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultSetHoldTime");
private String name;
private String file;
private String dbType;
private String name;
private String file;
private String dbType;
private long executeNanoSpanMaxOccurTime;
private volatile long executeNanoSpanMaxOccurTime;
private volatile long executeErrorCount;
private Throwable executeErrorLast;
private long executeErrorLastTime;
private volatile long executeErrorCount;
private volatile Throwable executeErrorLast;
private volatile long executeErrorLastTime;
private volatile long updateCount;
private volatile long updateCountMax;
private volatile long fetchRowCount;
private volatile long fetchRowCountMax;
private volatile long updateCount;
private volatile long updateCountMax;
private volatile long fetchRowCount;
private volatile long fetchRowCountMax;
private volatile long inTransactionCount;
private volatile long inTransactionCount;
private String lastSlowParameters;
private volatile String lastSlowParameters;
private boolean removed = false;
private boolean removed = false;
private volatile long clobOpenCount;
private volatile long blobOpenCount;
private volatile long readStringLength;
private volatile long readBytesLength;
private volatile long clobOpenCount;
private volatile long blobOpenCount;
private volatile long readStringLength;
private volatile long readBytesLength;
private volatile long inputStreamOpenCount;
private volatile long readerOpenCount;
private volatile long inputStreamOpenCount;
private volatile long readerOpenCount;
final static AtomicLongFieldUpdater<JdbcSqlStat> executeErrorCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeErrorCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCountMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCountMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCountMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCountMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> inTransactionCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"inTransactionCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeErrorCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeErrorCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCountMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCountMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCountMaxUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCountMax");
final static AtomicLongFieldUpdater<JdbcSqlStat> inTransactionCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"inTransactionCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> clobOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"clobOpenCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> blobOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"blobOpenCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> readStringLengthUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"readStringLength");
final static AtomicLongFieldUpdater<JdbcSqlStat> readBytesLengthUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"readBytesLength");
final static AtomicLongFieldUpdater<JdbcSqlStat> clobOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"clobOpenCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> blobOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"blobOpenCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> readStringLengthUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"readStringLength");
final static AtomicLongFieldUpdater<JdbcSqlStat> readBytesLengthUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"readBytesLength");
final static AtomicLongFieldUpdater<JdbcSqlStat> inputStreamOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"inputStreamOpenCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> readerOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"readerOpenCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> inputStreamOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"inputStreamOpenCount");
final static AtomicLongFieldUpdater<JdbcSqlStat> readerOpenCountUpdater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"readerOpenCount");
private volatile long histogram_0_1;
private volatile long histogram_1_10;
private volatile long histogram_10_100;
private volatile long histogram_100_1000;
private volatile long histogram_1000_10000;
private volatile long histogram_10000_100000;
private volatile long histogram_100000_1000000;
private volatile long histogram_1000000_more;
private volatile long histogram_0_1;
private volatile long histogram_1_10;
private volatile int histogram_10_100;
private volatile int histogram_100_1000;
private volatile int histogram_1000_10000;
private volatile int histogram_10000_100000;
private volatile int histogram_100000_1000000;
private volatile int histogram_1000000_more;
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_1_10");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_10_100_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_10_100");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_100_1000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_100_1000");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_1000_10000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_1000_10000");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_10000_100000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_10000_100000");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_100000_1000000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_100000_1000000");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_1000000_more_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_1000000_more");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> histogram_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_1_10");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> histogram_10_100_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_10_100");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> histogram_100_1000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_100_1000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> histogram_1000_10000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_1000_10000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> histogram_10000_100000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_10000_100000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> histogram_100000_1000000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_100000_1000000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> histogram_1000000_more_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"histogram_1000000_more");
private volatile long executeAndResultHoldTime_0_1;
private volatile long executeAndResultHoldTime_1_10;
private volatile long executeAndResultHoldTime_10_100;
private volatile long executeAndResultHoldTime_100_1000;
private volatile long executeAndResultHoldTime_1000_10000;
private volatile long executeAndResultHoldTime_10000_100000;
private volatile long executeAndResultHoldTime_100000_1000000;
private volatile long executeAndResultHoldTime_1000000_more;
private volatile long executeAndResultHoldTime_0_1;
private volatile long executeAndResultHoldTime_1_10;
private volatile int executeAndResultHoldTime_10_100;
private volatile int executeAndResultHoldTime_100_1000;
private volatile int executeAndResultHoldTime_1000_10000;
private volatile int executeAndResultHoldTime_10000_100000;
private volatile int executeAndResultHoldTime_100000_1000000;
private volatile int executeAndResultHoldTime_1000000_more;
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_1_10");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_10_100_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_10_100");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_100_1000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_100_1000");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_1000_10000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_1000_10000");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_10000_100000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_10000_100000");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_100000_1000000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_100000_1000000");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_1000000_more_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_1000000_more");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_1_10");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_10_100_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_10_100");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_100_1000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_100_1000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_1000_10000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_1000_10000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_10000_100000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_10000_100000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_100000_1000000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_100000_1000000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> executeAndResultHoldTime_1000000_more_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"executeAndResultHoldTime_1000000_more");
private volatile long fetchRowCount_0_1;
private volatile long fetchRowCount_1_10;
private volatile long fetchRowCount_10_100;
private volatile long fetchRowCount_100_1000;
private volatile long fetchRowCount_1000_10000;
private volatile long fetchRowCount_10000_more;
private volatile long fetchRowCount_0_1;
private volatile long fetchRowCount_1_10;
private volatile long fetchRowCount_10_100;
private volatile int fetchRowCount_100_1000;
private volatile int fetchRowCount_1000_10000;
private volatile int fetchRowCount_10000_more;
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_1_10");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_10_100_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_10_100");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_100_1000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_100_1000");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_1000_10000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_1000_10000");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_10000_more_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_10000_more");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_1_10");
final static AtomicLongFieldUpdater<JdbcSqlStat> fetchRowCount_10_100_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_10_100");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> fetchRowCount_100_1000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_100_1000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> fetchRowCount_1000_10000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_1000_10000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> fetchRowCount_10000_more_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"fetchRowCount_10000_more");
private volatile long updateCount_0_1;
private volatile long updateCount_1_10;
private volatile long updateCount_10_100;
private volatile long updateCount_100_1000;
private volatile long updateCount_1000_10000;
private volatile long updateCount_10000_more;
private volatile long updateCount_0_1;
private volatile long updateCount_1_10;
private volatile long updateCount_10_100;
private volatile int updateCount_100_1000;
private volatile int updateCount_1000_10000;
private volatile int updateCount_10000_more;
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_1_10");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_10_100_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_10_100");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_100_1000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_100_1000");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_1000_10000_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_1000_10000");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_10000_more_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_10000_more");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_0_1_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_0_1");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_1_10_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_1_10");
final static AtomicLongFieldUpdater<JdbcSqlStat> updateCount_10_100_Updater = AtomicLongFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_10_100");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> updateCount_100_1000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_100_1000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> updateCount_1000_10000_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_1000_10000");
final static AtomicIntegerFieldUpdater<JdbcSqlStat> updateCount_10000_more_Updater = AtomicIntegerFieldUpdater.newUpdater(JdbcSqlStat.class,
"updateCount_10000_more");
public JdbcSqlStat(String sql){
this.sql = sql;
@@ -555,9 +556,9 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
// executeBatchSizeMax
for (;;) {
long current = executeBatchSizeMaxUpdater.get(this);
int current = executeBatchSizeMaxUpdater.get(this);
if (current < batchSize) {
if (executeBatchSizeMaxUpdater.compareAndSet(this, current, batchSize)) {
if (executeBatchSizeMaxUpdater.compareAndSet(this, current, (int) batchSize)) {
break;
} else {
continue;
@@ -577,10 +578,10 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
}
public void incrementRunningCount() {
long val = runningCountUpdater.incrementAndGet(this);
int val = runningCountUpdater.incrementAndGet(this);
for (;;) {
long max = concurrentMaxUpdater.get(this);
int max = concurrentMaxUpdater.get(this);
if (val > max) {
if (concurrentMaxUpdater.compareAndSet(this, max, val)) {
break;
@@ -229,14 +229,7 @@ public class WebStatFilter implements Filter {
String ip = DruidWebUtils.getRemoteAddr(request);
int addressCount = sessionStat.getRemoteAddresses().size();
if (addressCount < 10) {
sessionStat.addRemoteAddress(ip);
} else {
if (!sessionStat.getRemoteAddress().contains(ip)) {
LOG.error("sessoin ip change too many");
}
}
sessionStat.addRemoteAddress(ip);
}
return sessionStat;
@@ -16,67 +16,95 @@
package com.alibaba.druid.support.http.stat;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import com.alibaba.druid.util.Histogram;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
public class WebSessionStat {
private final static Log LOG = LogFactory.getLog(WebSessionStat.class);
private final String sessionId;
private volatile int runningCount;
private volatile int concurrentMax;
final static AtomicIntegerFieldUpdater<WebSessionStat> runningCountUpdater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"runningCount");
final static AtomicIntegerFieldUpdater<WebSessionStat> concurrentMaxUpdater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"concurrentMax");
final static AtomicIntegerFieldUpdater<WebSessionStat> runningCountUpdater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"runningCount");
final static AtomicIntegerFieldUpdater<WebSessionStat> concurrentMaxUpdater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"concurrentMax");
private volatile long requestCount;
private volatile long requestErrorCount;
private volatile long requestTimeNano;
final static AtomicLongFieldUpdater<WebSessionStat> requestCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"requestCount");
final static AtomicLongFieldUpdater<WebSessionStat> requestErrorCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"requestErrorCount");
final static AtomicLongFieldUpdater<WebSessionStat> requestTimeNanoUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"requestTimeNano");
final static AtomicLongFieldUpdater<WebSessionStat> requestCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"requestCount");
final static AtomicLongFieldUpdater<WebSessionStat> requestErrorCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"requestErrorCount");
final static AtomicLongFieldUpdater<WebSessionStat> requestTimeNanoUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"requestTimeNano");
private volatile long jdbcFetchRowCount;
private volatile long jdbcUpdateCount;
private volatile long jdbcExecuteCount;
private volatile long jdbcExecuteTimeNano;
final static AtomicLongFieldUpdater<WebSessionStat> jdbcFetchRowCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcFetchRowCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcUpdateCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcUpdateCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcExecuteCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcExecuteCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcExecuteTimeNanoUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcExecuteTimeNano");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcFetchRowCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcFetchRowCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcUpdateCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcUpdateCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcExecuteCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcExecuteCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcExecuteTimeNanoUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcExecuteTimeNano");
private volatile long jdbcCommitCount;
private volatile long jdbcRollbackCount;
final static AtomicLongFieldUpdater<WebSessionStat> jdbcCommitCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcCommitCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcRollbackCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcRollbackCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcCommitCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcCommitCount");
final static AtomicLongFieldUpdater<WebSessionStat> jdbcRollbackCountUpdater = AtomicLongFieldUpdater.newUpdater(WebSessionStat.class,
"jdbcRollbackCount");
private long createTimeMillis = -1L;
private volatile long lastAccessTimeMillis = -1L;
private long createTimeMillis = -1L;
private volatile long lastAccessTimeMillis = -1L;
private Set<String> remoteAddresses = new HashSet<String>(2);
private String remoteAddresses;
private String principal = null;
private String principal = null;
private String userAgent;
private Histogram requestIntervalHistogram = Histogram.makeHistogram(8);
private volatile int requestIntervalHistogram_0_1;
private volatile int requestIntervalHistogram_1_10;
private volatile int requestIntervalHistogram_10_100;
private volatile int requestIntervalHistogram_100_1000;
private volatile int requestIntervalHistogram_1000_10000;
private volatile int requestIntervalHistogram_10000_100000;
private volatile int requestIntervalHistogram_100000_1000000;
private volatile int requestIntervalHistogram_1000000_10000000;
private volatile int requestIntervalHistogram_10000000_more;
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_0_1_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_0_1");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_1_10_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_1_10");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_10_100_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_10_100");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_100_1000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_100_1000");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_1000_10000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_1000_10000");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_10000_100000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_10000_100000");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_100000_1000000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_100000_1000000");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_1000000_10000000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_1000000_10000000");
final static AtomicIntegerFieldUpdater<WebSessionStat> requestIntervalHistogram_10000000_more_Updater = AtomicIntegerFieldUpdater.newUpdater(WebSessionStat.class,
"requestIntervalHistogram_10000000_more");
public WebSessionStat(String sessionId){
super();
@@ -96,10 +124,18 @@ public class WebSessionStat {
jdbcCommitCountUpdater.set(this, 0);
jdbcRollbackCountUpdater.set(this, 0);
remoteAddresses.clear();
remoteAddresses = null;
principal = null;
requestIntervalHistogram.reset();
requestIntervalHistogram_0_1_Updater.set(this, 0);
requestIntervalHistogram_1_10_Updater.set(this, 0);
requestIntervalHistogram_10_100_Updater.set(this, 0);
requestIntervalHistogram_100_1000_Updater.set(this, 0);
requestIntervalHistogram_1000_10000_Updater.set(this, 0);
requestIntervalHistogram_10000_100000_Updater.set(this, 0);
requestIntervalHistogram_100000_1000000_Updater.set(this, 0);
requestIntervalHistogram_1000000_10000000_Updater.set(this, 0);
requestIntervalHistogram_10000000_more_Updater.set(this, 0);
}
public String getUserAgent() {
@@ -150,38 +186,42 @@ public class WebSessionStat {
return new Date(lastAccessTimeMillis);
}
public Set<String> getRemoteAddresses() {
return remoteAddresses;
}
public String getRemoteAddress() {
if (remoteAddresses.size() == 0) {
return null;
}
if (remoteAddresses.size() == 1) {
return remoteAddresses.iterator().next();
}
StringBuilder buf = new StringBuilder();
for (String item : remoteAddresses) {
if (buf.length() != 0) {
buf.append(";");
}
buf.append(item);
}
return buf.toString();
return remoteAddresses;
}
public void setLastAccessTimeMillis(long lastAccessTimeMillis) {
if (this.lastAccessTimeMillis > 0) {
long interval = lastAccessTimeMillis - this.lastAccessTimeMillis;
requestIntervalHistogram.record(interval);
requestIntervalHistogramRecord(interval);
}
this.lastAccessTimeMillis = lastAccessTimeMillis;
}
private void requestIntervalHistogramRecord(long nanoSpan) {
long millis = nanoSpan / 1000 / 1000;
if (millis < 1) {
requestIntervalHistogram_0_1_Updater.incrementAndGet(this);
} else if (millis < 10) {
requestIntervalHistogram_1_10_Updater.incrementAndGet(this);
} else if (millis < 100) {
requestIntervalHistogram_10_100_Updater.incrementAndGet(this);
} else if (millis < 1000) {
requestIntervalHistogram_100_1000_Updater.incrementAndGet(this);
} else if (millis < 10000) {
requestIntervalHistogram_1000_10000_Updater.incrementAndGet(this);
} else if (millis < 100000) {
requestIntervalHistogram_10000_100000_Updater.incrementAndGet(this);
} else if (millis < 1000000) {
requestIntervalHistogram_100000_1000000_Updater.incrementAndGet(this);
} else if (millis < 10000000) {
requestIntervalHistogram_1000000_10000000_Updater.incrementAndGet(this);
} else {
requestIntervalHistogram_10000000_more_Updater.incrementAndGet(this);
}
}
public void beforeInvoke() {
int running = runningCountUpdater.incrementAndGet(this);
@@ -230,7 +270,21 @@ public class WebSessionStat {
}
public void addRemoteAddress(String ip) {
this.remoteAddresses.add(ip);
if (remoteAddresses == null) {
this.remoteAddresses = ip;
return;
}
if (remoteAddresses.contains(ip)) {
return;
}
if (remoteAddresses.length() > 256) {
LOG.error("sessoin ip change too many");
return;
}
remoteAddresses += ';' + ip;
}
public int getRunningCount() {
@@ -322,7 +376,18 @@ public class WebSessionStat {
}
public long[] getRequestInterval() {
return requestIntervalHistogram.toArray();
return new long[] {
//
requestIntervalHistogram_0_1, //
requestIntervalHistogram_1_10, //
requestIntervalHistogram_10_100, //
requestIntervalHistogram_100_1000, //
requestIntervalHistogram_1000_10000, //
requestIntervalHistogram_10000_100000, //
requestIntervalHistogram_100000_1000000, //
requestIntervalHistogram_1000000_10000000, //
requestIntervalHistogram_10000000_more //
};
}
public Map<String, Object> getStatData() {
@@ -5,13 +5,12 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ProfileStat {
private ConcurrentHashMap<ProfileEntryKey, ProfileEntryStat> entries = new ConcurrentHashMap<ProfileEntryKey, ProfileEntryStat>(
16,
4,
0.75f,
1);
public ConcurrentHashMap<ProfileEntryKey, ProfileEntryStat> getEntries() {
public Map<ProfileEntryKey, ProfileEntryStat> getEntries() {
return entries;
}