Skip to content

Commit

Permalink
Revert "[#3368]Cancel empty Long polling thread to improve performanc…
Browse files Browse the repository at this point in the history
…e. (#ISSUE3432)"

This reverts commit 95c8bf2.
  • Loading branch information
yanlinly authored Sep 8, 2020
1 parent d84d1a8 commit 87b8602
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.alibaba.nacos.client.utils.TenantUtil;
import com.alibaba.nacos.common.http.HttpRestResult;
import com.alibaba.nacos.common.lifecycle.Closeable;
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
import com.alibaba.nacos.common.utils.ConvertUtils;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.common.utils.StringUtils;
Expand Down Expand Up @@ -166,7 +165,6 @@ private void removeCache(String dataId, String group) {
copy.remove(groupKey);
cacheMap.set(copy);
}
reMakeCacheDataTaskId();
LOGGER.info("[{}] [unsubscribe] {}", this.agent.getName(), groupKey);

MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
Expand All @@ -179,38 +177,11 @@ void removeCache(String dataId, String group, String tenant) {
copy.remove(groupKey);
cacheMap.set(copy);
}
reMakeCacheDataTaskId();
LOGGER.info("[{}] [unsubscribe] {}", agent.getName(), groupKey);

MetricsMonitor.getListenConfigCountMonitor().set(cacheMap.get().size());
}

/**
* Remake cacheData taskId.
*/
private void reMakeCacheDataTaskId() {
int listenerSize = cacheMap.get().size();
int remakeTaskId = (int) Math.ceil(listenerSize / ParamUtil.getPerTaskConfigSize());
if (remakeTaskId < (int) currentLongingTaskCount) {
for (int i = 0; i < remakeTaskId; i++) {
int count = 0;
for (String key : cacheMap.get().keySet()) {
if (count == ParamUtil.getPerTaskConfigSize()) {
break;
}
CacheData cacheData = cacheMap.get().get(key);
cacheData.setTaskId(i);
synchronized (cacheMap) {
Map<String, CacheData> copy = new HashMap<String, CacheData>(this.cacheMap.get());
copy.put(key, cacheData);
cacheMap.set(copy);
}
count++;
}
}
}
}

/**
* Add cache data if absent.
*
Expand Down Expand Up @@ -277,8 +248,6 @@ public CacheData addCacheDataIfAbsent(String dataId, String group, String tenant
cache.setInitializing(true);
} else {
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
int taskId = cacheMap.get().size() / (int) ParamUtil.getPerTaskConfigSize();
cache.setTaskId(taskId);
// fix issue # 1317
if (enableRemoteSyncConfig) {
String[] ct = getServerConfig(dataId, group, tenant, 3000L);
Expand Down Expand Up @@ -425,16 +394,11 @@ public void checkConfigInfo() {
int longingTaskCount = (int) Math.ceil(listenerSize / ParamUtil.getPerTaskConfigSize());
if (longingTaskCount > currentLongingTaskCount) {
for (int i = (int) currentLongingTaskCount; i < longingTaskCount; i++) {
taskIdSet.add(i);
// The task list is no order.So it maybe has issues when changing.
executorService.execute(new LongPollingRunnable(i));
}
} else if (longingTaskCount < currentLongingTaskCount) {
for (int i = longingTaskCount; i < (int) currentLongingTaskCount; i++) {
taskIdSet.remove(i);
}
currentLongingTaskCount = longingTaskCount;
}
currentLongingTaskCount = longingTaskCount;
}

/**
Expand Down Expand Up @@ -692,9 +656,7 @@ public void run() {
}
inInitializingCacheList.clear();

if (taskIdSet.contains(taskId)) {
executorService.execute(this);
}
executorService.execute(this);

} catch (Throwable e) {

Expand Down Expand Up @@ -723,11 +685,6 @@ private void setHealthServer(boolean isHealthServer) {
private final AtomicReference<Map<String, CacheData>> cacheMap = new AtomicReference<Map<String, CacheData>>(
new HashMap<String, CacheData>());

/**
* Store the running taskId.
*/
private final ConcurrentHashSet<Integer> taskIdSet = new ConcurrentHashSet<Integer>();

private final HttpAgent agent;

private final ConfigFilterChainManager configFilterChainManager;
Expand Down

This file was deleted.

0 comments on commit 87b8602

Please sign in to comment.