random load balancer

Adam Schwartz adam at anschwa.com
Sun Nov 5 01:56:29 UTC 2017


I’m experimenting with nginx module development by trying to implement a random load balancer.

I see that *us->servers->nelts matches the upstream servers defined in nginx.conf

However, something that’s confusing to me is where *us->elts[0]->naddrs comes from.

My thinking was that I could chose a random integer and select a peer by indexing it.
This doesn’t work reliably because the “real” webservers are only accessible every two indexes such as: &peer[0] => foo.example, &peer[3] => bar.example, and &peer[6] => baz.example, etc.

I’m having trouble finding why this is the case and any advice would be appreciated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20171104/0e2fe0ac/attachment.html>

More information about the nginx mailing list