feat(naming): Support empty service cleanup task time configurable

This commit is contained in:
chuntaojun 2020-03-08 00:00:44 +08:00
parent 4f264fed2d
commit 0886653a08
3 changed files with 15 additions and 3 deletions

View File

@ -37,5 +37,7 @@ nacos.core.auth.enabled=false
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.naming.empty.service.auto-clean=true
nacos.naming.empty-service.clean.initial-delay-ms=50000
nacos.naming.empty-service.clean.period-time-ms=30000
tldSkipPatterns=derbyLocale_*.jar,jaxb-api.jar,jsr173_1.0_api.jar,jaxb1-impl.jar,activation.jar

View File

@ -44,6 +44,10 @@ server.port=8848
### If enable the empty service auto clean, services with an empty instance are automatically cleared
nacos.naming.empty.service.auto-clean=false
### The empty service cleanup task delays startup time in milliseconds
nacos.naming.empty-service.clean.initial-delay-ms=60000
### The empty service cleanup task cycle execution time in milliseconds
nacos.naming.empty-service.clean.period-time-ms=20000
#*************** CMDB Module Related Configurations ***************#

View File

@ -110,6 +110,12 @@ public class ServiceManager implements RecordListener<Service> {
private final Object putServiceLock = new Object();
@Value("${nacos.naming.empty-service.clean.initial-delay-ms:60000}")
private int cleanEmptyServiceDelay;
@Value("${nacos.naming.empty-service.clean.period-time-ms:20000}")
private int cleanEmptyServicePeriod;
@PostConstruct
public void init() {
@ -119,15 +125,15 @@ public class ServiceManager implements RecordListener<Service> {
if (emptyServiceAutoClean) {
Loggers.SRV_LOG.info("open empty service auto clean job, initialDelay : {} ms, period : {} ms", cleanEmptyServiceDelay, cleanEmptyServicePeriod);
// delay 60s, period 20s;
// This task is not recommended to be performed frequently in order to avoid
// the possibility that the service cache information may just be deleted
// and then created due to the heartbeat mechanism
GlobalExecutor.scheduleServiceAutoClean(new EmptyServiceAutoClean(), 60_000L, 20_000L);
Loggers.SRV_LOG.info("open empty service auto clean job");
GlobalExecutor.scheduleServiceAutoClean(new EmptyServiceAutoClean(), cleanEmptyServiceDelay, cleanEmptyServicePeriod);
}
try {