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