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 2323import java .util .List ;
2424import java .util .Map ;
2525import java .util .Objects ;
26+ import java .util .Random ;
2627import java .util .concurrent .ConcurrentHashMap ;
2728
2829import org .apache .servicecomb .http .client .task .AbstractTask ;
@@ -101,6 +102,8 @@ public static class SubscriptionValue {
101102
102103 private final Object lock = new Object ();
103104
105+ private final Random random = new Random ();
106+
104107 public ServiceCenterDiscovery (ServiceCenterClient serviceCenterClient , EventBus eventBus ) {
105108 super ("service-center-discovery-task" );
106109 this .serviceCenterClient = serviceCenterClient ;
@@ -219,10 +222,17 @@ class PullInstanceTask implements Task {
219222 public void execute () {
220223 pullAllInstance ();
221224
222- startTask (new BackOffSleepTask (pollInterval , new PullInstanceTask ()));
225+ startTask (new BackOffSleepTask (buildPollIntervalWithSalt () , new PullInstanceTask ()));
223226 }
224227 }
225228
229+ private long buildPollIntervalWithSalt () {
230+ int positive = random .nextInt (5 );
231+ int sign = random .nextBoolean () ? 1 : -1 ;
232+ long currentPollInterval = pollInterval + sign * positive * 1000 ;
233+ return currentPollInterval > 0 ? currentPollInterval : pollInterval ;
234+ }
235+
226236 class PullInstanceOnceTask implements Task {
227237 @ Override
228238 public void execute () {
You can’t perform that action at this time.
0 commit comments