优化服务端清理线程池运行历史数据的参数.

pull/39/head
chen.ma 3 years ago
parent 830de5d9b6
commit 426afecf23

@ -0,0 +1,34 @@
package cn.hippo4j.config.config;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* Server bootstrap properties.
*
* @author chen.ma
* @date 2021/12/22 08:01
*/
@Slf4j
@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = ServerBootstrapProperties.PREFIX)
public class ServerBootstrapProperties {
public final static String PREFIX = "hippo4j.core";
/**
* Whether to start the background task of cleaning up thread pool history data.
*/
private Boolean cleanHistoryDataEnable = Boolean.TRUE;
/**
* Regularly clean up the historical running data of thread pool. unit: minute.
*/
private Integer cleanHistoryDataPeriod = 30;
}

@ -1,6 +1,7 @@
package cn.hippo4j.config.monitor;
import cn.hippo4j.common.executor.ExecutorFactory;
import cn.hippo4j.config.config.ServerBootstrapProperties;
import cn.hippo4j.config.model.HisRunDataInfo;
import cn.hippo4j.config.service.biz.HisRunDataService;
import cn.hutool.core.date.DateTime;
@ -10,7 +11,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Date;
@ -29,11 +29,8 @@ import static cn.hippo4j.common.constant.Constants.DEFAULT_GROUP;
@RequiredArgsConstructor
public class TimeCleanHistoryDataTask implements Runnable, InitializingBean {
@Value("${clean.history.data.period:30}")
private Long cleanHistoryDataPeriod;
@Value("${clean.history.data.period.enable:true}")
private Boolean cleanHistoryDataPeriodEnable;
@NonNull
private final ServerBootstrapProperties properties;
@NonNull
private final HisRunDataService hisRunDataService;
@ -43,7 +40,7 @@ public class TimeCleanHistoryDataTask implements Runnable, InitializingBean {
@Override
public void run() {
Date currentDate = new Date();
DateTime offsetMinuteDateTime = DateUtil.offsetMinute(currentDate, (int) -cleanHistoryDataPeriod);
DateTime offsetMinuteDateTime = DateUtil.offsetMinute(currentDate, -properties.getCleanHistoryDataPeriod());
LambdaQueryWrapper<HisRunDataInfo> queryWrapper = Wrappers.lambdaQuery(HisRunDataInfo.class)
.le(HisRunDataInfo::getTimestamp, offsetMinuteDateTime.getTime());
@ -53,7 +50,7 @@ public class TimeCleanHistoryDataTask implements Runnable, InitializingBean {
@Override
public void afterPropertiesSet() throws Exception {
if (cleanHistoryDataPeriodEnable) {
if (properties.getCleanHistoryDataEnable()) {
cleanHistoryDataExecutor = ExecutorFactory.Managed
.newSingleScheduledExecutorService(DEFAULT_GROUP, r -> new Thread(r, "clean-history-data"));
cleanHistoryDataExecutor.scheduleWithFixedDelay(this, 0, 1, TimeUnit.MINUTES);

@ -3,6 +3,7 @@ package cn.hippo4j.config.service.biz.impl;
import cn.hippo4j.common.monitor.Message;
import cn.hippo4j.common.monitor.RuntimeMessage;
import cn.hippo4j.common.toolkit.GroupKey;
import cn.hippo4j.config.config.ServerBootstrapProperties;
import cn.hippo4j.config.mapper.HisRunDataMapper;
import cn.hippo4j.config.model.HisRunDataInfo;
import cn.hippo4j.config.model.biz.monitor.MonitorActiveRespDTO;
@ -14,7 +15,7 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Value;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Date;
@ -29,15 +30,15 @@ import static cn.hutool.core.date.DatePattern.NORM_TIME_PATTERN;
* @date 2021/12/10 21:28
*/
@Service
@AllArgsConstructor
public class HisRunDataServiceImpl extends ServiceImpl<HisRunDataMapper, HisRunDataInfo> implements HisRunDataService {
@Value("${clean.history.data.period:30}")
private Long cleanHistoryDataPeriod;
private final ServerBootstrapProperties properties;
@Override
public List<MonitorRespDTO> query(MonitorQueryReqDTO reqDTO) {
Date currentDate = new Date();
DateTime dateTime = DateUtil.offsetMinute(currentDate, (int) -cleanHistoryDataPeriod);
DateTime dateTime = DateUtil.offsetMinute(currentDate, -properties.getCleanHistoryDataPeriod());
long startTime = dateTime.getTime();
List<HisRunDataInfo> hisRunDataInfos = this.lambdaQuery()
@ -55,7 +56,7 @@ public class HisRunDataServiceImpl extends ServiceImpl<HisRunDataMapper, HisRunD
@Override
public MonitorActiveRespDTO queryInfoThreadPoolMonitor(MonitorQueryReqDTO reqDTO) {
Date currentDate = new Date();
DateTime dateTime = DateUtil.offsetMinute(currentDate, (int) -cleanHistoryDataPeriod);
DateTime dateTime = DateUtil.offsetMinute(currentDate, -properties.getCleanHistoryDataPeriod());
long startTime = dateTime.getTime();
List<HisRunDataInfo> hisRunDataInfos = this.lambdaQuery()

@ -17,8 +17,8 @@ server.tomcat.basedir=
tenant=hippo4j
### Regularly clean up the historical running data of thread pool. unit: minute.
clean.history.data.period=30
clean.history.data.period.enable=true
hippo4j.core.clean-history-data-period=30
hippo4j.core.clean-history-data-enable=true
#*************** Config Module Related Configurations ***************#

@ -17,8 +17,8 @@ server.tomcat.basedir=
tenant=hippo4j
### Regularly clean up the historical running data of thread pool. unit: minute.
clean.history.data.period=30
clean.history.data.period.enable=true
hippo4j.core.clean-history-data-period=30
hippo4j.core.clean-history-data-enable=true
#*************** Config Module Related Configurations ***************#

Loading…
Cancel
Save