use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
the class MycatServer method resultSetMapClear.
/**
* 在bufferpool使用率大于使用率阈值时不清理
* 在bufferpool使用率小于使用率阈值时清理大结果集清单内容
*
*/
private Runnable resultSetMapClear() {
return new Runnable() {
@Override
public void run() {
try {
BufferPool bufferPool = getBufferPool();
long bufferSize = bufferPool.size();
long bufferCapacity = bufferPool.capacity();
long bufferUsagePercent = (bufferCapacity - bufferSize) * 100 / bufferCapacity;
if (bufferUsagePercent < config.getSystem().getBufferUsagePercent()) {
Map<String, UserStat> map = UserStatAnalyzer.getInstance().getUserStatMap();
Set<String> userSet = config.getUsers().keySet();
for (String user : userSet) {
UserStat userStat = map.get(user);
if (userStat != null) {
SqlResultSizeRecorder recorder = userStat.getSqlResultSizeRecorder();
//System.out.println(recorder.getSqlResultSet().size());
recorder.clearSqlResultSet();
}
}
}
} catch (Exception e) {
LOGGER.warn("resultSetMapClear err " + e);
}
}
;
};
}
use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
the class MycatServer method recycleSqlStat.
//定时清理保存SqlStat中的数据
private Runnable recycleSqlStat() {
return new Runnable() {
@Override
public void run() {
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
userStat.getSqlLastStat().recycle();
userStat.getSqlRecorder().recycle();
userStat.getSqlHigh().recycle();
userStat.getSqlLargeRowStat().recycle();
}
}
};
}
use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
the class ReloadSqlSlowTime method execute.
public static void execute(ManagerConnection c, long time) {
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
userStat.setSlowTime(time);
}
StringBuilder s = new StringBuilder();
s.append(c).append("Reset show @@sql.slow=" + time + " time success by manager");
logger.warn(s.toString());
OkPacket ok = new OkPacket();
ok.packetId = 1;
ok.affectedRows = 1;
ok.serverStatus = 2;
ok.message = "Reset show @@sql.slow time success".getBytes();
ok.write(c);
System.out.println(s.toString());
}
use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
the class ShowSqlResultSet method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
byte packetId = eof.packetId;
int i = 0;
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
ConcurrentHashMap<String, SqlResultSet> map = userStat.getSqlResultSizeRecorder().getSqlResultSet();
if (map != null) {
for (SqlResultSet sqlResultSet : map.values()) {
RowDataPacket row = getRow(++i, user, sqlResultSet.getSql(), sqlResultSet.getCount(), sqlResultSet.getResultSetSize(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.statistic.stat.UserStat in project Mycat-Server by MyCATApache.
the class ShowSQLHigh method execute.
public static void execute(ManagerConnection c, boolean isClear) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
byte packetId = eof.packetId;
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<SqlFrequency> list = userStat.getSqlHigh().getSqlFrequency(isClear);
if (list != null) {
int i = 1;
for (SqlFrequency sqlFrequency : list) {
if (sqlFrequency != null) {
RowDataPacket row = getRow(i, user, sqlFrequency.getSql(), sqlFrequency.getCount(), sqlFrequency.getAvgTime(), sqlFrequency.getMaxTime(), sqlFrequency.getMinTime(), sqlFrequency.getExecuteTime(), sqlFrequency.getLastTime(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
i++;
}
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations