unbit/uwsgi — pull request #15 by prymitive (2012-10-06 10:38:16+00:00)
Title: weighted least reference count (wlrc) load balancing algorithm

Same as [lrc weight handling support pull request](https://github.com/unbit/uwsgi/pull/14) but implemented as separate algorithm. Reasons:

* I disliked idea of patching current lrc algo, it should be left alone as is
* I've come to conclusion that wlrc algo might be usefull and I would opt for including it

In practice wlrc gives us weighted algorithm that can handle misbehaving nodes (while wrr can't), so if someone is using nodes with different hardware specs than one node might have few times more memory and cpu cores, and so it can spawn much more workers. In such case lrc will probably forward more requests to it only when lower spec nodes are heavily loaded and they start to have longer response times (in theory, I didn't tested it).

Tested with ab, each node had number of workers equal to it's weight value. Results:

```
ab -r -c 13 -n 13000

172.16.200.56:3001: weight=1 failcnt=0 wrr=0 requests=1235 ref=0
172.16.200.70:3001: weight=4 failcnt=0 wrr=0 requests=4301 ref=0
172.16.200.55:3001: weight=8 failcnt=0 wrr=0 requests=7464 ref=0
```