Upstream Feedback#
Implements feedback-based load balancing for server groups of the HTTP Upstream module: server weights are adjusted by a metric that the servers report, for example in response headers. The module's directive is set in the upstream block.
Related guides
Load Balancing: explains the value direction and
inverse.
Configuration Example#
upstream backend {
zone backend 1m;
feedback $upstream_http_x_capacity;
server backend1.example.com;
server backend2.example.com;
}
Each server reports its spare capacity in the X-Capacity response
header field; a server that reports a higher value gets a larger share of
requests.
Directives#
feedback (PRO)#
| |
Default | — |
upstream |
Sets up a feedback-based load balancing mechanism in the upstream.
It dynamically adjusts balancing decisions
by multiplying the weight of each proxied server by the average feedback value,
which changes over time depending on the value of the variable
and is subject to an optional condition.
The following parameters can be specified:
| The variable from which the feedback value is taken. It should represent a performance or health metric; it is assumed that the server provides it in headers or otherwise. The value is evaluated with each response from the server
and is factored into the moving average
according to the |
| If the parameter is set, the feedback value is interpreted inversely: lower values indicate better performance. |
| The factor by which the feedback value is considered
when calculating the average.
Valid values are integers from 0 to 99.
Default is The average is calculated using the exponential smoothing formula. The larger the factor, the less new values affect the average;
if |
| Specifies a condition variable
that controls which responses are considered in the calculation.
The average value is updated with the feedback value from the response
only if the condition variable of that response
is not equal to Note By default, responses during active checks
are not included in the calculation;
combining the $upstream_probe variable
with |
| Allows processing data from the proxied server after receiving the complete response, not just the header. |
Example:
upstream backend {
zone backend 1m;
feedback $feedback_value factor=80 account=$condition_value;
server backend1.example.com;
server backend2.example.com;
}
map $upstream_http_custom_score $feedback_value {
"high" 100;
"medium" 75;
"low" 50;
default 10;
}
map $upstream_probe $condition_value {
"high_priority" "1";
"low_priority" "0";
default "1";
}
This configuration categorizes server responses by feedback levels
based on specific scores from response header fields,
and also adds a condition on $upstream_probe
to consider only responses from the high_priority active check
or responses to regular client requests.