Permalink
Browse files

Properly account backend weights

Conflicts:

	src/http/modules/ngx_http_upstream_fair_module.c
  • Loading branch information...
1 parent 161e5b3 commit 1e2b7a3fcd1f44c9bd5e223959aeb412fd6bbaf1 @gnosek committed Nov 11, 2007
Showing with 15 additions and 0 deletions.
  1. +15 −0 ngx_http_upstream_fair_module.c
@@ -337,8 +337,23 @@ ngx_http_upstream_get_fair_peer(ngx_peer_connection_t *pc, void *data)
* and advance the "current peer" for the next run of round-robin
*/
if (first_peer != fp->rrpd.current) {
+ ngx_http_upstream_rr_peer_t *orig_peer = &fp->rrpd.peers->peer[first_peer];
ngx_http_upstream_rr_peer_t *peer = &fp->rrpd.peers->peer[fp->rrpd.current];
+ /* undo ajdustments made to the original peer by rr algorithm */
+ if (orig_peer->current_weight == orig_peer->weight) {
+ orig_peer->current_weight = 1;
+ } else {
+ orig_peer->current_weight++;
+ }
+
+ /* adjust the new peer accordingly */
+ if (peer->current_weight == 1) {
+ peer->current_weight = peer->weight;
+ } else {
+ peer->current_weight--;
+ }
+
pc->sockaddr = peer->sockaddr;
pc->socklen = peer->socklen;
pc->name = &peer->name;

0 comments on commit 1e2b7a3

Please sign in to comment.