优化监控数据的处理

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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.thebeastshop.liteflow.entity.data.DataBus; import com.thebeastshop.liteflow.entity.data.DataBus;
import com.thebeastshop.liteflow.entity.monitor.CompStatistics; import com.thebeastshop.liteflow.entity.monitor.CompStatistics;
import com.thebeastshop.liteflow.util.LimitQueue; import com.thebeastshop.liteflow.util.LimitQueue;
@@ -28,6 +29,8 @@ public class MonitorBus {
private static final int QUEUE_LIMIT_SIZE = 200; 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>>(); private static ConcurrentHashMap<String, LimitQueue<CompStatistics>> statisticsMap = new ConcurrentHashMap<String, LimitQueue<CompStatistics>>();
static{ static{
@@ -36,7 +39,7 @@ public class MonitorBus {
public void run() { public void run() {
MonitorBus.printStatistics(); MonitorBus.printStatistics();
} }
}, 30*1000L, 10*60*1000L); }, 30*1000L, 1*60*1000L);
} }
public static void addStatistics(CompStatistics statistics){ public static void addStatistics(CompStatistics statistics){
@@ -50,6 +53,7 @@ public class MonitorBus {
} }
public static void printStatistics(){ public static void printStatistics(){
try{
Map<String, Long> compAverageTimeSpent = new HashMap<String, Long>(); Map<String, Long> compAverageTimeSpent = new HashMap<String, Long>();
Map<String, Long> compAverageMemorySpent = new HashMap<String, Long>(); Map<String, Long> compAverageMemorySpent = new HashMap<String, Long>();
@@ -77,5 +81,8 @@ public class MonitorBus {
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("COMPONENT["+entry.getKey()+"] AVERAGE MEMORY SPENT : "+ new BigDecimal(entry.getValue()).divide(new BigDecimal(1024), 2, RoundingMode.HALF_UP) + "K");
} }
System.out.println("======================================================================================"); System.out.println("======================================================================================");
}catch(Exception e){
LOG.error("print statistics cause error",e);
}
} }
} }

View File

@@ -1,5 +1,8 @@
package com.thebeastshop.liteflow.test; package com.thebeastshop.liteflow.test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.junit.Test; import org.junit.Test;
@@ -20,7 +23,18 @@ public class TestWithSpringMain {
@Test @Test
public void test1() throws Exception { public void test1() throws Exception {
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"); String response = flowExecutor.execute("chain2", "it's a request");
System.out.println(response); System.out.println(response);
} }
});
}
System.out.println("done!");
System.in.read();
}
} }