diff --git a/console/src/main/resources/application.properties b/console/src/main/resources/application.properties index ddaf39fc1..b3c775beb 100644 --- a/console/src/main/resources/application.properties +++ b/console/src/main/resources/application.properties @@ -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 diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index 209a23e51..0b555db32 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -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 ***************# diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index e8fd98083..0bc0bf323 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -110,6 +110,12 @@ public class ServiceManager implements RecordListener { 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 { 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 {