Merge pull request #485 from mabaiwan/develop

hippo4j-adapter code naming and log optimization
pull/442/head
小马哥 2 years ago committed by GitHub
commit 674ce2bc16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,7 +26,7 @@ import java.util.Map;
public interface ThreadPoolAdapterRegisterAction {
/**
* getThreadPoolAdapterCacheConfigs
* Get thread pool adapter cache configs.
*
* @param threadPoolAdapterMap
* @return List<ThreadPoolAdapterCacheConfig>
@ -34,7 +34,7 @@ public interface ThreadPoolAdapterRegisterAction {
List<ThreadPoolAdapterCacheConfig> getThreadPoolAdapterCacheConfigs(Map<String, ThreadPoolAdapter> threadPoolAdapterMap);
/**
* doRegister
* Do register.
*
* @param cacheConfigList
* @return

@ -9,15 +9,20 @@
</parent>
<artifactId>hippo4j-adapter-dubbo</artifactId>
<properties>
<dubbo.version>3.0.5</dubbo.version>
</properties>
<dependencies>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-adapter-base</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>3.0.5</version>
<version>${dubbo.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
@ -38,7 +43,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

@ -85,7 +85,7 @@ public class DubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationLis
int originalMaximumPoolSize = executor.getMaximumPoolSize();
executor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
executor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize());
log.info("[{}] Dubbo consumption thread pool parameter change. coreSize :: {}, maximumSize :: {}",
log.info("[{}] Dubbo consumption thread pool parameter change. coreSize: {}, maximumSize: {}",
threadPoolKey,
String.format(CHANGE_DELIMITER, originalCoreSize, executor.getCorePoolSize()),
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, executor.getMaximumPoolSize()));

@ -72,7 +72,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
result.setMaximumSize(threadPoolExecutor.getMaximumPoolSize());
return result;
}
log.warn("[{}] hystrix thread pool not found.", identify);
log.warn("[{}] Hystrix thread pool not found.", identify);
return result;
}
@ -88,14 +88,14 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
String threadPoolKey = threadPoolAdapterParameter.getThreadPoolKey();
ThreadPoolExecutor threadPoolExecutor = HYSTRIX_CONSUME_EXECUTOR.get(threadPoolKey);
if (threadPoolExecutor == null) {
log.warn("[{}] hystrix thread pool not found.", threadPoolKey);
log.warn("[{}] Hystrix thread pool not found.", threadPoolKey);
return false;
}
int originalCoreSize = threadPoolExecutor.getCorePoolSize();
int originalMaximumPoolSize = threadPoolExecutor.getMaximumPoolSize();
threadPoolExecutor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
threadPoolExecutor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize());
log.info("[{}] hystrix thread pool parameter change. coreSize :: {}, maximumSize :: {}",
log.info("[{}] Hystrix thread pool parameter change. coreSize: {}, maximumSize: {}",
threadPoolKey,
String.format(CHANGE_DELIMITER, originalCoreSize, threadPoolExecutor.getCorePoolSize()),
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, threadPoolExecutor.getMaximumPoolSize()));
@ -106,16 +106,13 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
public void onApplicationEvent(ApplicationStartedEvent event) {
ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler();
int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds();
// Periodically update the Hystrix thread pool
// Periodically update the Hystrix thread pool.
HystrixThreadPoolRefreshTask hystrixThreadPoolRefreshTask = new HystrixThreadPoolRefreshTask(scheduler, taskIntervalSeconds);
scheduler.schedule(hystrixThreadPoolRefreshTask, taskIntervalSeconds, TimeUnit.SECONDS);
// Periodically refresh registration
// Periodically refresh registration.
ThreadPoolAdapterRegisterAction threadPoolAdapterRegisterAction = ApplicationContextHolder.getBean(ThreadPoolAdapterRegisterAction.class);
Map<String, ? extends HystrixThreadPoolAdapter> beansOfType = ApplicationContextHolder.getBeansOfType(this.getClass());
Map<String, ThreadPoolAdapter> map = Maps.newHashMap(beansOfType);
ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler, taskIntervalSeconds, map, threadPoolAdapterRegisterAction);
scheduler.schedule(threadPoolAdapterRegisterTask, threadPoolAdapterScheduler.getTaskIntervalSeconds(), TimeUnit.SECONDS);
}
@ -143,8 +140,8 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
}
}
}
} catch (Exception e) {
log.error("Failed to get Hystrix thread pool.", e);
} catch (Exception ex) {
log.error("Failed to get Hystrix thread pool.", ex);
}
}
@ -230,8 +227,8 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
if (registerFlag) {
threadPoolAdapterRegisterAction.doRegister(cacheConfigList);
}
} catch (Exception e) {
log.error("Register Task Error", e);
} catch (Exception ex) {
log.error("Register task error.", ex);
} finally {
if (!scheduler.isShutdown()) {
scheduler.schedule(this, taskIntervalSeconds, TimeUnit.MILLISECONDS);

@ -32,7 +32,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

@ -91,13 +91,13 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
int originalMaximumPoolSize = threadPoolTaskExecutor.getMaximumPoolSize();
threadPoolTaskExecutor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize());
threadPoolTaskExecutor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
log.info("[{}] rabbitmq consumption thread pool parameter change. coreSize :: {}, maximumSize :: {}",
log.info("[{}] Rabbitmq consumption thread pool parameter change. coreSize: {}, maximumSize: {}",
threadPoolKey,
String.format(CHANGE_DELIMITER, originalCoreSize, threadPoolAdapterParameter.getCorePoolSize()),
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, threadPoolAdapterParameter.getMaximumPoolSize()));
return true;
}
log.warn("[{}] rabbitmq consuming thread pool not found.", threadPoolKey);
log.warn("[{}] Rabbitmq consuming thread pool not found.", threadPoolKey);
return false;
}
@ -108,7 +108,7 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPoolTaskExecutor = (ThreadPoolExecutor) executor;
RABBITMQ_THREAD_POOL_TASK_EXECUTOR.put(RABBITMQ_EXECUTOR_SERVICE, threadPoolTaskExecutor);
log.info("rabbitmq executor name {}", RABBITMQ_EXECUTOR_SERVICE);
log.info("Rabbitmq executor name {}", RABBITMQ_EXECUTOR_SERVICE);
} else {
log.warn("Custom thread pools only support ThreadPoolExecutor");
}

@ -38,7 +38,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

@ -80,7 +80,7 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize();
rocketMQConsumeExecutor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
rocketMQConsumeExecutor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize());
log.info("[{}] RocketMQ consumption thread pool parameter change. coreSize :: {}, maximumSize :: {}",
log.info("[{}] RocketMQ consumption thread pool parameter change. coreSize: {}, maximumSize: {}",
threadPoolKey,
String.format(CHANGE_DELIMITER, originalCoreSize, rocketMQConsumeExecutor.getCorePoolSize()),
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, rocketMQConsumeExecutor.getMaximumPoolSize()));
@ -96,9 +96,9 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
ApplicationContextHolder.getBeansOfType(DefaultRocketMQListenerContainer.class);
try {
for (DefaultRocketMQListenerContainer container : containerMap.values()) {
DefaultMQPushConsumer consumer = container.getConsumer();
if (consumer != null) {
ConsumeMessageService consumeMessageService = consumer.getDefaultMQPushConsumerImpl().getConsumeMessageService();
DefaultMQPushConsumer defaultMQPushConsumer = container.getConsumer();
if (defaultMQPushConsumer != null) {
ConsumeMessageService consumeMessageService = defaultMQPushConsumer.getDefaultMQPushConsumerImpl().getConsumeMessageService();
ThreadPoolExecutor consumeExecutor = (ThreadPoolExecutor) ReflectUtil.getFieldValue(consumeMessageService, "consumeExecutor");
ROCKET_MQ_CONSUME_EXECUTOR.put(container.getConsumerGroup(), consumeExecutor);
}
@ -106,6 +106,5 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
} catch (Exception ex) {
log.error("Failed to get RocketMQ thread pool.", ex);
}
}
}

@ -32,7 +32,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

@ -38,7 +38,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

@ -89,7 +89,7 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda
int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize();
rocketMQConsumeExecutor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
rocketMQConsumeExecutor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize());
log.info("[{}] RocketMQ consumption thread pool parameter change. coreSize :: {}, maximumSize :: {}",
log.info("[{}] RocketMQ consumption thread pool parameter change. coreSize: {}, maximumSize: {}",
threadPoolKey,
String.format(CHANGE_DELIMITER, originalCoreSize, rocketMQConsumeExecutor.getCorePoolSize()),
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, rocketMQConsumeExecutor.getMaximumPoolSize()));

@ -67,7 +67,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

@ -64,8 +64,7 @@ public abstract class AbstractWebThreadPoolService implements WebThreadPoolServi
public void run(ApplicationArguments args) {
try {
getWebThreadPool();
} catch (Exception ex) {
// ignore. Adaptation unit test.
} catch (Exception ignored) {
}
}
}

@ -89,7 +89,7 @@ public class JettyWebThreadPoolHandler extends AbstractWebThreadPoolService {
Integer maxSize = threadPoolParameterInfo.maximumPoolSizeAdapt();
jettyExecutor.setMinThreads(coreSize);
jettyExecutor.setMaxThreads(maxSize);
log.info("[JETTY] Changed web thread pool. corePoolSize :: [{}], maximumPoolSize :: [{}]",
log.info("[Jetty] Changed web thread pool. corePoolSize: [{}], maximumPoolSize: [{}]",
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, minThreads, jettyExecutor.getMinThreads()),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, maxThreads, jettyExecutor.getMaxThreads()));
} catch (Exception ex) {

@ -62,7 +62,7 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
} catch (Exception ex) {
cacheFlag.set(Boolean.TRUE);
EXCEPTION_MESSAGE = ex.getMessage();
log.error("Failed to get Tomcat thread pool. Message :: {}", EXCEPTION_MESSAGE);
log.error("Failed to get Tomcat thread pool. Message: {}", EXCEPTION_MESSAGE);
}
return tomcatExecutor;
}
@ -168,7 +168,7 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
tomcatThreadPoolExecutor.setCorePoolSize(threadPoolParameterInfo.corePoolSizeAdapt());
tomcatThreadPoolExecutor.setMaximumPoolSize(threadPoolParameterInfo.maximumPoolSizeAdapt());
tomcatThreadPoolExecutor.setKeepAliveTime(threadPoolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS);
log.info("[TOMCAT] Changed web thread pool. corePoolSize :: [{}], maximumPoolSize :: [{}], keepAliveTime :: [{}]",
log.info("[Tomcat] Changed web thread pool. corePoolSize: [{}], maximumPoolSize: [{}], keepAliveTime :: [{}]",
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalCoreSize, threadPoolParameterInfo.corePoolSizeAdapt()),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalMaximumPoolSize, threadPoolParameterInfo.maximumPoolSizeAdapt()),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalKeepAliveTime, threadPoolParameterInfo.getKeepAliveTime()));

@ -49,7 +49,7 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
@Override
protected Executor getWebThreadPoolByServer(WebServer webServer) {
// There is no need to consider reflection performance because the fetch is a singleton
// There is no need to consider reflection performance because the fetch is a singleton.
UndertowWebServer undertowWebServer = (UndertowWebServer) webServer;
Field undertowField = ReflectionUtils.findField(UndertowWebServer.class, UNDERTOW_NAME);
ReflectionUtils.makeAccessible(undertowField);
@ -66,7 +66,6 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
int coreSize = xnioWorker.getOption(Options.WORKER_TASK_CORE_THREADS);
int maximumPoolSize = xnioWorker.getOption(Options.WORKER_TASK_MAX_THREADS);
int keepAliveTime = xnioWorker.getOption(Options.WORKER_TASK_KEEPALIVE);
poolBaseInfo.setCoreSize(coreSize);
poolBaseInfo.setMaximumSize(maximumPoolSize);
poolBaseInfo.setKeepAliveTime((long) keepAliveTime);
@ -87,7 +86,6 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
int minThreads = xnioWorker.getOption(Options.WORKER_TASK_CORE_THREADS);
int maxThreads = xnioWorker.getOption(Options.WORKER_TASK_MAX_THREADS);
int keepAliveTime = xnioWorker.getOption(Options.WORKER_TASK_KEEPALIVE);
parameterInfo.setCoreSize(minThreads);
parameterInfo.setMaxSize(maxThreads);
parameterInfo.setKeepAliveTime(keepAliveTime);
@ -101,7 +99,6 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
public ThreadPoolRunStateInfo getWebRunStateInfo() {
ThreadPoolRunStateInfo stateInfo = new ThreadPoolRunStateInfo();
XnioWorker xnioWorker = (XnioWorker) executor;
Field field = ReflectionUtils.findField(XnioWorker.class, "taskPool");
ReflectionUtils.makeAccessible(field);
Object fieldObject = ReflectionUtils.getField(field, xnioWorker);
@ -127,14 +124,12 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
// 峰值负载
// 没有峰值记录,直接使用当前数据
String peakLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + "";
stateInfo.setCoreSize(corePoolSize);
stateInfo.setPoolSize(poolSize);
stateInfo.setMaximumSize(maximumPoolSize);
stateInfo.setActiveSize(activeCount);
stateInfo.setCurrentLoad(currentLoad);
stateInfo.setPeakLoad(peakLoad);
long rejectCount = fieldObject instanceof DynamicThreadPoolExecutor
? ((DynamicThreadPoolExecutor) fieldObject).getRejectCountNum()
: -1L;
@ -157,7 +152,7 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
xnioWorker.setOption(Options.WORKER_TASK_CORE_THREADS, coreSize);
xnioWorker.setOption(Options.WORKER_TASK_MAX_THREADS, maxSize);
xnioWorker.setOption(Options.WORKER_TASK_KEEPALIVE, keepAliveTime);
log.info("[UNDERTOW] Changed web thread pool. corePoolSize :: [{}], maximumPoolSize :: [{}], keepAliveTime :: [{}]",
log.info("[Undertow] Changed web thread pool. corePoolSize: [{}], maximumPoolSize: [{}], keepAliveTime :: [{}]",
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalCoreSize, coreSize),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalMaximumPoolSize, maxSize),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalKeepAliveTime, keepAliveTime));

@ -38,13 +38,10 @@ public class WebThreadPoolRunStateHandler extends AbstractThreadPoolRuntime {
ByteConvertUtil.getPrintSize(runtimeInfo.getTotalMemory()),
" / 最大可用: ",
ByteConvertUtil.getPrintSize(runtimeInfo.getMaxMemory())).toString();
poolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad() + "%");
poolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad() + "%");
poolRunStateInfo.setMemoryProportion(memoryProportion);
poolRunStateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(runtimeInfo.getFreeMemory()));
return poolRunStateInfo;
}
}

Loading…
Cancel
Save