Upstream Queue#

Queues requests to server groups of the HTTP Upstream module when no server can take them on the first attempt. The module's directive is set in the upstream block.

Related guides

Configuration Example#

upstream backend {
    zone backend 1m;
    server backend1.example.com:8080 max_conns=100;
    server backend2.example.com:8080 max_conns=100;

    queue 50 timeout=10s;
}

Directives#

queue (PRO)#

Syntax

queue number [timeout=time];

Default

—

Context

upstream

If it is not possible to assign a proxied server to a request on the first attempt (for example, during a brief service interruption or when there is a surge in load reaching the max_conns limit), the request is not rejected; instead, Angie attempts to enqueue it for processing.

The number parameter of the directive sets the maximum number of requests in the queue for a worker process. If the queue is full, a 502 (Bad Gateway) error is returned to the client.

Note

The logic of the proxy_next_upstream directive also applies to queued requests. Specifically, if a server was selected for a request but it cannot be handed over to it, the request may be returned to the queue.

If a server is not selected to process a queued request within the time set by timeout (default is 60 seconds), a 502 (Bad Gateway) error is returned to the client. Requests from clients that prematurely close the connection are also removed from the queue; there are counters for the states of requests passing through the queue in the API. The time that a request spent in the queue is stored in the $upstream_queue_time variable of the HTTP Upstream module.

Warning

The queue directive must be used after all directives that set the load balancing method; otherwise, it won't work.