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

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

@ -85,7 +85,7 @@ public class DubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationLis
int originalMaximumPoolSize = executor.getMaximumPoolSize(); int originalMaximumPoolSize = executor.getMaximumPoolSize();
executor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize()); executor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
executor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize()); 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, threadPoolKey,
String.format(CHANGE_DELIMITER, originalCoreSize, executor.getCorePoolSize()), String.format(CHANGE_DELIMITER, originalCoreSize, executor.getCorePoolSize()),
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, executor.getMaximumPoolSize())); String.format(CHANGE_DELIMITER, originalMaximumPoolSize, executor.getMaximumPoolSize()));

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

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

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

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

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

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

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

@ -89,7 +89,7 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda
int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize(); int originalMaximumPoolSize = rocketMQConsumeExecutor.getMaximumPoolSize();
rocketMQConsumeExecutor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize()); rocketMQConsumeExecutor.setCorePoolSize(threadPoolAdapterParameter.getCorePoolSize());
rocketMQConsumeExecutor.setMaximumPoolSize(threadPoolAdapterParameter.getMaximumPoolSize()); 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, threadPoolKey,
String.format(CHANGE_DELIMITER, originalCoreSize, rocketMQConsumeExecutor.getCorePoolSize()), String.format(CHANGE_DELIMITER, originalCoreSize, rocketMQConsumeExecutor.getCorePoolSize()),
String.format(CHANGE_DELIMITER, originalMaximumPoolSize, rocketMQConsumeExecutor.getMaximumPoolSize())); String.format(CHANGE_DELIMITER, originalMaximumPoolSize, rocketMQConsumeExecutor.getMaximumPoolSize()));

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

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

@ -89,7 +89,7 @@ public class JettyWebThreadPoolHandler extends AbstractWebThreadPoolService {
Integer maxSize = threadPoolParameterInfo.maximumPoolSizeAdapt(); Integer maxSize = threadPoolParameterInfo.maximumPoolSizeAdapt();
jettyExecutor.setMinThreads(coreSize); jettyExecutor.setMinThreads(coreSize);
jettyExecutor.setMaxThreads(maxSize); 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, minThreads, jettyExecutor.getMinThreads()),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, maxThreads, jettyExecutor.getMaxThreads())); String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, maxThreads, jettyExecutor.getMaxThreads()));
} catch (Exception ex) { } catch (Exception ex) {

@ -62,7 +62,7 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
} catch (Exception ex) { } catch (Exception ex) {
cacheFlag.set(Boolean.TRUE); cacheFlag.set(Boolean.TRUE);
EXCEPTION_MESSAGE = ex.getMessage(); 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; return tomcatExecutor;
} }
@ -168,7 +168,7 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService {
tomcatThreadPoolExecutor.setCorePoolSize(threadPoolParameterInfo.corePoolSizeAdapt()); tomcatThreadPoolExecutor.setCorePoolSize(threadPoolParameterInfo.corePoolSizeAdapt());
tomcatThreadPoolExecutor.setMaximumPoolSize(threadPoolParameterInfo.maximumPoolSizeAdapt()); tomcatThreadPoolExecutor.setMaximumPoolSize(threadPoolParameterInfo.maximumPoolSizeAdapt());
tomcatThreadPoolExecutor.setKeepAliveTime(threadPoolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS); 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, originalCoreSize, threadPoolParameterInfo.corePoolSizeAdapt()),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalMaximumPoolSize, threadPoolParameterInfo.maximumPoolSizeAdapt()), String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalMaximumPoolSize, threadPoolParameterInfo.maximumPoolSizeAdapt()),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalKeepAliveTime, threadPoolParameterInfo.getKeepAliveTime())); String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalKeepAliveTime, threadPoolParameterInfo.getKeepAliveTime()));

