我正在尝试优化流下服务器,我想尝试为我的HttpListener设置I/O线程(WORKER_IO_TTHREADS和WORKER_TAK_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工作程序。然而,我不清楚该怎么做。
恐怕您需要像文档中所述的那样手动引导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());