use of com.actiontech.dble.statistic.stat.QueryTimeCost in project dble by actiontech.
the class ShowCostTimeStat method getBackendConnCost.
private static String[] getBackendConnCost(QueryTimeCost queryTimeCost) {
int i = 0;
StringBuilder sb = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
for (Map.Entry<Long, QueryTimeCost> backCostEntry : queryTimeCost.getBackEndTimeCosts().entrySet()) {
if (i != 0) {
sb.append(";");
sb2.append(";");
}
long id = backCostEntry.getKey();
sb.append("Id:");
sb.append(id);
sb.append(",Time:");
QueryTimeCost backendCost = backCostEntry.getValue();
sb.append((backendCost.getRequestTime() - queryTimeCost.getRequestTime()) / 1000);
sb2.append("Id:");
sb2.append(id);
sb2.append(",Time:");
sb2.append((backendCost.getResponseTime().get() - backendCost.getRequestTime()) / 1000);
i++;
}
return new String[] { sb.toString(), sb2.toString() };
}
use of com.actiontech.dble.statistic.stat.QueryTimeCost in project dble by actiontech.
the class NonBlockingSession method setBackendResponseTime.
public void setBackendResponseTime(long backendID) {
if (!timeCost) {
return;
}
QueryTimeCost backCost = queryTimeCost.getBackEndTimeCosts().get(backendID);
long responseTime = System.nanoTime();
if (backCost != null && backCost.getResponseTime().compareAndSet(0, responseTime)) {
if (queryTimeCost.getFirstBackConRes().compareAndSet(false, true)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("backend connection[" + backendID + "] setResponseTime:" + responseTime);
}
provider.resFromBack(source.getId());
firstBackConRes.set(false);
}
if (queryTimeCost.getBackendReserveCount().decrementAndGet() == 0) {
provider.resLastBack(source.getId());
}
}
}
use of com.actiontech.dble.statistic.stat.QueryTimeCost in project dble by actiontech.
the class NonBlockingSession method setRequestTime.
public void setRequestTime() {
if (DbleServer.getInstance().getConfig().getSystem().getCostTimeStat() == 0) {
return;
}
timeCost = false;
if (ThreadLocalRandom.current().nextInt(100) >= DbleServer.getInstance().getConfig().getSystem().getCostSamplePercent()) {
return;
}
timeCost = true;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("clear");
}
queryTimeCost = new QueryTimeCost();
provider = new CostTimeProvider();
provider.beginRequest(source.getId());
long requestTime = System.nanoTime();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("frontend connection setRequestTime:" + requestTime);
}
queryTimeCost.setRequestTime(requestTime);
}
use of com.actiontech.dble.statistic.stat.QueryTimeCost in project dble by actiontech.
the class NonBlockingSession method setBackendRequestTime.
public void setBackendRequestTime(long backendID) {
if (!timeCost) {
return;
}
QueryTimeCost backendCost = new QueryTimeCost();
long requestTime = System.nanoTime();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("backend connection[" + backendID + "] setRequestTime:" + requestTime);
}
backendCost.setRequestTime(requestTime);
queryTimeCost.getBackEndTimeCosts().put(backendID, backendCost);
}
use of com.actiontech.dble.statistic.stat.QueryTimeCost in project dble by actiontech.
the class ShowCostTimeStat 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();
QueryTimeCost[] recorders = QueryTimeCostContainer.getInstance().getRecorders();
int realPos = QueryTimeCostContainer.getInstance().getRealPos();
int start = 0;
int end = realPos;
if (realPos != recorders.length - 1 && recorders[realPos + 1] != null) {
start = realPos + 1;
end = realPos + recorders.length;
}
for (int i = start; i <= end; i++) {
RowDataPacket row = getRow(recorders[i % recorders.length], 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);
}
Aggregations