mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
优化监控数据的处理
This commit is contained in:
@@ -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,32 +53,36 @@ public class MonitorBus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void printStatistics(){
|
public static void printStatistics(){
|
||||||
Map<String, Long> compAverageTimeSpent = new HashMap<String, Long>();
|
try{
|
||||||
Map<String, Long> compAverageMemorySpent = new HashMap<String, Long>();
|
Map<String, Long> compAverageTimeSpent = new HashMap<String, Long>();
|
||||||
|
Map<String, Long> compAverageMemorySpent = new HashMap<String, Long>();
|
||||||
|
|
||||||
long totalTimeSpent = 0;
|
long totalTimeSpent = 0;
|
||||||
long totalMemorySpent = 0;
|
long totalMemorySpent = 0;
|
||||||
|
|
||||||
for(Entry<String, LimitQueue<CompStatistics>> entry : statisticsMap.entrySet()){
|
for(Entry<String, LimitQueue<CompStatistics>> entry : statisticsMap.entrySet()){
|
||||||
for(CompStatistics statistics : entry.getValue()){
|
for(CompStatistics statistics : entry.getValue()){
|
||||||
totalTimeSpent += statistics.getTimeSpent();
|
totalTimeSpent += statistics.getTimeSpent();
|
||||||
totalMemorySpent += statistics.getMemorySpent();
|
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());
|
System.out.println("======================================================================================");
|
||||||
compAverageMemorySpent.put(entry.getKey(), new BigDecimal(totalMemorySpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue());
|
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("======================================================================================");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
String response = flowExecutor.execute("chain2", "it's a request");
|
ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||||
System.out.println(response);
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user