How to configure max concurrent requests limit for specific application in EAP 7

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7.x

Issue

  • How do I configure max concurrent requests limit for specific application in EAP 7?

Resolution

You can use request-limit filter to limit concurrent requests in EAP 7. And you can specify path or use regex with predicate attribute in order to apply the filter to the specific path.

For example:

  1. Enable request-limit filter with 512 max concurrent requests and with queue-size 10.
    Note: specifying 0 or negative value to queue-size means using unlimited queue (actually, setting Integer.MAX_VALUE internally):

     /subsystem=undertow/configuration=filter/request-limit=mylimit:add(max-concurrent-requests=512, queue-size=10)
     /subsystem=undertow/server=default-server/host=default-host/filter-ref=mylimit:add()
    
  2. Add predicate to specify the path to apply the filter.

    • To apply the filter only to path starting with /example/:

        /subsystem=undertow/server=default-server/host=default-host/filter-ref=mylimit:write-attribute(name=predicate,value="path-prefix('/example/')")
      
    • To apply the filter only to jsp file under the path starting with /example/:

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

Caution: Though the queue-size is an optional attribute, a request fails due to IllegalArgumentException like the following when you omit the queue-size attribute in EAP 7.0.x. This is a known bug reported as Content from issues.jboss.org is not included.JBEAP-3668 which has been fixed in EAP 7.1.0 or later. So, please make sure to specify both max-concurrent-requests and queue-size attributes in EAP 7.0.x.

ERROR [io.undertow.request] (default I/O-11) UT005071: Undertow request failed HttpServerExchange{ GET / request {Accept=[*/*], User-Agent=[curl/7.29.0], Host=[localhost:8080]} response {}}: java.lang.RuntimeException: WFLYUT0059: Could not construct handler for class: class io.undertow.server.handlers.RequestLimitingHandler. with parameters {
    "max-concurrent-requests" => 100,
    "queue-size" => undefined
}
	at org.wildfly.extension.undertow.filters.Filter.createHandler(Filter.java:111)
	at org.wildfly.extension.undertow.filters.Filter.createHttpHandler(Filter.java:68)
	at org.wildfly.extension.undertow.filters.RequestLimitHandler.createHttpHandler(RequestLimitHandler.java:37)
	at org.wildfly.extension.undertow.filters.FilterService.createHttpHandler(FilterService.java:57)
	at org.wildfly.extension.undertow.filters.FilterRef.createHttpHandler(FilterRef.java:69)
	at org.wildfly.extension.undertow.LocationService.configureHandlerChain(LocationService.java:96)
	at org.wildfly.extension.undertow.Host.configureRootHandler(Host.java:118)
	at org.wildfly.extension.undertow.Host.getOrCreateRootHandler(Host.java:172)
	at org.wildfly.extension.undertow.Host$HostRootHandler.handleRequest(Host.java:293)
	at io.undertow.server.handlers.NameVirtualHostHandler.handleRequest(NameVirtualHostHandler.java:54)
	at io.undertow.server.handlers.error.SimpleErrorPageHandler.handleRequest(SimpleErrorPageHandler.java:76)
	at io.undertow.server.handlers.CanonicalPathHandler.handleRequest(CanonicalPathHandler.java:49)
	at io.undertow.server.handlers.ChannelUpgradeHandler.handleRequest(ChannelUpgradeHandler.java:158)
	at io.undertow.server.handlers.DisallowedMethodsHandler.handleRequest(DisallowedMethodsHandler.java:61)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:324)
	at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:239)
	at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:132)
	at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:145)
	at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:92)
	at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:51)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:291)
	at org.xnio.ChannelListeners$10.handleEvent(ChannelListeners.java:286)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.nio.QueuedNioTcpServer$1.run(QueuedNioTcpServer.java:131)
	at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:592)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:472)
Caused by: java.lang.IllegalArgumentException
	at org.jboss.dmr.ModelValue.asInt(ModelValue.java:58)
	at org.jboss.dmr.ModelNode.asInt(ModelNode.java:240)
	at org.wildfly.extension.undertow.filters.Filter.createHandler(Filter.java:94)
	... 26 more
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.