Search in sources :

Example 1 with ThreadWorkUsage

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

the class BackendAsyncHandler method handleInnerData.

private void handleInnerData() {
    byte[] data;
    // threadUsageStat start
    boolean useThreadUsageStat = false;
    String threadName = null;
    ThreadWorkUsage workUsage = null;
    long workStart = 0;
    if (DbleServer.getInstance().getConfig().getSystem().getUseThreadUsageStat() == 1) {
        useThreadUsageStat = true;
        threadName = Thread.currentThread().getName();
        workUsage = DbleServer.getInstance().getThreadUsedMap().get(threadName);
        if (threadName.startsWith("backend")) {
            if (workUsage == null) {
                workUsage = new ThreadWorkUsage();
                DbleServer.getInstance().getThreadUsedMap().put(threadName, workUsage);
            }
        }
        workStart = System.nanoTime();
    }
    // handleData
    while ((data = dataQueue.poll()) != null) {
        handleData(data);
    }
    // threadUsageStat end
    if (useThreadUsageStat && threadName.startsWith("backend")) {
        workUsage.setCurrentSecondUsed(workUsage.getCurrentSecondUsed() + System.nanoTime() - workStart);
    }
}
Also used : ThreadWorkUsage(com.actiontech.dble.statistic.stat.ThreadWorkUsage)

Example 2 with ThreadWorkUsage

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

the class ShowThreadUsed method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = HEADER.write(buffer, c, true);
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    buffer = EOF.write(buffer, c, true);
    byte packetId = EOF.getPacketId();
    for (Map.Entry<String, ThreadWorkUsage> entry : DbleServer.getInstance().getThreadUsedMap().entrySet()) {
        RowDataPacket row = getRow(entry.getKey(), entry.getValue(), c.getCharset().getResults());
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : ThreadWorkUsage(com.actiontech.dble.statistic.stat.ThreadWorkUsage) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Map(java.util.Map)

Example 3 with ThreadWorkUsage

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

the class FrontEndHandlerRunnable method run.

@Override
public void run() {
    FrontendCommandHandler handler;
    while (true) {
        try {
            handler = frontHandlerQueue.take();
            // threadUsageStat start
            boolean useThreadUsageStat = false;
            String threadName = null;
            ThreadWorkUsage workUsage = null;
            long workStart = 0;
            if (DbleServer.getInstance().getConfig().getSystem().getUseThreadUsageStat() == 1) {
                useThreadUsageStat = true;
                threadName = Thread.currentThread().getName();
                workUsage = DbleServer.getInstance().getThreadUsedMap().get(threadName);
                if (workUsage == null) {
                    workUsage = new ThreadWorkUsage();
                    DbleServer.getInstance().getThreadUsedMap().put(threadName, workUsage);
                }
                workStart = System.nanoTime();
            }
            // handler data
            handler.handle();
            // threadUsageStat end
            if (useThreadUsageStat) {
                workUsage.setCurrentSecondUsed(workUsage.getCurrentSecondUsed() + System.nanoTime() - workStart);
            }
        } catch (InterruptedException e) {
            throw new RuntimeException("FrontendCommandHandler error.", e);
        }
    }
}
Also used : ThreadWorkUsage(com.actiontech.dble.statistic.stat.ThreadWorkUsage)

Example 4 with ThreadWorkUsage

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

the class ConcurrentFrontEndHandlerRunnable method run.

@Override
public void run() {
    FrontendCommandHandler handler;
    while (true) {
        while ((handler = frontHandlerQueue.poll()) != null) {
            // threadUsageStat start
            boolean useThreadUsageStat = false;
            String threadName = null;
            ThreadWorkUsage workUsage = null;
            long workStart = 0;
            if (DbleServer.getInstance().getConfig().getSystem().getUseThreadUsageStat() == 1) {
                useThreadUsageStat = true;
                threadName = Thread.currentThread().getName();
                workUsage = DbleServer.getInstance().getThreadUsedMap().get(threadName);
                if (workUsage == null) {
                    workUsage = new ThreadWorkUsage();
                    DbleServer.getInstance().getThreadUsedMap().put(threadName, workUsage);
                }
                workStart = System.nanoTime();
            }
            // handler data
            handler.handle();
            // threadUsageStat end
            if (useThreadUsageStat) {
                workUsage.setCurrentSecondUsed(workUsage.getCurrentSecondUsed() + System.nanoTime() - workStart);
            }
        }
    }
}
Also used : ThreadWorkUsage(com.actiontech.dble.statistic.stat.ThreadWorkUsage)

Aggregations

ThreadWorkUsage (com.actiontech.dble.statistic.stat.ThreadWorkUsage)4 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1