Class QoSHandler

java.lang.Object
All Implemented Interfaces:
Handler, Handler.Container, Handler.Singleton, Request.Handler, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.util.thread.Invocable

@ManagedObject public class QoSHandler extends ConditionalHandler.Abstract

A quality of service Handler that conditionally limits the number of concurrent requests, to provide more predictable end-user experience in case descendant Handlers have limited capacity.

This Handler limits the number of concurrent requests to the number configured via setMaxRequestCount(int). If more requests are received, they are suspended (that is, not forwarded to the child Handler) and stored in a priority queue.

The maximum number of suspended request can be set with setMaxSuspendedRequestCount(int) to avoid out of memory errors. When this limit is reached, the request will fail fast with status code 503 (not available).

Priorities are determined via getPriority(Request), that should return values between 0 (the lowest priority) and positive numbers, typically in the range 0-10.

When a request that is being processed completes, the suspended request that current has the highest priority is resumed.

This Handler is ideal to avoid contending on slow/limited resources such as a JDBC connection pool, avoiding the situation where all server threads blocked contending on the limited resource, therefore leaving threads free to process other requests that do not require access to the limited resource.

Requests are resumed in priority order, so that when the server is under load, and there are many requests suspended to be processed, high priority request are processed first. For example, load balancer "ping" requests may have the highest priority, followed by requests performed by admin users, etc. so that regardless of the load, "ping" and "admin" requests will always be able to access the web application.