调度中心日志自动清理功能:调度中心新增配置项("xxl.job.logretentiondays")日志保存天数,过期日志自动清理;解决海量日志情况下日志表慢SQL问题;限制大于等于7时生效,否则关闭清理功能,默认为30;

2.1.2
xuxueli 5 years ago
parent 7ab75aa817
commit 333f15e504

@ -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

@ -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;
}

@ -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<Long> 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) {

@ -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

Loading…
Cancel
Save