Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.servicecomb.http.client.task.AbstractTask;
Expand Down Expand Up @@ -101,6 +102,8 @@ public static class SubscriptionValue {

private final Object lock = new Object();

private final Random random = new Random();

public ServiceCenterDiscovery(ServiceCenterClient serviceCenterClient, EventBus eventBus) {
super("service-center-discovery-task");
this.serviceCenterClient = serviceCenterClient;
Expand Down Expand Up @@ -219,10 +222,17 @@ class PullInstanceTask implements Task {
public void execute() {
pullAllInstance();

startTask(new BackOffSleepTask(pollInterval, new PullInstanceTask()));
startTask(new BackOffSleepTask(buildPollIntervalWithSalt(), new PullInstanceTask()));
}
}

private long buildPollIntervalWithSalt() {
int positive = random.nextInt(5);
int sign = random.nextBoolean() ? 1 : -1;
long currentPollInterval = pollInterval + sign * positive * 1000;
return currentPollInterval > 0 ? currentPollInterval : pollInterval;
}

class PullInstanceOnceTask implements Task {
@Override
public void execute() {
Expand Down
Loading