From 333f15e504b8ec7b3a012aca7d5cda92afe1407b Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Fri, 22 Nov 2019 18:59:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9A=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9=EF=BC=88"xxl.job.logretentiondays"?= =?UTF-8?q?=EF=BC=89=E6=97=A5=E5=BF=97=E4=BF=9D=E5=AD=98=E5=A4=A9=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E8=BF=87=E6=9C=9F=E6=97=A5=E5=BF=97=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B8=85=E7=90=86=EF=BC=9B=E8=A7=A3=E5=86=B3=E6=B5=B7=E9=87=8F?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=83=85=E5=86=B5=E4=B8=8B=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=A1=A8=E6=85=A2SQL=E9=97=AE=E9=A2=98=EF=BC=9B=E9=99=90?= =?UTF-8?q?=E5=88=B6=E5=A4=A7=E4=BA=8E=E7=AD=89=E4=BA=8E7=E6=97=B6?= =?UTF-8?q?=E7=94=9F=E6=95=88=EF=BC=8C=E5=90=A6=E5=88=99=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=BA30=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 10 +++++- .../admin/core/conf/XxlJobAdminConfig.java | 10 ++++++ .../admin/core/thread/JobLogReportHelper.java | 35 +++++++++++++++++-- .../src/main/resources/application.properties | 3 ++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 4cfb4626..dd67c247 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -464,6 +464,13 @@ XXL-JOB是一个轻量级分布式任务调度平台,其核心设计目标是 ### xxl-job, i18n (default empty as chinese, "en" as english) xxl.job.i18n= + ## xxl-job, 调度线程池最大线程配置 + xxl.job.triggerpool.fast.max=200 + xxl.job.triggerpool.slow.max=100 + + ### xxl-job, 日志保存天数,过期日志自动清理;限制大于等于7时生效,否则,如-1,关闭自动清理功能; + xxl.job.logretentiondays=30 + #### 步骤二:部署项目: @@ -1599,7 +1606,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 21、调度中心回调API服务改为restful方式; - 22、调度中心日志删除优化,改为分页获取ID并根据ID删除的方式,避免批量删除海量日志导致死锁问题; - 23、调度报表优化:新增日志报表的存储表,三天内的任务日志会以每分钟一次的频率异步同步至报表中;任务报表仅读取报表数据,极大提升加载速度; -- 24、[ing]调度日志优化:支持设置日志保留天数,过期日志天维度记录报表,并清理;调度报表汇总实时数据和报表; +- 24、调度中心日志自动清理功能:调度中心新增配置项("xxl.job.logretentiondays")日志保存天数,过期日志自动清理;解决海量日志情况下日志表慢SQL问题;限制大于等于7时生效,否则关闭清理功能,默认为30; + diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java index 8d8f14d1..7fc26443 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java @@ -62,6 +62,9 @@ public class XxlJobAdminConfig implements InitializingBean, DisposableBean { @Value("${xxl.job.triggerpool.slow.max}") private int triggerPoolSlowMax; + @Value("${xxl.job.logretentiondays}") + private int logretentiondays; + // dao, service @Resource @@ -106,6 +109,13 @@ public class XxlJobAdminConfig implements InitializingBean, DisposableBean { return triggerPoolSlowMax; } + public int getLogretentiondays() { + if (logretentiondays < 7) { + return -1; // Limit greater than or equal to 7, otherwise close + } + return logretentiondays; + } + public XxlJobLogDao getXxlJobLogDao() { return xxlJobLogDao; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobLogReportHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobLogReportHelper.java index 54228644..2387a0c4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobLogReportHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobLogReportHelper.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import java.util.Calendar; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -32,11 +33,15 @@ public class JobLogReportHelper { @Override public void run() { - // monitor + // last clean log time + long lastCleanLogTime = 0; + + while (!toStop) { + + // 1、log-report refresh: refresh log report in 3 days try { - // refresh log report in 3 days for (int i = 0; i < 3; i++) { // today @@ -88,6 +93,32 @@ public class JobLogReportHelper { } } + // 2、log-clean: switch open & once each day + if (XxlJobAdminConfig.getAdminConfig().getLogretentiondays()>0 + && System.currentTimeMillis() - lastCleanLogTime > 24*60*60*1000) { + + // expire-time + Calendar expiredDay = Calendar.getInstance(); + expiredDay.add(Calendar.DAY_OF_MONTH, -1 * XxlJobAdminConfig.getAdminConfig().getLogretentiondays()); + expiredDay.set(Calendar.HOUR_OF_DAY, 0); + expiredDay.set(Calendar.MINUTE, 0); + expiredDay.set(Calendar.SECOND, 0); + expiredDay.set(Calendar.MILLISECOND, 0); + Date clearBeforeTime = expiredDay.getTime(); + + // clean expired log + List logIds = null; + do { + logIds = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findClearLogIds(0, 0, clearBeforeTime, 0, 1000); + if (logIds!=null && logIds.size()>0) { + XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().clearLog(logIds); + } + } while (logIds!=null && logIds.size()>0); + + // update clean time + lastCleanLogTime = System.currentTimeMillis(); + } + try { TimeUnit.MINUTES.sleep(1); } catch (Exception e) { diff --git a/xxl-job-admin/src/main/resources/application.properties b/xxl-job-admin/src/main/resources/application.properties index 36ac06ec..af668193 100644 --- a/xxl-job-admin/src/main/resources/application.properties +++ b/xxl-job-admin/src/main/resources/application.properties @@ -48,3 +48,6 @@ xxl.job.i18n= ## xxl-job, triggerpool max size xxl.job.triggerpool.fast.max=200 xxl.job.triggerpool.slow.max=100 + +### xxl-job, log retention days +xxl.job.logretentiondays=30