|
|
@ -2,18 +2,16 @@ package cn.hippo4j.starter.handler.web;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.common.model.PoolParameterInfo;
|
|
|
|
import cn.hippo4j.common.model.PoolParameterInfo;
|
|
|
|
import io.undertow.Undertow;
|
|
|
|
import io.undertow.Undertow;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.boot.web.embedded.undertow.UndertowWebServer;
|
|
|
|
import org.springframework.boot.web.embedded.undertow.UndertowWebServer;
|
|
|
|
import org.springframework.boot.web.server.WebServer;
|
|
|
|
import org.springframework.boot.web.server.WebServer;
|
|
|
|
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
|
|
|
|
|
|
|
|
import org.springframework.util.ReflectionUtils;
|
|
|
|
import org.springframework.util.ReflectionUtils;
|
|
|
|
|
|
|
|
import org.xnio.Options;
|
|
|
|
|
|
|
|
import org.xnio.XnioWorker;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Undertow web thread pool handler.
|
|
|
|
* Undertow web thread pool handler.
|
|
|
@ -42,11 +40,25 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateWebThreadPool(PoolParameterInfo poolParameterInfo) {
|
|
|
|
public void updateWebThreadPool(PoolParameterInfo poolParameterInfo) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ThreadPoolExecutor undertowExecutor = (ThreadPoolExecutor) executor;
|
|
|
|
XnioWorker xnioWorker = (XnioWorker) executor;
|
|
|
|
undertowExecutor.setCorePoolSize(poolParameterInfo.getCoreSize());
|
|
|
|
|
|
|
|
undertowExecutor.setMaximumPoolSize(poolParameterInfo.getMaxSize());
|
|
|
|
Integer coreSize = poolParameterInfo.getCoreSize();
|
|
|
|
undertowExecutor.setKeepAliveTime(poolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS);
|
|
|
|
Integer maxSize = poolParameterInfo.getMaxSize();
|
|
|
|
super.log(poolParameterInfo, undertowExecutor);
|
|
|
|
Integer keepAliveTime = poolParameterInfo.getKeepAliveTime();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int originalCoreSize = xnioWorker.getOption(Options.WORKER_TASK_CORE_THREADS);
|
|
|
|
|
|
|
|
int originalMaximumPoolSize = xnioWorker.getOption(Options.WORKER_TASK_MAX_THREADS);
|
|
|
|
|
|
|
|
int originalKeepAliveTime = xnioWorker.getOption(Options.WORKER_TASK_KEEPALIVE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
|
|
|
"🔥 Changed web thread pool. coreSize :: [{}], maxSize :: [{}], keepAliveTime :: [{}]",
|
|
|
|
|
|
|
|
String.format("%s => %s", originalCoreSize, coreSize),
|
|
|
|
|
|
|
|
String.format("%s => %s", originalMaximumPoolSize, maxSize),
|
|
|
|
|
|
|
|
String.format("%s => %s", originalKeepAliveTime, keepAliveTime)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
log.error("Failed to modify the undertow thread pool parameter.", ex);
|
|
|
|
log.error("Failed to modify the undertow thread pool parameter.", ex);
|
|
|
|