diff options
author | Igor Sysoev <igor@sysoev.ru> | 2007-08-09 15:28:17 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2007-08-09 15:28:17 +0000 |
commit | 7a8e33993a1322c11c583d96c5c47498fda12859 (patch) | |
tree | 5ab024834b5492940a75c0ee1380727a4752bd84 /src | |
parent | 6876bcdad64aceecb2d4b832c6a2a5e347b17ac0 (diff) | |
download | nginx-7a8e33993a1322c11c583d96c5c47498fda12859.tar.gz nginx-7a8e33993a1322c11c583d96c5c47498fda12859.zip |
sort upstream weights
Diffstat (limited to 'src')
-rw-r--r-- | src/http/ngx_http_upstream_round_robin.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c index 8aecb47c8..ccb2eefab 100644 --- a/src/http/ngx_http_upstream_round_robin.c +++ b/src/http/ngx_http_upstream_round_robin.c @@ -9,6 +9,7 @@ #include <ngx_http.h> +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 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, 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 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, 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 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, } +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) |