Search in sources :

Example 1 with UserStat

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);
            }
        }

        ;
    };
}
Also used : BufferPool(io.mycat.buffer.BufferPool) DirectByteBufferPool(io.mycat.buffer.DirectByteBufferPool) UserStat(io.mycat.statistic.stat.UserStat) SqlResultSizeRecorder(io.mycat.statistic.stat.SqlResultSizeRecorder)

Example 2 with UserStat

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();
            }
        }
    };
}
Also used : UserStat(io.mycat.statistic.stat.UserStat)

Example 3 with UserStat

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());
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket) UserStat(io.mycat.statistic.stat.UserStat)

Example 4 with UserStat

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);
}
Also used : SqlResultSet(io.mycat.statistic.stat.SqlResultSet) RowDataPacket(io.mycat.net.mysql.RowDataPacket) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 5 with UserStat

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);
}
Also used : SqlFrequency(io.mycat.statistic.stat.SqlFrequency) RowDataPacket(io.mycat.net.mysql.RowDataPacket) UserStat(io.mycat.statistic.stat.UserStat) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

UserStat (io.mycat.statistic.stat.UserStat)10 EOFPacket (io.mycat.net.mysql.EOFPacket)6 FieldPacket (io.mycat.net.mysql.FieldPacket)6 RowDataPacket (io.mycat.net.mysql.RowDataPacket)6 ByteBuffer (java.nio.ByteBuffer)6 OkPacket (io.mycat.net.mysql.OkPacket)2 BufferPool (io.mycat.buffer.BufferPool)1 DirectByteBufferPool (io.mycat.buffer.DirectByteBufferPool)1 SQLRecord (io.mycat.statistic.SQLRecord)1 SqlFrequency (io.mycat.statistic.stat.SqlFrequency)1 SqlResultSet (io.mycat.statistic.stat.SqlResultSet)1 SqlResultSizeRecorder (io.mycat.statistic.stat.SqlResultSizeRecorder)1 UserSqlLargeStat (io.mycat.statistic.stat.UserSqlLargeStat)1 UserSqlLastStat (io.mycat.statistic.stat.UserSqlLastStat)1