File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 2121import java .util .List ;
2222import java .util .Map ;
2323import java .util .Objects ;
24+ import java .util .Random ;
2425import java .util .concurrent .ConcurrentHashMap ;
2526
2627import org .apache .servicecomb .http .client .task .AbstractTask ;
@@ -99,6 +100,8 @@ public static class SubscriptionValue {
99100
100101 private final Object lock = new Object ();
101102
103+ private final Random random = new Random ();
104+
102105 public ServiceCenterDiscovery (ServiceCenterClient serviceCenterClient , EventBus eventBus ) {
103106 super ("service-center-discovery-task" );
104107 this .serviceCenterClient = serviceCenterClient ;
@@ -208,10 +211,17 @@ class PullInstanceTask implements Task {
208211 public void execute () {
209212 pullAllInstance ();
210213
211- startTask (new BackOffSleepTask (pollInterval , new PullInstanceTask ()));
214+ startTask (new BackOffSleepTask (buildPollIntervalWithSalt () , new PullInstanceTask ()));
212215 }
213216 }
214217
218+ private long buildPollIntervalWithSalt () {
219+ int positive = random .nextInt (5 );
220+ int sign = random .nextBoolean () ? 1 : -1 ;
221+ long currentPollInterval = pollInterval + sign * positive * 1000 ;
222+ return currentPollInterval > 0 ? currentPollInterval : pollInterval ;
223+ }
224+
215225 class PullInstanceOnceTask implements Task {
216226 @ Override
217227 public void execute () {
You can’t perform that action at this time.
0 commit comments