From d8806fd37d05ff0c1e952a525e2af6af976b2d72 Mon Sep 17 00:00:00 2001 From: dzdx Date: Sun, 7 Feb 2021 21:20:28 +0800 Subject: [PATCH] cache digest fixed rate --- .../data/bootstrap/DataServerConfig.java | 71 +++++++++++++------ .../server/data/timer/CacheDigestTask.java | 11 +-- .../bootstrap/SessionServerConfig.java | 2 +- .../bootstrap/SessionServerConfigBean.java | 10 +-- .../timertask/SessionCacheDigestTask.java | 15 ++-- 5 files changed, 70 insertions(+), 39 deletions(-) diff --git a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java index 071c524b1..b65f9b4bd 100644 --- a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java +++ b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java @@ -25,8 +25,6 @@ import java.util.Set; /** - * - * * @author qian.lqlq * @version $Id: DataServerBootstrapConfig.java, v 0.1 2017-12-06 20:50 qian.lqlq Exp $ */ @@ -111,12 +109,13 @@ public class DataServerConfig { private boolean enableTestApi = false; - private int cacheDigestIntervalSecs = 60 * 15; + private int cacheDigestIntervalMinutes = 15; private int cacheCountIntervalSecs = 30; /** * constructor + * * @param commonConfig */ public DataServerConfig(CommonConfig commonConfig) { @@ -143,7 +142,7 @@ public int getPort() { /** * Setter method for property port. * - * @param port value to be assigned to property port + * @param port value to be assigned to property port */ public void setPort(int port) { this.port = port; @@ -161,7 +160,7 @@ public int getSyncDataPort() { /** * Setter method for property syncDataPort. * - * @param syncDataPort value to be assigned to property syncDataPort + * @param syncDataPort value to be assigned to property syncDataPort */ public void setSyncDataPort(int syncDataPort) { this.syncDataPort = syncDataPort; @@ -179,7 +178,7 @@ public int getMetaServerPort() { /** * Setter method for property metaServerPort. * - * @param metaServerPort value to be assigned to property metaServerPort + * @param metaServerPort value to be assigned to property metaServerPort */ public void setMetaServerPort(int metaServerPort) { this.metaServerPort = metaServerPort; @@ -197,7 +196,7 @@ public int getHttpServerPort() { /** * Setter method for property httpServerPort. * - * @param httpServerPort value to be assigned to property httpServerPort + * @param httpServerPort value to be assigned to property httpServerPort */ public void setHttpServerPort(int httpServerPort) { this.httpServerPort = httpServerPort; @@ -215,7 +214,7 @@ public int getNotifyIntervalMs() { /** * Setter method for property notifyIntervalMs. * - * @param notifyIntervalMs value to be assigned to property notifyIntervalMs + * @param notifyIntervalMs value to be assigned to property notifyIntervalMs */ public void setNotifyIntervalMs(int notifyIntervalMs) { this.notifyIntervalMs = notifyIntervalMs; @@ -233,7 +232,7 @@ public int getNotifyTempDataIntervalMs() { /** * Setter method for property notifyTempDataIntervalMs. * - * @param notifyTempDataIntervalMs value to be assigned to property notifyTempDataIntervalMs + * @param notifyTempDataIntervalMs value to be assigned to property notifyTempDataIntervalMs */ public void setNotifyTempDataIntervalMs(int notifyTempDataIntervalMs) { this.notifyTempDataIntervalMs = notifyTempDataIntervalMs; @@ -251,7 +250,7 @@ public int getRpcTimeout() { /** * Setter method for property rpcTimeout. * - * @param rpcTimeout value to be assigned to property rpcTimeout + * @param rpcTimeout value to be assigned to property rpcTimeout */ public void setRpcTimeout(int rpcTimeout) { this.rpcTimeout = rpcTimeout; @@ -296,7 +295,7 @@ public long getGetDataExecutorKeepAliveTime() { /** * Setter method for property getDataExecutorMinPoolSize. * - * @param getDataExecutorMinPoolSize value to be assigned to property getDataExecutorMinPoolSize + * @param getDataExecutorMinPoolSize value to be assigned to property getDataExecutorMinPoolSize */ public void setGetDataExecutorMinPoolSize(int getDataExecutorMinPoolSize) { this.getDataExecutorMinPoolSize = getDataExecutorMinPoolSize; @@ -305,7 +304,7 @@ public void setGetDataExecutorMinPoolSize(int getDataExecutorMinPoolSize) { /** * Setter method for property getDataExecutorMaxPoolSize. * - * @param getDataExecutorMaxPoolSize value to be assigned to property getDataExecutorMaxPoolSize + * @param getDataExecutorMaxPoolSize value to be assigned to property getDataExecutorMaxPoolSize */ public void setGetDataExecutorMaxPoolSize(int getDataExecutorMaxPoolSize) { this.getDataExecutorMaxPoolSize = getDataExecutorMaxPoolSize; @@ -314,7 +313,7 @@ public void setGetDataExecutorMaxPoolSize(int getDataExecutorMaxPoolSize) { /** * Setter method for property getDataExecutorQueueSize. * - * @param getDataExecutorQueueSize value to be assigned to property getDataExecutorQueueSize + * @param getDataExecutorQueueSize value to be assigned to property getDataExecutorQueueSize */ public void setGetDataExecutorQueueSize(int getDataExecutorQueueSize) { this.getDataExecutorQueueSize = getDataExecutorQueueSize; @@ -323,7 +322,7 @@ public void setGetDataExecutorQueueSize(int getDataExecutorQueueSize) { /** * Setter method for property getDataExecutorKeepAliveTime. * - * @param getDataExecutorKeepAliveTime value to be assigned to property getDataExecutorKeepAliveTime + * @param getDataExecutorKeepAliveTime value to be assigned to property getDataExecutorKeepAliveTime */ public void setGetDataExecutorKeepAliveTime(long getDataExecutorKeepAliveTime) { this.getDataExecutorKeepAliveTime = getDataExecutorKeepAliveTime; @@ -341,7 +340,7 @@ public int getPublishExecutorMinPoolSize() { /** * Setter method for property publishExecutorMinPoolSize. * - * @param publishExecutorMinPoolSize value to be assigned to property publishExecutorMinPoolSize + * @param publishExecutorMinPoolSize value to be assigned to property publishExecutorMinPoolSize */ public void setPublishExecutorMinPoolSize(int publishExecutorMinPoolSize) { this.publishExecutorMinPoolSize = publishExecutorMinPoolSize; @@ -359,7 +358,7 @@ public int getPublishExecutorMaxPoolSize() { /** * Setter method for property publishExecutorMaxPoolSize. * - * @param publishExecutorMaxPoolSize value to be assigned to property publishExecutorMaxPoolSize + * @param publishExecutorMaxPoolSize value to be assigned to property publishExecutorMaxPoolSize */ public void setPublishExecutorMaxPoolSize(int publishExecutorMaxPoolSize) { this.publishExecutorMaxPoolSize = publishExecutorMaxPoolSize; @@ -377,7 +376,7 @@ public int getPublishExecutorQueueSize() { /** * Setter method for property publishExecutorQueueSize. * - * @param publishExecutorQueueSize value to be assigned to property publishExecutorQueueSize + * @param publishExecutorQueueSize value to be assigned to property publishExecutorQueueSize */ public void setPublishExecutorQueueSize(int publishExecutorQueueSize) { this.publishExecutorQueueSize = publishExecutorQueueSize; @@ -400,6 +399,7 @@ public Set getMetaServerIpAddresses() { /** * Getter method for property sessionLeaseSec. + * * @return property value of sessionLeaseSec */ public int getSessionLeaseSec() { @@ -408,6 +408,7 @@ public int getSessionLeaseSec() { /** * Setter method for property sessionLeaseSec. + * * @param sessionLeaseSec value to be assigned to property sessionLeaseSec */ public void setSessionLeaseSec(int sessionLeaseSec) { @@ -416,6 +417,7 @@ public void setSessionLeaseSec(int sessionLeaseSec) { /** * Getter method for property datumCompactDelayMs. + * * @return property value of datumCompactDelayMs */ public int getDatumCompactDelayMs() { @@ -424,6 +426,7 @@ public int getDatumCompactDelayMs() { /** * Setter method for property datumCompactDelayMs. + * * @param datumCompactDelayMs value to be assigned to property datumCompactDelayMs */ public void setDatumCompactDelayMs(int datumCompactDelayMs) { @@ -432,6 +435,7 @@ public void setDatumCompactDelayMs(int datumCompactDelayMs) { /** * Getter method for property slotSyncPublisherDigestMaxNum. + * * @return property value of slotSyncPublisherDigestMaxNum */ public int getSlotSyncPublisherDigestMaxNum() { @@ -440,6 +444,7 @@ public int getSlotSyncPublisherDigestMaxNum() { /** * Setter method for property slotSyncPublisherDigestMaxNum. + * * @param slotSyncPublisherDigestMaxNum value to be assigned to property slotSyncPublisherDigestMaxNum */ public void setSlotSyncPublisherDigestMaxNum(int slotSyncPublisherDigestMaxNum) { @@ -448,6 +453,7 @@ public void setSlotSyncPublisherDigestMaxNum(int slotSyncPublisherDigestMaxNum) /** * Getter method for property slotSyncPublisherMaxNum. + * * @return property value of slotSyncPublisherMaxNum */ public int getSlotSyncPublisherMaxNum() { @@ -456,6 +462,7 @@ public int getSlotSyncPublisherMaxNum() { /** * Setter method for property slotSyncPublisherMaxNum. + * * @param slotSyncPublisherMaxNum value to be assigned to property slotSyncPublisherMaxNum */ public void setSlotSyncPublisherMaxNum(int slotSyncPublisherMaxNum) { @@ -464,6 +471,7 @@ public void setSlotSyncPublisherMaxNum(int slotSyncPublisherMaxNum) { /** * Getter method for property slotLeaderSyncSessionExecutorThreadSize. + * * @return property value of slotLeaderSyncSessionExecutorThreadSize */ public int getSlotLeaderSyncSessionExecutorThreadSize() { @@ -472,6 +480,7 @@ public int getSlotLeaderSyncSessionExecutorThreadSize() { /** * Setter method for property slotLeaderSyncSessionExecutorThreadSize. + * * @param slotLeaderSyncSessionExecutorThreadSize value to be assigned to property slotLeaderSyncSessionExecutorThreadSize */ public void setSlotLeaderSyncSessionExecutorThreadSize(int slotLeaderSyncSessionExecutorThreadSize) { @@ -480,6 +489,7 @@ public void setSlotLeaderSyncSessionExecutorThreadSize(int slotLeaderSyncSession /** * Getter method for property slotLeaderSyncSessionIntervalMs. + * * @return property value of slotLeaderSyncSessionIntervalMs */ public int getSlotLeaderSyncSessionIntervalSec() { @@ -488,6 +498,7 @@ public int getSlotLeaderSyncSessionIntervalSec() { /** * Setter method for property slotLeaderSyncSessionIntervalSec. + * * @param slotLeaderSyncSessionIntervalSec value to be assigned to property slotLeaderSyncSessionIntervalSec */ public void setSlotLeaderSyncSessionIntervalSec(int slotLeaderSyncSessionIntervalSec) { @@ -496,6 +507,7 @@ public void setSlotLeaderSyncSessionIntervalSec(int slotLeaderSyncSessionInterva /** * Getter method for property slotFollowerSyncLeaderExecutorThreadSize. + * * @return property value of slotFollowerSyncLeaderExecutorThreadSize */ public int getSlotFollowerSyncLeaderExecutorThreadSize() { @@ -504,6 +516,7 @@ public int getSlotFollowerSyncLeaderExecutorThreadSize() { /** * Setter method for property slotFollowerSyncLeaderExecutorThreadSize. + * * @param slotFollowerSyncLeaderExecutorThreadSize value to be assigned to property slotFollowerSyncLeaderExecutorThreadSize */ public void setSlotFollowerSyncLeaderExecutorThreadSize(int slotFollowerSyncLeaderExecutorThreadSize) { @@ -512,6 +525,7 @@ public void setSlotFollowerSyncLeaderExecutorThreadSize(int slotFollowerSyncLead /** * Getter method for property slotFollowerSyncLeaderIntervalMs. + * * @return property value of slotFollowerSyncLeaderIntervalMs */ public int getSlotFollowerSyncLeaderIntervalMs() { @@ -520,6 +534,7 @@ public int getSlotFollowerSyncLeaderIntervalMs() { /** * Setter method for property slotFollowerSyncLeaderIntervalMs. + * * @param slotFollowerSyncLeaderIntervalMs value to be assigned to property slotFollowerSyncLeaderIntervalMs */ public void setSlotFollowerSyncLeaderIntervalMs(int slotFollowerSyncLeaderIntervalMs) { @@ -528,6 +543,7 @@ public void setSlotFollowerSyncLeaderIntervalMs(int slotFollowerSyncLeaderInterv /** * Getter method for property slotLeaderSyncSessionExecutorQueueSize. + * * @return property value of slotLeaderSyncSessionExecutorQueueSize */ public int getSlotLeaderSyncSessionExecutorQueueSize() { @@ -536,6 +552,7 @@ public int getSlotLeaderSyncSessionExecutorQueueSize() { /** * Setter method for property slotLeaderSyncSessionExecutorQueueSize. + * * @param slotLeaderSyncSessionExecutorQueueSize value to be assigned to property slotLeaderSyncSessionExecutorQueueSize */ public void setSlotLeaderSyncSessionExecutorQueueSize(int slotLeaderSyncSessionExecutorQueueSize) { @@ -544,6 +561,7 @@ public void setSlotLeaderSyncSessionExecutorQueueSize(int slotLeaderSyncSessionE /** * Getter method for property slotFollowerSyncLeaderExecutorQueueSize. + * * @return property value of slotFollowerSyncLeaderExecutorQueueSize */ public int getSlotFollowerSyncLeaderExecutorQueueSize() { @@ -552,6 +570,7 @@ public int getSlotFollowerSyncLeaderExecutorQueueSize() { /** * Setter method for property slotFollowerSyncLeaderExecutorQueueSize. + * * @param slotFollowerSyncLeaderExecutorQueueSize value to be assigned to property slotFollowerSyncLeaderExecutorQueueSize */ public void setSlotFollowerSyncLeaderExecutorQueueSize(int slotFollowerSyncLeaderExecutorQueueSize) { @@ -560,6 +579,7 @@ public void setSlotFollowerSyncLeaderExecutorQueueSize(int slotFollowerSyncLeade /** * Getter method for property slotSyncRequestExecutorMinPoolSize. + * * @return property value of slotSyncRequestExecutorMinPoolSize */ public int getSlotSyncRequestExecutorMinPoolSize() { @@ -568,6 +588,7 @@ public int getSlotSyncRequestExecutorMinPoolSize() { /** * Setter method for property slotSyncRequestExecutorMinPoolSize. + * * @param slotSyncRequestExecutorMinPoolSize value to be assigned to property slotSyncRequestExecutorMinPoolSize */ public void setSlotSyncRequestExecutorMinPoolSize(int slotSyncRequestExecutorMinPoolSize) { @@ -576,6 +597,7 @@ public void setSlotSyncRequestExecutorMinPoolSize(int slotSyncRequestExecutorMin /** * Getter method for property slotSyncRequestExecutorMaxPoolSize. + * * @return property value of slotSyncRequestExecutorMaxPoolSize */ public int getSlotSyncRequestExecutorMaxPoolSize() { @@ -584,6 +606,7 @@ public int getSlotSyncRequestExecutorMaxPoolSize() { /** * Setter method for property slotSyncRequestExecutorMaxPoolSize. + * * @param slotSyncRequestExecutorMaxPoolSize value to be assigned to property slotSyncRequestExecutorMaxPoolSize */ public void setSlotSyncRequestExecutorMaxPoolSize(int slotSyncRequestExecutorMaxPoolSize) { @@ -592,6 +615,7 @@ public void setSlotSyncRequestExecutorMaxPoolSize(int slotSyncRequestExecutorMax /** * Getter method for property slotSyncRequestExecutorQueueSize. + * * @return property value of slotSyncRequestExecutorQueueSize */ public int getSlotSyncRequestExecutorQueueSize() { @@ -600,6 +624,7 @@ public int getSlotSyncRequestExecutorQueueSize() { /** * Setter method for property slotSyncRequestExecutorQueueSize. + * * @param slotSyncRequestExecutorQueueSize value to be assigned to property slotSyncRequestExecutorQueueSize */ public void setSlotSyncRequestExecutorQueueSize(int slotSyncRequestExecutorQueueSize) { @@ -608,6 +633,7 @@ public void setSlotSyncRequestExecutorQueueSize(int slotSyncRequestExecutorQueue /** * Getter method for property schedulerHeartbeatIntervalSec. + * * @return property value of schedulerHeartbeatIntervalSec */ public int getSchedulerHeartbeatIntervalSec() { @@ -616,6 +642,7 @@ public int getSchedulerHeartbeatIntervalSec() { /** * Setter method for property schedulerHeartbeatIntervalSec. + * * @param schedulerHeartbeatIntervalSec value to be assigned to property schedulerHeartbeatIntervalSec */ public void setSchedulerHeartbeatIntervalSec(int schedulerHeartbeatIntervalSec) { @@ -624,6 +651,7 @@ public void setSchedulerHeartbeatIntervalSec(int schedulerHeartbeatIntervalSec) /** * Getter method for property syncSessionPort. + * * @return property value of syncSessionPort */ public int getSyncSessionPort() { @@ -632,6 +660,7 @@ public int getSyncSessionPort() { /** * Setter method for property syncSessionPort. + * * @param syncSessionPort value to be assigned to property syncSessionPort */ public void setSyncSessionPort(int syncSessionPort) { @@ -702,12 +731,12 @@ public void setNotifyRetryTimes(int notifyRetryTimes) { this.notifyRetryTimes = notifyRetryTimes; } - public int getCacheDigestIntervalSecs() { - return cacheDigestIntervalSecs; + public int getCacheDigestIntervalMinutes() { + return cacheDigestIntervalMinutes; } - public void setCacheDigestIntervalSecs(int cacheDigestIntervalSecs) { - this.cacheDigestIntervalSecs = cacheDigestIntervalSecs; + public void setCacheDigestIntervalMinutes(int cacheDigestIntervalMinutes) { + this.cacheDigestIntervalMinutes = cacheDigestIntervalMinutes; } public int getCacheCountIntervalSecs() { diff --git a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/timer/CacheDigestTask.java b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/timer/CacheDigestTask.java index 0b89bd800..a0646707f 100644 --- a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/timer/CacheDigestTask.java +++ b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/timer/CacheDigestTask.java @@ -48,14 +48,15 @@ public class CacheDigestTask { @PostConstruct public void init() { - final int intervalSec = dataServerConfig.getCacheDigestIntervalSecs(); - if (intervalSec <= 0) { - LOGGER.info("cache digest off with intervalSecs={}", intervalSec); + final int intervalMinutes = dataServerConfig.getCacheDigestIntervalMinutes(); + if (intervalMinutes <= 0) { + LOGGER.info("cache digest off with intervalMinutes={}", intervalMinutes); return; } Date firstDate = new Date(); firstDate = DateUtils.round(firstDate, Calendar.MINUTE); - firstDate.setMinutes(firstDate.getMinutes() / 5 * 5 + 5); + firstDate.setMinutes(firstDate.getMinutes() / intervalMinutes * intervalMinutes + + intervalMinutes); Timer timer = new Timer("CacheDigestTask", true); TimerTask task = new TimerTask() { @Override @@ -63,7 +64,7 @@ public void run() { dump(); } }; - timer.scheduleAtFixedRate(task, firstDate, intervalSec * 1000); + timer.scheduleAtFixedRate(task, firstDate, intervalMinutes * 60 * 1000); } private void dump() { diff --git a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfig.java b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfig.java index 932dd96c2..5dc65ae26 100644 --- a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfig.java +++ b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfig.java @@ -133,7 +133,7 @@ public interface SessionServerConfig { int getSlotSyncWorkerSize(); - int getCacheDigestIntervalSecs(); + int getCacheDigestIntervalMinutes(); int getCacheCountIntervalSecs(); } \ No newline at end of file diff --git a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfigBean.java b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfigBean.java index e1e03e1a5..30d5d51d1 100644 --- a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfigBean.java +++ b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/bootstrap/SessionServerConfigBean.java @@ -153,7 +153,7 @@ public class SessionServerConfigBean implements SessionServerConfig { private boolean enableSessionLoadbalancePolicy = false; - private int cacheDigestIntervalSecs = 60 * 15; + private int cacheDigestIntervalMinutes = 15; private int cacheCountIntervalSecs = 30; @@ -964,12 +964,12 @@ public int getSlotSyncWorkerSize() { } @Override - public int getCacheDigestIntervalSecs() { - return cacheDigestIntervalSecs; + public int getCacheDigestIntervalMinutes() { + return cacheDigestIntervalMinutes; } - public void setCacheDigestIntervalSecs(int cacheDigestIntervalSecs) { - this.cacheDigestIntervalSecs = cacheDigestIntervalSecs; + public void setCacheDigestIntervalMinutes(int cacheDigestIntervalMinutes) { + this.cacheDigestIntervalMinutes = cacheDigestIntervalMinutes; } public void setSlotSyncWorkerSize(int slotSyncWorkerSize) { diff --git a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/scheduler/timertask/SessionCacheDigestTask.java b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/scheduler/timertask/SessionCacheDigestTask.java index f9f870ba7..98e4f1348 100644 --- a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/scheduler/timertask/SessionCacheDigestTask.java +++ b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/scheduler/timertask/SessionCacheDigestTask.java @@ -43,24 +43,25 @@ public class SessionCacheDigestTask { private static final Logger LOGGER = LoggerFactory.getLogger("CACHE-DIGEST"); @Autowired - private DataStore sessionDataStore; + private DataStore sessionDataStore; @Autowired - private Interests sessionInterests; + private Interests sessionInterests; @Autowired private SessionServerConfig sessionServerConfig; @PostConstruct public void init() { - final int intervalSec = sessionServerConfig.getCacheDigestIntervalSecs(); - if (intervalSec <= 0) { - LOGGER.info("cache digest off with intervalSec={}", intervalSec); + final int intervalMinutes = sessionServerConfig.getCacheDigestIntervalMinutes(); + if (intervalMinutes <= 0) { + LOGGER.info("cache digest off with intervalMinutes={}", intervalMinutes); return; } Date firstDate = new Date(); firstDate = DateUtils.round(firstDate, Calendar.MINUTE); - firstDate.setMinutes(firstDate.getMinutes() / 5 * 5 + 5); + firstDate.setMinutes(firstDate.getMinutes() / intervalMinutes * intervalMinutes + + intervalMinutes); Timer timer = new Timer("CacheDigestTask", true); TimerTask task = new TimerTask() { @Override @@ -68,7 +69,7 @@ public void run() { dump(); } }; - timer.scheduleAtFixedRate(task, firstDate, intervalSec * 1000); + timer.scheduleAtFixedRate(task, firstDate, intervalMinutes * 60 * 1000); } private void dump() {