Search in sources :

Example 1 with SqlFrequency

use of com.actiontech.dble.statistic.stat.SqlFrequency in project dble by actiontech.

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.getPacketId();
    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().getResults());
                    row.setPacketId(++packetId);
                    buffer = row.write(buffer, c, true);
                    i++;
                }
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : SqlFrequency(com.actiontech.dble.statistic.stat.SqlFrequency) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) UserStat(com.actiontech.dble.statistic.stat.UserStat) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 2 with SqlFrequency

use of com.actiontech.dble.statistic.stat.SqlFrequency in project dble by actiontech.

the class TestConcurrentSafety method testUserSqlHighStat.

@Test
@Ignore
public void testUserSqlHighStat() throws InterruptedException {
    final UserSqlHighStat userSqlHighStat = new UserSqlHighStat();
    Thread[] thread = new Thread[THREAD_COUNT];
    Thread[] thread2 = new Thread[THREAD_COUNT];
    Thread[] thread3 = new Thread[THREAD_COUNT];
    for (int i = 0; i < THREAD_COUNT; i++) {
        thread[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    userSqlHighStat.addSql(sql, 10L, 1L, 11L);
                }
            }
        };
        thread2[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    userSqlHighStat.addSql(sql2, 10L, 1L, 11L);
                }
            }
        };
        thread3[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    userSqlHighStat.addSql(sql4, 10L, 1L, 11L);
                }
            }
        };
    }
    for (int i = 0; i < THREAD_COUNT; i++) {
        thread[i].start();
        thread2[i].start();
        thread3[i].start();
    }
    for (int i = 0; i < THREAD_COUNT; i++) {
        thread[i].join();
        thread2[i].join();
        thread3[i].join();
    }
    List<SqlFrequency> sqlFrequency = userSqlHighStat.getSqlFrequency(true);
    Assert.assertTrue(sqlFrequency.size() == 2);
    Assert.assertTrue(sqlFrequency.get(0).getCount() == 2 * THREAD_COUNT * LOOP_COUNT);
    Assert.assertTrue(sqlFrequency.get(1).getCount() == THREAD_COUNT * LOOP_COUNT);
}
Also used : SqlFrequency(com.actiontech.dble.statistic.stat.SqlFrequency) UserSqlHighStat(com.actiontech.dble.statistic.stat.UserSqlHighStat) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SqlFrequency (com.actiontech.dble.statistic.stat.SqlFrequency)2 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)1 UserSqlHighStat (com.actiontech.dble.statistic.stat.UserSqlHighStat)1 UserStat (com.actiontech.dble.statistic.stat.UserStat)1 ByteBuffer (java.nio.ByteBuffer)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1