Introduce Undertow

What’s Undertow

Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO.

Undertow has a composition based architecture that allows you to build a web server by combining small single purpose handlers. The gives you the flexibility to choose between a full Java EE servlet 4.0 container, or a low level non-blocking handler, to anything in between.

Undertow is designed to be fully embeddable, with easy to use fluent builder APIs. Undertow’s lifecycle is completely controlled by the embedding application.

Undertow is sponsored by JBoss and is the default web server in the Wildfly Application Server.

http://undertow.io/

Usage

Paramter

  • server.undertow.io-threads=16

    设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
    不要设置过大,如果过大,启动项目会报错:打开文件数过多

  • server.undertow.worker-threads=256

    阻塞任务线程池, 当执行类似servlet请求阻塞IO操作, undertow会从这个线程池中取得线程
    它的值设置取决于系统线程执行任务的阻塞系数,默认值是IO线程数*8

  • server.undertow.buffer-size=1024

    以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
    每块buffer的空间大小,越小的空间被利用越充分,不要设置太大,以免影响其他应用,合适即可

  • server.undertow.buffers-per-region=1024

    每个区分配的buffer数量 , 所以pool的大小是buffer-size * buffers-per-region

  • server.undertow.direct-buffers=true

    是否分配的直接内存(NIO直接分配的堆外内存)

Error

UT000128: Remote peer closed connection before all data could be read