# HG changeset patch # User Igor Sysoev # Date 1186673297 0 # Node ID cc8ac1936aa444e149d422a5bafbec099e5c735c # Parent 0be898896d1a16c39694f0343b1450333d2905d8 sort upstream weights diff -r 0be898896d1a -r cc8ac1936aa4 src/http/ngx_http_upstream_round_robin.c --- a/src/http/ngx_http_upstream_round_robin.c Thu Aug 09 13:54:33 2007 +0000 +++ b/src/http/ngx_http_upstream_round_robin.c Thu Aug 09 15:28:17 2007 +0000 @@ -9,6 +9,7 @@ #include +static int ngx_http_upstream_cmp_servers(const void *one, const void *two); static ngx_uint_t ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers); @@ -69,6 +70,10 @@ us->peer.data = peers; + ngx_sort(&peers->peer[0], (size_t) n, + sizeof(ngx_http_upstream_rr_peer_t), + ngx_http_upstream_cmp_servers); + /* backup servers */ n = 0; @@ -118,6 +123,10 @@ peers->next = backup; + ngx_sort(&backup->peer[0], (size_t) n, + sizeof(ngx_http_upstream_rr_peer_t), + ngx_http_upstream_cmp_servers); + return NGX_OK; } @@ -179,6 +188,18 @@ } +static int +ngx_http_upstream_cmp_servers(const void *one, const void *two) +{ + ngx_http_upstream_rr_peer_t *first, *second; + + first = (ngx_http_upstream_rr_peer_t *) one; + second = (ngx_http_upstream_rr_peer_t *) two; + + return (first->weight < second->weight); +} + + ngx_int_t ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r, ngx_http_upstream_srv_conf_t *us)