optimize: 优化相关功能日志打印.

pull/161/head
chen.ma 3 years ago
parent d7fb126ea0
commit 82256ea5e7

@ -17,12 +17,14 @@ public class CommonThreadPool {
public static ThreadPoolExecutor getInstance(String threadPoolId) { public static ThreadPoolExecutor getInstance(String threadPoolId) {
ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder() ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder()
.isCustomPool(true)
.threadFactory(threadPoolId) .threadFactory(threadPoolId)
.poolThreadNum(3, 5) .poolThreadSize(3, 5)
.keepAliveTime(1000L, TimeUnit.SECONDS) .keepAliveTime(1000L, TimeUnit.SECONDS)
.rejected(RejectedPolicies.runsOldestTaskPolicy()) .rejected(RejectedPolicies.runsOldestTaskPolicy())
.workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, 512) .workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, 512)
.build(); .build();
return poolExecutor; return poolExecutor;
} }
} }

@ -20,21 +20,25 @@ public class ThreadPoolDynamicRefresh {
public static void refreshDynamicPool(String content) { public static void refreshDynamicPool(String content) {
PoolParameterInfo parameter = JSON.parseObject(content, PoolParameterInfo.class); PoolParameterInfo parameter = JSON.parseObject(content, PoolParameterInfo.class);
String tpId = parameter.getTpId(); String tpId = parameter.getTpId();
Integer coreSize, maxSize, queueType, capacity, keepAliveTime; Integer coreSize = parameter.getCoreSize(), maxSize = parameter.getMaxSize(),
log.info("[🔥] Start refreshing configuration. tpId :: {}, coreSize :: {}, maxSize :: {}, queueType :: {}, capacity :: {}, keepAliveTime :: {}", queueType = parameter.getQueueType(), capacity = parameter.getCapacity(),
tpId, coreSize = parameter.getCoreSize(), maxSize = parameter.getMaxSize(), keepAliveTime = parameter.getKeepAliveTime();
queueType = parameter.getQueueType(), capacity = parameter.getCapacity(), keepAliveTime = parameter.getKeepAliveTime());
refreshDynamicPool(tpId, coreSize, maxSize, queueType, capacity, keepAliveTime); refreshDynamicPool(tpId, coreSize, maxSize, queueType, capacity, keepAliveTime);
} }
public static void refreshDynamicPool(String threadPoolId, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Integer keepAliveTime) { public static void refreshDynamicPool(String threadPoolId, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Integer keepAliveTime) {
ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool(); ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool();
log.info("[✈️] Original thread pool. coreSize :: {}, maxSize :: {}, queueType :: {}, capacity :: {}, keepAliveTime :: {}", printLog("[🔥] Original thread pool. ",
executor.getCorePoolSize(), executor.getMaximumPoolSize(), queueType, executor.getQueue().remainingCapacity(), executor.getKeepAliveTime(TimeUnit.MILLISECONDS)); executor.getCorePoolSize(), executor.getMaximumPoolSize(), queueType, executor.getQueue().remainingCapacity(), executor.getKeepAliveTime(TimeUnit.MILLISECONDS));
ThreadPoolChangeHandler.changePool(executor, coreSize, maxSize, queueType, capacity, keepAliveTime); ThreadPoolChangeHandler.changePool(executor, coreSize, maxSize, queueType, capacity, keepAliveTime);
ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool(); ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getPool();
log.info("[🚀] Changed thread pool. coreSize :: {}, maxSize :: {}, queueType :: {}, capacity :: {}, keepAliveTime :: {}",
printLog("[🚀] Changed thread pool. ",
afterExecutor.getCorePoolSize(), afterExecutor.getMaximumPoolSize(), queueType, afterExecutor.getQueue().remainingCapacity(), afterExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS)); afterExecutor.getCorePoolSize(), afterExecutor.getMaximumPoolSize(), queueType, afterExecutor.getQueue().remainingCapacity(), afterExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS));
} }
private static void printLog(String prefixMsg, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Long keepAliveTime) {
log.info("{} coreSize :: {}, maxSize :: {}, queueType :: {}, capacity :: {}, keepAliveTime :: {}", prefixMsg, coreSize, maxSize, queueType, capacity, keepAliveTime);
}
} }

@ -118,7 +118,10 @@ public class ClientWorker {
List<String> changedTpIds = checkUpdateDataIds(queryCacheDataList); List<String> changedTpIds = checkUpdateDataIds(queryCacheDataList);
if (!CollectionUtils.isEmpty(changedTpIds)) { if (!CollectionUtils.isEmpty(changedTpIds)) {
log.info("[dynamic threadPool] tpIds changed :: {}", changedTpIds); /**
*
* log.info("[dynamic threadPool] tpIds changed :: {}", changedTpIds);
*/
for (String each : changedTpIds) { for (String each : changedTpIds) {
String[] keys = StrUtil.split(each, Constants.GROUP_KEY_DELIMITER); String[] keys = StrUtil.split(each, Constants.GROUP_KEY_DELIMITER);
String tpId = keys[0]; String tpId = keys[0];
@ -131,8 +134,10 @@ public class ClientWorker {
String poolContent = ContentUtil.getPoolContent(JSON.parseObject(content, PoolParameterInfo.class)); String poolContent = ContentUtil.getPoolContent(JSON.parseObject(content, PoolParameterInfo.class));
cacheData.setContent(poolContent); cacheData.setContent(poolContent);
cacheDataList.add(cacheData); cacheDataList.add(cacheData);
log.info("[data-received] namespace :: {}, itemId :: {}, tpId :: {}, md5 :: {}", /**
namespace, itemId, tpId, cacheData.getMd5()); *
* log.info("[data-received] namespace :: {}, itemId :: {}, tpId :: {}, md5 :: {}", namespace, itemId, tpId, cacheData.getMd5());
*/
} catch (Exception ex) { } catch (Exception ex) {
// ignore // ignore
} }
@ -184,9 +189,11 @@ public class ClientWorker {
try { try {
long readTimeoutMs = timeout + (long) Math.round(timeout >> 1); long readTimeoutMs = timeout + (long) Math.round(timeout >> 1);
Result result = agent.httpPost(Constants.LISTENER_PATH, headers, params, readTimeoutMs); Result result = agent.httpPost(Constants.LISTENER_PATH, headers, params, readTimeoutMs);
if (result == null || result.isFail()) { /**
log.warn("[check-update] get changed dataId error, code: {}", result == null ? "error" : result.getCode()); *
} else { * log.warn("[check-update] get changed dataId error, code: {}", result == null ? "error" : result.getCode());
*/
if (result != null && result.isSuccess()) {
setHealthServer(true); setHealthServer(true);
return parseUpdateDataIdResponse(result.getData().toString()); return parseUpdateDataIdResponse(result.getData().toString());
} }

Loading…
Cancel
Save