Update NettyWebSocketServer.java

feat(main):netty服务,worker的EventLoopGroup大小根据当前cpu核心数动态获取
This commit is contained in:
thinker
2023-06-14 14:37:18 +08:00
committed by GitHub
parent ab7d06d333
commit a3eeb4ee9f

View File

@@ -15,6 +15,7 @@ import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.stream.ChunkedWriteHandler; import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.NettyRuntime;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@@ -28,7 +29,7 @@ public class NettyWebSocketServer {
public static final int WEB_SOCKET_PORT = 8090; public static final int WEB_SOCKET_PORT = 8090;
// 创建线程池执行器 // 创建线程池执行器
private EventLoopGroup bossGroup = new NioEventLoopGroup(1); private EventLoopGroup bossGroup = new NioEventLoopGroup(1);
private EventLoopGroup workerGroup = new NioEventLoopGroup(8); private EventLoopGroup workerGroup = new NioEventLoopGroup(NettyRuntime.availableProcessors());
/** /**
* 启动 ws server * 启动 ws server