优化监控数据的处理

This commit is contained in:
bryan.zhang 2017-11-23 15:27:08 +08:00
parent 07c0ab8b41
commit b02167cf4e
2 changed files with 49 additions and 28 deletions

View File

@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.thebeastshop.liteflow.entity.data.DataBus;
import com.thebeastshop.liteflow.entity.monitor.CompStatistics;
import com.thebeastshop.liteflow.util.LimitQueue;
@ -28,6 +29,8 @@ public class MonitorBus {
private static final int QUEUE_LIMIT_SIZE = 200;
private static final Logger LOG = LoggerFactory.getLogger(MonitorBus.class);
private static ConcurrentHashMap<String, LimitQueue<CompStatistics>> statisticsMap = new ConcurrentHashMap<String, LimitQueue<CompStatistics>>();
static{
@ -36,7 +39,7 @@ public class MonitorBus {
public void run() {
MonitorBus.printStatistics();
}
}, 30*1000L, 10*60*1000L);
}, 30*1000L, 1*60*1000L);
}
public static void addStatistics(CompStatistics statistics){
@ -50,32 +53,36 @@ public class MonitorBus {
}
public static void printStatistics(){
Map<String, Long> compAverageTimeSpent = new HashMap<String, Long>();
Map<String, Long> compAverageMemorySpent = new HashMap<String, Long>();
long totalTimeSpent = 0;
long totalMemorySpent = 0;
for(Entry<String, LimitQueue<CompStatistics>> entry : statisticsMap.entrySet()){
for(CompStatistics statistics : entry.getValue()){
totalTimeSpent += statistics.getTimeSpent();
totalMemorySpent += statistics.getMemorySpent();
try{
Map<String, Long> compAverageTimeSpent = new HashMap<String, Long>();
Map<String, Long> compAverageMemorySpent = new HashMap<String, Long>();
long totalTimeSpent = 0;
long totalMemorySpent = 0;
for(Entry<String, LimitQueue<CompStatistics>> entry : statisticsMap.entrySet()){
for(CompStatistics statistics : entry.getValue()){
totalTimeSpent += statistics.getTimeSpent();
totalMemorySpent += statistics.getMemorySpent();
}
compAverageTimeSpent.put(entry.getKey(), new BigDecimal(totalTimeSpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue());
compAverageMemorySpent.put(entry.getKey(), new BigDecimal(totalMemorySpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue());
}
compAverageTimeSpent.put(entry.getKey(), new BigDecimal(totalTimeSpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue());
compAverageMemorySpent.put(entry.getKey(), new BigDecimal(totalMemorySpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue());
System.out.println("======================================================================================");
System.out.println("===================================SLOT INFO==========================================");
System.out.println("SLOT TOTAL SIZE : "+DataBus.SLOT_SIZE);
System.out.println("SLOT OCCUPY COUNT : "+DataBus.OCCUPY_COUNT);
System.out.println("===============================TIME AVERAGE SPENT=====================================");
for(Entry<String, Long> entry : compAverageTimeSpent.entrySet()){
System.out.println("COMPONENT["+entry.getKey()+"] AVERAGE TIME SPENT : " + entry.getValue());
}
System.out.println("==============================MEMORY AVERAGE SPENT====================================");
for(Entry<String, Long> entry : compAverageMemorySpent.entrySet()){
System.out.println("COMPONENT["+entry.getKey()+"] AVERAGE MEMORY SPENT : "+ new BigDecimal(entry.getValue()).divide(new BigDecimal(1024), 2, RoundingMode.HALF_UP) + "K");
}
System.out.println("======================================================================================");
}catch(Exception e){
LOG.error("print statistics cause error",e);
}
System.out.println("======================================================================================");
System.out.println("===================================SLOT INFO==========================================");
System.out.println("SLOT TOTAL SIZE : "+DataBus.SLOT_SIZE);
System.out.println("SLOT OCCUPY COUNT : "+DataBus.OCCUPY_COUNT);
System.out.println("===============================TIME AVERAGE SPENT=====================================");
for(Entry<String, Long> entry : compAverageTimeSpent.entrySet()){
System.out.println("COMPONENT["+entry.getKey()+"] AVERAGE TIME SPENT : " + entry.getValue());
}
System.out.println("==============================MEMORY AVERAGE SPENT====================================");
for(Entry<String, Long> entry : compAverageMemorySpent.entrySet()){
System.out.println("COMPONENT["+entry.getKey()+"] AVERAGE MEMORY SPENT : "+ new BigDecimal(entry.getValue()).divide(new BigDecimal(1024), 2, RoundingMode.HALF_UP) + "K");
}
System.out.println("======================================================================================");
}
}

View File

@ -1,5 +1,8 @@
package com.thebeastshop.liteflow.test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Resource;
import org.junit.Test;
@ -20,7 +23,18 @@ public class TestWithSpringMain {
@Test
public void test1() throws Exception {
String response = flowExecutor.execute("chain2", "it's a request");
System.out.println(response);
ExecutorService executorService = Executors.newFixedThreadPool(10);
for(int i=0;i<100;i++){
executorService.submit(new Thread(){
@Override
public void run() {
String response = flowExecutor.execute("chain2", "it's a request");
System.out.println(response);
}
});
}
System.out.println("done!");
System.in.read();
}
}