Chapter 9. Undertow Subsystem Tuning
The non-blocking I/O undertow
subsystem introduced in JBoss EAP 7 has greatly improved performance compared to the previous web
subsystem in JBoss EAP 6. Opportunities for tuning the undertow
subsystem for your environment include configuring buffer caches, JSP settings, and listeners.
9.1. Buffer Caches
A buffer cache is used to cache static files handled by the undertow
subsystem. This includes images, static HTML, CSS, and JavaScript files. You can specify a default buffer cache for each Undertow servlet container. Having an optimized buffer cache for your servlet container can improve Undertow performance for serving static files.
Buffers in a buffer cache are allocated in regions, and are of a fixed size. There are three configurable attributes for each buffer cache:
buffer-size
- The size of an individual buffer, in bytes. The default is 1024 bytes. Red Hat recommends that you set the buffer size to entirely store your largest static file.
buffers-per-region
- The number of buffers per region. The default is 1024.
max-regions
- The maximum number of regions, which sets a maximum amount of memory allocated to the buffer cache. The default is 10 regions.
You can calculate the maximum amount memory used by a buffer cache by multiplying the buffer size, the number of buffers per region, and the maximum number of regions. For example, the default buffer cache is 1024 bytes * 1024 buffers per region * 10 regions = 10MB.
Configure your buffer caches based on the size of your static files, and the results from testing expected loads in a development environment. When determining the effect on performance, consider the balance of the buffer cache performance benefit versus the memory used.
For instructions on using the management CLI to configure buffer caches, see Configuring Buffer Caches in the JBoss EAP Configuration Guide.
9.2. JSP Configuration
There are JSP configuration options for Undertow servlet containers that provide optimizations for how JSP pages are compiled into Java bytecode.
generate-strings-as-char-arrays
-
If your JSPs contain a lot of
String
constants, enabling this option optimizes scriplets by converting theString
constants tochar
arrays. optimize-scriptlets
-
If your JSPs contain many
String
concatenations, enabling this option optimizes scriplets by removingString
concatenation for every JSP request. trim-spaces
- If your JSPs contain a lot of white space, enabling this option trims the white space from HTTP requests and reduces HTTP request payload.
Configuring JSP Options
You can enable these Undertow JSP configuration options using the management console or management CLI.
To enable them using the management console:
-
Navigate to Configuration
Subsystems Web/HTTP - Undertow Servlet/JSP and click View. - Select the servlet container you want to configure and click View.
- Select JSP, and under Attributes, click Edit.
- Select the check boxes for the options you want to enable, and click Save.
-
Navigate to Configuration
To enable them using the management CLI, use the following command:
/subsystem=undertow/servlet-container=SERVLET_CONTAINER/setting=jsp/:write-attribute(name=OPTION_NAME,value=true)
For example, to enable
generate-strings-as-char-arrays
for thedefault
servlet container, use the following command:/subsystem=undertow/servlet-container=default/setting=jsp/:write-attribute(name=generate-strings-as-char-arrays,value=true)
9.3. Listeners
Depending on your applications and environment, you can configure multiple listeners specific to certain types of traffic, for example, traffic on specific ports, and then configure options for each listener.
The following are selected performance-related options that can be configured on HTTP, HTTPS, and AJP listeners.
max-connections
The maximum number of concurrent connections that the listener can handle. By default this attribute is undefined, which results in unlimited connections.
You can use this option to set a ceiling on the number of connections a listener can handle, which might be useful to cap resource usage. In configuring this value you should consider your workload and traffic type. Also see
no-request-timeout
below.no-request-timeout
The length of time in milliseconds that a connection is idle before it is closed. The default value is 60000 milliseconds (1 minute).
Tuning this option in your environment for optimal connection efficiency can help improve network performance. If idle connections are prematurely closed, there are overheads in re-establishing connections. If idle connections are open for too long, they unnecessarily use resources.
max-header-size
The maximum size of a HTTP request header, in bytes. The default is 1048576 (1024KB).
Limiting the header size can be useful to prevent certain types of denial of service attacks.
buffer-pool
Specifies the buffer pool in the
io
subsystem to use for the listener. By default, all listeners use thedefault
buffer pool.You can use this option to configure each listener to use a unique buffer pool, or have multiple listeners use the same buffer pool.
worker
The
undertow
subsystem relies on theio
subsystem to provide XNIO workers. This option specifies the XNIO worker that the listener uses. By default, a listener uses thedefault
worker in theio
subsystem.It might be useful to configure each listener to use a specific worker so you can assign different worker resources to certain types of network traffic.
Configuring Listener Options
You can configure listener options using the management console or management CLI.
To configure them using the management console:
-
Navigate to Configuration
Subsystems Web/HTTP - Undertow HTTP and click View. - Select the HTTP Server tab, then select the server you want to configure and click View.
- In the left menu, select type of listener to configure, for example HTTP Listener, and select the listener in the table.
- Under Attributes, click Edit.
- Modify the options you want to configure, and click Save.
-
Navigate to Configuration
To configure them using the management CLI, use the following command:
/subsystem=undertow/server=SERVER_NAME/LISTENER_TYPE=LISTENER_NAME:write-attribute(name=OPTION_NAME,value=OPTION_VALUE)
For example, to set
max-connections
to100000
for thedefault
HTTP listener in thedefault-server
Undertow server, use the following command:/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=max-connections,value=100000)