소스 검색

调度报表优化,报表SQL调优并且新增LocalCache缓存(缓存时间60s),提高大数据量下报表加载速度;

xuxueli 7 년 전
부모
커밋
a1e11ea190

+ 2 - 2
doc/XXL-JOB官方文档.md 파일 보기

@@ -1144,8 +1144,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1144 1144
 - 1、修复打包部署时资源文件乱码问题;
1145 1145
 - 2、修复新版本chrome滚动到顶部失效问题;
1146 1146
 - 3、国际化:调度中心实现国际化,支持中文、英文两种语言,默认为中文。
1147
-- 4、调度报表新增"运行中"中状态项,数据加载SQL优化
1148
-- 5、调度报表缓存优化,修复大数据量执行日志加载缓慢的问题
1147
+- 4、调度报表新增"运行中"中状态项;
1148
+- 5、调度报表优化,报表SQL调优并且新增LocalCache缓存(缓存时间60s),提高大数据量下报表加载速度
1149 1149
 
1150 1150
 ### TODO LIST
1151 1151
 - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;

+ 5 - 7
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java 파일 보기

@@ -23,12 +23,11 @@ import java.util.Properties;
23 23
 public class I18nUtil {
24 24
     private static Logger logger = LoggerFactory.getLogger(I18nUtil.class);
25 25
 
26
-    private static Properties prop = null;
27
-    private static long lastCacheTim = 0L;
28
-
26
+    private static final String I18N_PROP_CACHE = "i18n_prop_cache";
29 27
     public static Properties loadI18nProp(){
30
-        if (prop != null && (System.currentTimeMillis()-lastCacheTim)<60*1000) {
31
-            //return prop;
28
+        Properties prop = (Properties) LocalCacheUtil.get(I18N_PROP_CACHE);
29
+        if (prop != null) {
30
+            return prop;
32 31
         }
33 32
         try {
34 33
             // bild i18n prop
@@ -40,11 +39,10 @@ public class I18nUtil {
40 39
             Resource resource = new ClassPathResource(i18nFile);
41 40
             EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
42 41
             prop = PropertiesLoaderUtils.loadProperties(encodedResource);
43
-            lastCacheTim = System.currentTimeMillis();
42
+            LocalCacheUtil.set(I18N_PROP_CACHE, prop, 60*1000);     // cache 60s
44 43
         } catch (IOException e) {
45 44
             logger.error(e.getMessage(), e);
46 45
         }
47
-        logger.warn("---111---");
48 46
         return prop;
49 47
     }
50 48
 

+ 112 - 0
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/LocalCacheUtil.java 파일 보기

@@ -0,0 +1,112 @@
1
+package com.xxl.job.admin.core.util;
2
+
3
+import org.apache.commons.lang3.StringUtils;
4
+
5
+import java.util.concurrent.ConcurrentHashMap;
6
+
7
+/**
8
+ * local cache tool
9
+ *
10
+ * @author xuxueli 2018-01-22 21:37:34
11
+ */
12
+public class LocalCacheUtil {
13
+
14
+    private static ConcurrentHashMap<String, LocalCacheData> cacheRepository = new ConcurrentHashMap<>();
15
+    private static class LocalCacheData{
16
+        private String key;
17
+        private Object val;
18
+        private long timeoutTime;
19
+
20
+        public LocalCacheData() {
21
+        }
22
+
23
+        public LocalCacheData(String key, Object val, long timeoutTime) {
24
+            this.key = key;
25
+            this.val = val;
26
+            this.timeoutTime = timeoutTime;
27
+        }
28
+
29
+        public String getKey() {
30
+            return key;
31
+        }
32
+
33
+        public void setKey(String key) {
34
+            this.key = key;
35
+        }
36
+
37
+        public Object getVal() {
38
+            return val;
39
+        }
40
+
41
+        public void setVal(Object val) {
42
+            this.val = val;
43
+        }
44
+
45
+        public long getTimeoutTime() {
46
+            return timeoutTime;
47
+        }
48
+
49
+        public void setTimeoutTime(long timeoutTime) {
50
+            this.timeoutTime = timeoutTime;
51
+        }
52
+    }
53
+
54
+
55
+    /**
56
+     * set cache
57
+     *
58
+     * @param key
59
+     * @param val
60
+     * @param cacheTime
61
+     * @return
62
+     */
63
+    public static boolean set(String key, Object val, long cacheTime){
64
+        if (StringUtils.isBlank(key)) {
65
+            return false;
66
+        }
67
+        if (val == null) {
68
+            remove(key);
69
+        }
70
+        if (cacheTime <= 0) {
71
+            remove(key);
72
+        }
73
+        long timeoutTime = System.currentTimeMillis() + cacheTime;
74
+        LocalCacheData localCacheData = new LocalCacheData(key, val, timeoutTime);
75
+        cacheRepository.put(localCacheData.getKey(), localCacheData);
76
+        return true;
77
+    }
78
+
79
+    /**
80
+     * remove cache
81
+     *
82
+     * @param key
83
+     * @return
84
+     */
85
+    public static boolean remove(String key){
86
+        if (StringUtils.isBlank(key)) {
87
+            return false;
88
+        }
89
+        cacheRepository.remove(key);
90
+        return true;
91
+    }
92
+
93
+    /**
94
+     * get cache
95
+     *
96
+     * @param key
97
+     * @return
98
+     */
99
+    public static Object get(String key){
100
+        if (StringUtils.isBlank(key)) {
101
+            return null;
102
+        }
103
+        LocalCacheData localCacheData = cacheRepository.get(key);
104
+        if (localCacheData!=null && System.currentTimeMillis()<localCacheData.getTimeoutTime()) {
105
+            return localCacheData.getVal();
106
+        } else {
107
+            remove(key);
108
+            return null;
109
+        }
110
+    }
111
+
112
+}

+ 13 - 0
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java 파일 보기

@@ -6,6 +6,7 @@ import com.xxl.job.admin.core.model.XxlJobInfo;
6 6
 import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
7 7
 import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
8 8
 import com.xxl.job.admin.core.util.I18nUtil;
9
+import com.xxl.job.admin.core.util.LocalCacheUtil;
9 10
 import com.xxl.job.admin.dao.XxlJobGroupDao;
10 11
 import com.xxl.job.admin.dao.XxlJobInfoDao;
11 12
 import com.xxl.job.admin.dao.XxlJobLogDao;
@@ -320,8 +321,16 @@ public class XxlJobServiceImpl implements XxlJobService {
320 321
 		return dashboardMap;
321 322
 	}
322 323
 
324
+	private static final String TRIGGER_CHART_DATA_CACHE = "trigger_chart_data_cache";
323 325
 	@Override
324 326
 	public ReturnT<Map<String, Object>> triggerChartDate(Date startDate, Date endDate) {
327
+		// get cache
328
+		Map<String, Object> triggerChartDateCache = (Map<String, Object>) LocalCacheUtil.get(TRIGGER_CHART_DATA_CACHE);
329
+		if (triggerChartDateCache != null) {
330
+			return new ReturnT<Map<String, Object>>(triggerChartDateCache);
331
+		}
332
+
333
+		// process
325 334
 		List<String> triggerDayList = new ArrayList<String>();
326 335
 		List<Integer> triggerDayCountRunningList = new ArrayList<Integer>();
327 336
 		List<Integer> triggerDayCountSucList = new ArrayList<Integer>();
@@ -365,6 +374,10 @@ public class XxlJobServiceImpl implements XxlJobService {
365 374
 		result.put("triggerCountRunningTotal", triggerCountRunningTotal);
366 375
 		result.put("triggerCountSucTotal", triggerCountSucTotal);
367 376
 		result.put("triggerCountFailTotal", triggerCountFailTotal);
377
+
378
+		// set cache
379
+		LocalCacheUtil.set(TRIGGER_CHART_DATA_CACHE, result, 60*1000);     // cache 60s
380
+
368 381
 		return new ReturnT<Map<String, Object>>(result);
369 382
 	}
370 383
 

+ 1 - 0
xxl-job-admin/src/main/webapp/static/js/joblog.index.1.js 파일 보기

@@ -76,6 +76,7 @@ $(function() {
76 76
 	    "serverSide": true,
77 77
 		"ajax": {
78 78
 	        url: base_url + "/joblog/pageList" ,
79
+            type:"post",
79 80
 	        data : function ( d ) {
80 81
 	        	var obj = {};
81 82
 	        	obj.jobGroup = $('#jobGroup').val();