Questions regarding upstream
Benedikt Heine
bebe at bebehei.de
Fri Aug 16 19:55:52 UTC 2024
Hi,
On 09.08.24 22:16, Sébastien Rebecchi wrote:
> 1. When is it better to use random load-balancing strategy rather than
> the default round-robin one (and vice-versa)?
Random selects always one randomly, while round robin usually sends the
next request to the next server in the list.
Personally, I've never had a use-case where the difference between round
robin or random mattered.
But if you're thinking about optimising your load balancing setup, check
out this article:
https://samwho.dev/load-balancing/
You can see, Least connections might work much better than round robin.
It also suggests PEWMA, but nginx doesn't have this sort of balancing
method.
> 2. Is there a way to be notified when a server is marked as down
> (max_fails reached during fail_timeout)? I can't see anything as such in
> error logs
You can read out the status of the upstream via the shared memory zone.
This is possible with lua AFAIK. You could use such a code add some sort
of prometheus or general metrics endpoint and regularily query it.
However there is no loggable variable, which retrieves the states and
makes it processable during normal request.
But there is $upstream_addr, $upstream_response_time,
$upstream_connect_time and $upstream_status. In case of
proxy_next_upstream getting active, you can see in their content to
which upstreams the request got passed. By reading the logs and
aggregating them into something like elasticsearch, I guess you could
also understand _why_ nginx thought some upstreams are down.
Kind Regards,
Benedikt
More information about the nginx
mailing list