Skip to content

Commit

Permalink
When session receives a connection and generates renew tasks, it rand…
Browse files Browse the repository at this point in the history
…omly delays different times to avoid everyone launching renew at the same time.
  • Loading branch information
kezhu.wukz committed Jul 26, 2019
1 parent c30a58d commit 6cd814f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public interface SessionServerConfig {

int getRenewDatumWheelTicksDuration();

long getRenewDatumWheelTaskDelay();
int getRenewDatumWheelTaskDelaySec();

int getRenewDatumWheelTaskRandomFirstDelaySec();

String getBlacklistPubDataIdRegex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ public class SessionServerConfigBean implements SessionServerConfig {

private int renewDatumWheelTicksDuration = 500;

private long renewDatumWheelTaskDelay = 180;
private int renewDatumWheelTaskDelaySec = 180;

private int renewDatumWheelTaskRandomFirstDelaySec = 60;

private int pushDataTaskRetryFirstDelay = 500;

Expand Down Expand Up @@ -1689,21 +1691,39 @@ public int getRenewDatumWheelTicksDuration() {
}

/**
* Getter method for property <tt>renewDatumWheelTaskDelay</tt>.
* Getter method for property <tt>renewDatumWheelTaskDelaySec</tt>.
*
* @return property value of renewDatumWheelTaskDelaySec
*/
public int getRenewDatumWheelTaskDelaySec() {
return renewDatumWheelTaskDelaySec;
}

/**
* Setter method for property <tt>renewDatumWheelTaskDelaySec </tt>.
*
* @param renewDatumWheelTaskDelaySec value to be assigned to property renewDatumWheelTaskDelaySec
*/
public void setRenewDatumWheelTaskDelaySec(int renewDatumWheelTaskDelaySec) {
this.renewDatumWheelTaskDelaySec = renewDatumWheelTaskDelaySec;
}

/**
* Getter method for property <tt>renewDatumWheelTaskRandomFirstDelaySec</tt>.
*
* @return property value of renewDatumWheelTaskDelay
* @return property value of renewDatumWheelTaskRandomFirstDelaySec
*/
public long getRenewDatumWheelTaskDelay() {
return renewDatumWheelTaskDelay;
public int getRenewDatumWheelTaskRandomFirstDelaySec() {
return renewDatumWheelTaskRandomFirstDelaySec;
}

/**
* Setter method for property <tt>renewDatumWheelTaskDelay</tt>.
* Setter method for property <tt>renewDatumWheelTaskRandomFirstDelaySec </tt>.
*
* @param renewDatumWheelTaskDelay value to be assigned to property renewDatumWheelTaskDelay
* @param renewDatumWheelTaskRandomFirstDelaySec value to be assigned to property renewDatumWheelTaskRandomFirstDelaySec
*/
public void setRenewDatumWheelTaskDelay(long renewDatumWheelTaskDelay) {
this.renewDatumWheelTaskDelay = renewDatumWheelTaskDelay;
public void setRenewDatumWheelTaskRandomFirstDelaySec(int renewDatumWheelTaskRandomFirstDelaySec) {
this.renewDatumWheelTaskRandomFirstDelaySec = renewDatumWheelTaskRandomFirstDelaySec;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang.math.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alipay.sofa.registry.common.model.constants.ValueConstants;
Expand Down Expand Up @@ -132,7 +133,7 @@ private void fireRenewDatum(Channel channel) {
RENEW_LOGGER.info("Renew task is started: {}", connectId);
executorManager.getAsyncHashedWheelTimerTask()
.newTimeout(connectId, timerOut -> sessionRegistry.renewDatum(connectId),
sessionServerConfig.getRenewDatumWheelTaskDelay(), TimeUnit.SECONDS, () -> {
randomDelay() + sessionServerConfig.getRenewDatumWheelTaskDelaySec(), TimeUnit.SECONDS, () -> {
Server sessionServer = boltExchange.getServer(sessionServerConfig.getServerPort());
Channel channelClient = sessionServer.getChannel(URL.valueOf(connectId));
boolean shouldContinue = channelClient != null && channel.isConnected();
Expand All @@ -143,4 +144,9 @@ private void fireRenewDatum(Channel channel) {
});
});
}

private long randomDelay() {
return RandomUtils.nextInt(sessionServerConfig.getRenewDatumWheelTaskRandomFirstDelaySec());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ session.server.schedulerFetchDataExpBackOffBound=10
#session.server.invalidForeverZones=<zone1>;<zone2>
#session.server.invalidIgnoreDataidRegex=<Regex>
#session.server.pushEmptyDataDataIdPrefixes=<some prefix string>
session.server.renewDatumWheelTaskDelay=180
session.server.renewDatumWheelTaskDelaySec=180
session.server.renewDatumWheelTaskRandomFirstDelaySec=60

0 comments on commit 6cd814f

Please sign in to comment.