我正在尝试优化underow服务器,我想尝试为我的HttpListener设置I / O线程(WORKER_IO_THREADS和WORKER_TASK_CORE_THREADS)。你能帮我完成所需的步骤吗?
Undertow server = Undertow.builder().addHttpListener(80, "")
.setHandler(new HttpHandler() {
public void handleRequest(final HttpServerExchange exchange)
throws Exception {
String string_exchange = exchange.getQueryString();
str = <some work on string_exchange>
exchange.getResponseSender().send(str);
}
}).build();
server.start();
我确实读过需要配置与侦听器关联的XNIO worker。但是我不明白如何解决这个问题。
答案 0 :(得分:0)
我担心你需要像documentation中所描述的那样,手动开辟Undertow。原因是所有处理程序都从一个XnioWorker共享NIO池。
XnioWorker worker = xnio.createWorker(OptionMap.builder()
.set(Options.WORKER_IO_THREADS, ioThreads)
.set(Options.WORKER_TASK_CORE_THREADS, workerThreads)
.set(Options.WORKER_TASK_MAX_THREADS, workerThreads)
.set(Options.TCP_NODELAY, true)
.getMap());