You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/08/06 03:05:56 UTC

[servicecomb-java-chassis] branch master updated: [SCB-2313]make service center client pull interval configurable (#2493)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new a6c047c  [SCB-2313]make service center client pull interval configurable (#2493)
a6c047c is described below

commit a6c047c516ac5680b72216849ef1e27236efab19
Author: liubao68 <bi...@qq.com>
AuthorDate: Fri Aug 6 11:05:49 2021 +0800

    [SCB-2313]make service center client pull interval configurable (#2493)
    
    * [SCB-2313]make service center client pull interval configurable
    
    * [SCB-2313]fix method error
---
 .../center/client/ServiceCenterDiscovery.java      | 21 +++++++++---
 .../center/client/ServiceCenterRegistration.java   | 38 ++++++++++++++++++----
 .../properties/GovernanceProperties.java           |  2 +-
 3 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterDiscovery.java b/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterDiscovery.java
index aaac3f0..625db29 100644
--- a/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterDiscovery.java
+++ b/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterDiscovery.java
@@ -38,11 +38,12 @@ import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
 
 public class ServiceCenterDiscovery extends AbstractTask {
-  private static final String ALL_VERSION = "0+";
 
-  private static final long POLL_INTERVAL = 15000;
+  public static final int MAX_INTERVAL = 600000;
 
-  private boolean started = false;
+  public static final int MIN_INTERVAL = 1000;
+
+  private static final String ALL_VERSION = "0+";
 
   public static class SubscriptionKey {
     final String appId;
@@ -93,6 +94,10 @@ public class ServiceCenterDiscovery extends AbstractTask {
 
   private final Map<String, Microservice> microserviceCache = new ConcurrentHashMap<>();
 
+  private long pollInterval = 15000;
+
+  private boolean started = false;
+
   public ServiceCenterDiscovery(ServiceCenterClient serviceCenterClient, EventBus eventBus) {
     super("service-center-discovery-task");
     this.serviceCenterClient = serviceCenterClient;
@@ -100,6 +105,14 @@ public class ServiceCenterDiscovery extends AbstractTask {
     this.eventBus.register(this);
   }
 
+  public ServiceCenterDiscovery setPollInterval(long interval) {
+    if (interval > MAX_INTERVAL || interval < MIN_INTERVAL) {
+      return this;
+    }
+    this.pollInterval = interval;
+    return this;
+  }
+
   public void updateMyselfServiceId(String myselfServiceId) {
     this.myselfServiceId = myselfServiceId;
   }
@@ -183,7 +196,7 @@ public class ServiceCenterDiscovery extends AbstractTask {
     public void execute() {
       pullAllInstance();
 
-      startTask(new BackOffSleepTask(POLL_INTERVAL, new PullInstanceTask()));
+      startTask(new BackOffSleepTask(pollInterval, new PullInstanceTask()));
     }
   }
 
diff --git a/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterRegistration.java b/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterRegistration.java
index a10f7e6..0786feb 100644
--- a/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterRegistration.java
+++ b/clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterRegistration.java
@@ -39,8 +39,13 @@ import org.slf4j.LoggerFactory;
 import com.google.common.eventbus.EventBus;
 
 public class ServiceCenterRegistration extends AbstractTask {
+
   private static final Logger LOGGER = LoggerFactory.getLogger(ServiceCenterRegistration.class);
 
+  public static final int MAX_INTERVAL = 600000;
+
+  public static final int MIN_INTERVAL = 1000;
+
   private final ServiceCenterClient serviceCenterClient;
 
   private final EventBus eventBus;
@@ -53,6 +58,10 @@ public class ServiceCenterRegistration extends AbstractTask {
 
   private ServiceCenterConfiguration serviceCenterConfiguration;
 
+  private long heartBeatInterval = 15000;
+
+  private long heartBeatRequestTimeout = 5000;
+
   public ServiceCenterRegistration(ServiceCenterClient serviceCenterClient, ServiceCenterConfiguration
       serviceCenterConfiguration, EventBus eventBus) {
     super("service-center-registration-task");
@@ -61,16 +70,35 @@ public class ServiceCenterRegistration extends AbstractTask {
     this.eventBus = eventBus;
   }
 
-  public void setMicroserviceInstance(MicroserviceInstance microserviceInstance) {
+  public ServiceCenterRegistration setMicroserviceInstance(MicroserviceInstance microserviceInstance) {
     this.microserviceInstance = microserviceInstance;
+    return this;
   }
 
-  public void setMicroservice(Microservice microservice) {
+  public ServiceCenterRegistration setMicroservice(Microservice microservice) {
     this.microservice = microservice;
+    return this;
   }
 
-  public void setSchemaInfos(List<SchemaInfo> schemaInfos) {
+  public ServiceCenterRegistration setHeartBeatInterval(long interval) {
+    if (interval > MAX_INTERVAL || interval < MIN_INTERVAL) {
+      return this;
+    }
+    this.heartBeatInterval = interval;
+    return this;
+  }
+
+  public ServiceCenterRegistration setHeartBeatRequestTimeout(long timeout) {
+    if (timeout > MAX_INTERVAL || timeout < MIN_INTERVAL) {
+      return this;
+    }
+    this.heartBeatRequestTimeout = timeout;
+    return this;
+  }
+
+  public ServiceCenterRegistration setSchemaInfos(List<SchemaInfo> schemaInfos) {
     this.schemaInfos = schemaInfos;
+    return this;
   }
 
   public void startRegistration() {
@@ -213,10 +241,6 @@ public class ServiceCenterRegistration extends AbstractTask {
   class SendHeartBeatTask implements Task {
     final int failedRetry = 3;
 
-    final long heartBeatInterval = 30000;
-
-    final long heartBeatRequestTimeout = 5000;
-
     int failedCount;
 
     SendHeartBeatTask(int failedCount) {
diff --git a/governance/src/main/java/org/apache/servicecomb/governance/properties/GovernanceProperties.java b/governance/src/main/java/org/apache/servicecomb/governance/properties/GovernanceProperties.java
index 530f032..ef1d0d9 100644
--- a/governance/src/main/java/org/apache/servicecomb/governance/properties/GovernanceProperties.java
+++ b/governance/src/main/java/org/apache/servicecomb/governance/properties/GovernanceProperties.java
@@ -129,7 +129,7 @@ public abstract class GovernanceProperties<T extends Configurable> implements In
       return;
     }
 
-    LOGGER.warn("None EnumerablePropertySource ignored in {}, propertySourceName = [{}]", this.getClass().getName(),
+    LOGGER.debug("None EnumerablePropertySource ignored in {}, propertySourceName = [{}]", this.getClass().getName(),
         propertySource.getName());
   }