comparison src/http/ngx_http_upstream_round_robin.c @ 1379:cc8ac1936aa4

sort upstream weights
author Igor Sysoev <igor@sysoev.ru>
date Thu, 09 Aug 2007 15:28:17 +0000
parents 0be898896d1a
children ab553c23bd3a
comparison
equal deleted inserted replaced
1378:0be898896d1a 1379:cc8ac1936aa4
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 10
11 11
12 static int ngx_http_upstream_cmp_servers(const void *one, const void *two);
12 static ngx_uint_t 13 static ngx_uint_t
13 ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers); 14 ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers);
14 15
15 16
16 ngx_int_t 17 ngx_int_t
67 } 68 }
68 } 69 }
69 70
70 us->peer.data = peers; 71 us->peer.data = peers;
71 72
73 ngx_sort(&peers->peer[0], (size_t) n,
74 sizeof(ngx_http_upstream_rr_peer_t),
75 ngx_http_upstream_cmp_servers);
76
72 /* backup servers */ 77 /* backup servers */
73 78
74 n = 0; 79 n = 0;
75 80
76 for (i = 0; i < us->servers->nelts; i++) { 81 for (i = 0; i < us->servers->nelts; i++) {
116 } 121 }
117 } 122 }
118 123
119 peers->next = backup; 124 peers->next = backup;
120 125
126 ngx_sort(&backup->peer[0], (size_t) n,
127 sizeof(ngx_http_upstream_rr_peer_t),
128 ngx_http_upstream_cmp_servers);
129
121 return NGX_OK; 130 return NGX_OK;
122 } 131 }
123 132
124 133
125 /* an upstream implicitly defined by proxy_pass, etc. */ 134 /* an upstream implicitly defined by proxy_pass, etc. */
177 186
178 return NGX_OK; 187 return NGX_OK;
179 } 188 }
180 189
181 190
191 static int
192 ngx_http_upstream_cmp_servers(const void *one, const void *two)
193 {
194 ngx_http_upstream_rr_peer_t *first, *second;
195
196 first = (ngx_http_upstream_rr_peer_t *) one;
197 second = (ngx_http_upstream_rr_peer_t *) two;
198
199 return (first->weight < second->weight);
200 }
201
202
182 ngx_int_t 203 ngx_int_t
183 ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r, 204 ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
184 ngx_http_upstream_srv_conf_t *us) 205 ngx_http_upstream_srv_conf_t *us)
185 { 206 {
186 ngx_uint_t n; 207 ngx_uint_t n;