@ -49,7 +49,7 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
@Override @Override
protected Executor getWebThreadPoolByServer(WebServer webServer) { 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; UndertowWebServer undertowWebServer = (UndertowWebServer) webServer;
Field undertowField = ReflectionUtils.findField(UndertowWebServer.class, UNDERTOW_NAME); Field undertowField = ReflectionUtils.findField(UndertowWebServer.class, UNDERTOW_NAME);
ReflectionUtils.makeAccessible(undertowField); ReflectionUtils.makeAccessible(undertowField);
@ -66,7 +66,6 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
int coreSize = xnioWorker.getOption(Options.WORKER_TASK_CORE_THREADS); int coreSize = xnioWorker.getOption(Options.WORKER_TASK_CORE_THREADS);
int maximumPoolSize = xnioWorker.getOption(Options.WORKER_TASK_MAX_THREADS); int maximumPoolSize = xnioWorker.getOption(Options.WORKER_TASK_MAX_THREADS);
int keepAliveTime = xnioWorker.getOption(Options.WORKER_TASK_KEEPALIVE); int keepAliveTime = xnioWorker.getOption(Options.WORKER_TASK_KEEPALIVE);
poolBaseInfo.setCoreSize(coreSize); poolBaseInfo.setCoreSize(coreSize);
poolBaseInfo.setMaximumSize(maximumPoolSize); poolBaseInfo.setMaximumSize(maximumPoolSize);
poolBaseInfo.setKeepAliveTime((long) keepAliveTime); poolBaseInfo.setKeepAliveTime((long) keepAliveTime);
@ -87,7 +86,6 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
int minThreads = xnioWorker.getOption(Options.WORKER_TASK_CORE_THREADS); int minThreads = xnioWorker.getOption(Options.WORKER_TASK_CORE_THREADS);
int maxThreads = xnioWorker.getOption(Options.WORKER_TASK_MAX_THREADS); int maxThreads = xnioWorker.getOption(Options.WORKER_TASK_MAX_THREADS);
int keepAliveTime = xnioWorker.getOption(Options.WORKER_TASK_KEEPALIVE); int keepAliveTime = xnioWorker.getOption(Options.WORKER_TASK_KEEPALIVE);
parameterInfo.setCoreSize(minThreads); parameterInfo.setCoreSize(minThreads);
parameterInfo.setMaxSize(maxThreads); parameterInfo.setMaxSize(maxThreads);
parameterInfo.setKeepAliveTime(keepAliveTime); parameterInfo.setKeepAliveTime(keepAliveTime);
@ -101,7 +99,6 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
public ThreadPoolRunStateInfo getWebRunStateInfo() { public ThreadPoolRunStateInfo getWebRunStateInfo() {
ThreadPoolRunStateInfo stateInfo = new ThreadPoolRunStateInfo(); ThreadPoolRunStateInfo stateInfo = new ThreadPoolRunStateInfo();
XnioWorker xnioWorker = (XnioWorker) executor; XnioWorker xnioWorker = (XnioWorker) executor;
Field field = ReflectionUtils.findField(XnioWorker.class, "taskPool"); Field field = ReflectionUtils.findField(XnioWorker.class, "taskPool");
ReflectionUtils.makeAccessible(field); ReflectionUtils.makeAccessible(field);
Object fieldObject = ReflectionUtils.getField(field, xnioWorker); Object fieldObject = ReflectionUtils.getField(field, xnioWorker);
@ -127,14 +124,12 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
// 峰值负载 // 峰值负载
// 没有峰值记录,直接使用当前数据 // 没有峰值记录,直接使用当前数据
String peakLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + ""; String peakLoad = CalculateUtil.divide(activeCount, maximumPoolSize) + "";
stateInfo.setCoreSize(corePoolSize); stateInfo.setCoreSize(corePoolSize);
stateInfo.setPoolSize(poolSize); stateInfo.setPoolSize(poolSize);
stateInfo.setMaximumSize(maximumPoolSize); stateInfo.setMaximumSize(maximumPoolSize);
stateInfo.setActiveSize(activeCount); stateInfo.setActiveSize(activeCount);
stateInfo.setCurrentLoad(currentLoad); stateInfo.setCurrentLoad(currentLoad);
stateInfo.setPeakLoad(peakLoad); stateInfo.setPeakLoad(peakLoad);
long rejectCount = fieldObject instanceof DynamicThreadPoolExecutor long rejectCount = fieldObject instanceof DynamicThreadPoolExecutor
? ((DynamicThreadPoolExecutor) fieldObject).getRejectCountNum() ? ((DynamicThreadPoolExecutor) fieldObject).getRejectCountNum()
: -1L; : -1L;
@ -157,7 +152,7 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
xnioWorker.setOption(Options.WORKER_TASK_CORE_THREADS, coreSize); xnioWorker.setOption(Options.WORKER_TASK_CORE_THREADS, coreSize);
xnioWorker.setOption(Options.WORKER_TASK_MAX_THREADS, maxSize); xnioWorker.setOption(Options.WORKER_TASK_MAX_THREADS, maxSize);
xnioWorker.setOption(Options.WORKER_TASK_KEEPALIVE, keepAliveTime); 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, originalCoreSize, coreSize),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalMaximumPoolSize, maxSize), String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalMaximumPoolSize, maxSize),
String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalKeepAliveTime, keepAliveTime)); String.format(ChangeThreadPoolConstants.CHANGE_DELIMITER, originalKeepAliveTime, keepAliveTime));

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

Loading…
Cancel
Save