Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The characteristics and usage of Undertow

Shulou Source: shulou.com Published: 2022-06-02 04:42:44 11月29日 Update

This article mainly explains the "characteristics and usage of Undertow". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the characteristics and usage of Undertow".

Undertow

Undertow is a high performance Web embedded server based on NIO developed by Red Hat.

Characteristics of Untertow:

Lightweight: it is a Web server, but unlike traditional Web servers, it has a container concept. It consists of two core Jar packages that load a Web application that can be less than 10MB memory.

Servlet3.1 support: it provides support for Servlet3.1

WebSocket support: full support for WebSocket to meet a huge number of clients for Web applications

Nesting: it does not need a container, and you can quickly build a Web server through API

By default, Spring Cloud uses Tomcat as an embedded Servlet container, which can start a Spring Boot program of Tomcat and a Spring Boot program of Undertow. By comparing the VisualVM tool, we can see that the performance of Undertow is better than that of Tomcat.

Use Undertow

Add dependency

Org.springframework.boot

Spring-boot-starter-web

Org.springframework.boot

Spring-boot-starter-tomcat

Org.springframework.boot

Spring-boot-starter-undertow

Support for HTTP2

/ / add @ bean to the @ Configuration class

@ Bean

UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory () {

UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory ()

/ / other configurations can also be made here.

Factory.addBuilderCustomizers (builder-> builder.setServerOption (UndertowOptions.ENABLE_HTTP2, true))

Return factory

}

Configure Undertow

# Undertow log storage directory

Server.undertow.accesslog.dir

# whether to start the log

Server.undertow.accesslog.enabled=false

# Log format

Server.undertow.accesslog.pattern=common

# Log file name prefix

Server.undertow.accesslog.prefix=access_log

# Log file name suffix

Server.undertow.accesslog.suffix=log

# maximum size of HTTP POST request

Server.undertow.max-http-post-size=0

# set the number of IO threads, which mainly perform non-blocking tasks, which are responsible for multiple connections. By default, one thread is set for each CPU core

Server.undertow.io-threads=4

# blocking task thread pool. When performing a similar servlet request blocking operation, undertow will get threads from this thread pool. Its value setting depends on the load of the system.

Server.undertow.worker-threads=20

# the following configurations will affect buffer, which will be used for IO operations of server connections, similar to pooled memory management of netty

# the size of each buffer. The smaller the space is, the more fully utilized it is.

Server.undertow.buffer-size=1024

# the number of buffer allocated per zone, so the size of pool is buffer-size * buffers-per-region

Server.undertow.buffers-per-region=1024

# whether direct memory is allocated or not

Server.undertow.direct-buffers=true

Thank you for your reading, the above is the content of "the characteristics and usage of Undertow". After the study of this article, I believe you have a deeper understanding of the characteristics and usage of Undertow, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Features logs servers threads support services usage methods memory size containers learning configuration blocking tasks content situation quantity files file names Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info Shulou Information MySQL Xiaomi