Nginx upstream automatic weight

load balancingnginx

We have been using nginx as a reverse-proxy for a php farm, with "manual weight settings" for upstream hosts.
The maybe 30 php backend servers are of wildly different power. We cannot change that.

We have reached the point where we cannot keep up with adjusting those weights manually any longer. Random spikes on individual upstream hosts will kill them before we can adjust weight. While other hosts are idle. (!)

What would be an alternative to manual weighted round-robin? Preferably an automatic solution based on the real upstream system load.

Best Answer

You can use the least-conn directive in your upstream module definitions. This specifies that a group should use a load balancing method where a request is passed to the server with the least number of active connections. It appeared in version 1.2.2.

More information is in the NGINX documentation: http://nginx.org/en/docs/http/ngx_http_upstream_module.html#least_conn