How to set the maximum number of Web connections in WildFly

In WildFly and JBoss EAP, you can manage concurrent request limits in different ways. In this tutorial we will learn how to configure the max concurrent request limits at server, connector and application path.

To avoid the error “The maximum number of web connections has been reached” we can configure the max concurrent request limits at different levels:

  • Server listener level: Each listener will have a maximum number of concurrent connections
  • Server level: Each Undertow Server will have a maximum number of concurrent connections which you can define through a Filter expression.
  • Application level: This is the most specific way to set the maximum number of concurrent connections, which applies at application level

Configuring Maximum Connections at Listener Level

Undertow provides a number of listeners for each protocol you have in your configurations. The max-connections attribute sets the amount of concurrent connections that can be processed by an Undertow listener. You can apply to any of your available connectors.

For example, to set the maximum number of connections for the HTTP connector from WildFly / JBoss CLI execute:

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

The configuration will be updated as follows:

<server name="default-server">
      <http-listener name="default" max-connections="300" socket-binding="http" redirect-socket="https" enable-http2="true"/>
                
</server>

If your configuration supports the AJP protocol, you can set the maximum number of AJP connections as well:

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

That will be the result in your XML configuration:

<server name="default-server">
      <ajp-listener name="ajp" max-connections="300" socket-binding="ajp"/>
</server>

When you reach or exceed the maximum number of connections a message will be logged. More in detail:

  • When reaching max-connections limit:
DEBUG [org.xnio.nio.tcp.server] (default Accept) Total open connections reach high water limit (10) by this new accepting request java.nio.channels.SocketChannel[connected local=/127.0.0.1:8080 remote=/127.0.0.1:40008]
  • When exceeding max-connections limit:
DEBUG [org.xnio.nio.tcp.server] (default Accept) Exceeding connection high water limit (10). Closing this new accepting request java.nio.channels.SocketChannel[connected local=/127.0.0.1:8080 remote=/127.0.0.1:40010]

In order to enable the logging of the above messages, you have to enable DEBUG logging of org.xnio.nio.tcp.server logger:

/subsystem=logging/logger=org.xnio.nio.tcp.server:add(level=DEBUG)

Configuring Maximum Connections at Server Level

You can use request-limit filter to limit concurrent requests in WIldFly. This filter will apply at Server Level. For example, to set the maximum number of concurrent requests to 500 with a Queue Size of 10:

/subsystem=undertow/configuration=filter/request-limit=connlimit:add(max-concurrent-requests=500, queue-size=10)
/subsystem=undertow/server=default-server/host=default-host/filter-ref=connlimit:add()

Configuring Maximum Connections at Application Level

To do that, add a predicate to the filter we have just created. In this predicate, specify the path to apply the filter. To apply the filter only to path starting with /mywebapp/:

/subsystem=undertow/server=default-server/host=default-host/filter-ref=connlimit:write-attribute(name=predicate,value="path-prefix('/mywebapp/')")

Additionally, you can also specify a limit for a specific resource, such as if you have a Servlet in the mywebapp Context which is mapped with “*-limited“:

/subsystem=undertow/server=default-server/host=default-host/filter-ref=connlimit:write-attribute(name=predicate,value="regex('/mywebapp/(.*)-limited')")

Conclusion

In conclusion, we have covered how to set the maximum number of concurrent connections for WildFly / JBoss Web connectors and how to log messages if reaching or exceeding this number.

Found the article helpful? if so please follow us on Socials