Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

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 the String constants to char arrays.
optimize-scriptlets
If your JSPs contain many String concatenations, enabling this option optimizes scriplets by removing String 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:

    1. Navigate to ConfigurationSubsystemsWeb/HTTP - UndertowServlet/JSP → and click View.
    2. Select the servlet container you want to configure and click View.
    3. Select JSP, and under Attributes, click Edit.
    4. Select the check boxes for the options you want to enable, and click Save.
  • 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 the default 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 the default 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 the io subsystem to provide XNIO workers. This option specifies the XNIO worker that the listener uses. By default, a listener uses the default worker in the io 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:

    1. Navigate to ConfigurationSubsystemsWeb/HTTP - UndertowHTTP → and click View.
    2. Select the HTTP Server tab, then select the server you want to configure and click View.
    3. In the left menu, select type of listener to configure, for example HTTP Listener, and select the listener in the table.
    4. Under Attributes, click Edit.
    5. Modify the options you want to configure, and click Save.
  • 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 to 100000 for the default HTTP listener in the default-server Undertow server, use the following command:

    /subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=max-connections,value=100000)