comparison src/http/ngx_http_upstream_round_robin.c @ 5135:0811376954e4

Upstream: removed sorting of upstream servers. Sorting of upstream servers by their weights is not required by current balancing algorithms. This will likely change mapping to backends served by ip_hash weighted upstreams.
author Ruslan Ermilov <ru@nginx.com>
date Mon, 25 Mar 2013 13:41:30 +0000
parents 089a662c17d1
children 88a302caca75
comparison
equal deleted inserted replaced
5134:c788e54090de 5135:0811376954e4
8 #include <ngx_config.h> 8 #include <ngx_config.h>
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <ngx_http.h> 10 #include <ngx_http.h>
11 11
12 12
13 static ngx_int_t ngx_http_upstream_cmp_servers(const void *one,
14 const void *two);
15 static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer( 13 static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer(
16 ngx_http_upstream_rr_peer_data_t *rrp); 14 ngx_http_upstream_rr_peer_data_t *rrp);
17 15
18 #if (NGX_HTTP_SSL) 16 #if (NGX_HTTP_SSL)
19 17
91 } 89 }
92 } 90 }
93 91
94 us->peer.data = peers; 92 us->peer.data = peers;
95 93
96 ngx_sort(&peers->peer[0], (size_t) n,
97 sizeof(ngx_http_upstream_rr_peer_t),
98 ngx_http_upstream_cmp_servers);
99
100 /* backup servers */ 94 /* backup servers */
101 95
102 n = 0; 96 n = 0;
103 w = 0; 97 w = 0;
104 98
149 } 143 }
150 } 144 }
151 145
152 peers->next = backup; 146 peers->next = backup;
153 147
154 ngx_sort(&backup->peer[0], (size_t) n,
155 sizeof(ngx_http_upstream_rr_peer_t),
156 ngx_http_upstream_cmp_servers);
157
158 return NGX_OK; 148 return NGX_OK;
159 } 149 }
160 150
161 151
162 /* an upstream implicitly defined by proxy_pass, etc. */ 152 /* an upstream implicitly defined by proxy_pass, etc. */
214 204
215 return NGX_OK; 205 return NGX_OK;
216 } 206 }
217 207
218 208
219 static ngx_int_t
220 ngx_http_upstream_cmp_servers(const void *one, const void *two)
221 {
222 ngx_http_upstream_rr_peer_t *first, *second;
223
224 first = (ngx_http_upstream_rr_peer_t *) one;
225 second = (ngx_http_upstream_rr_peer_t *) two;
226
227 return (first->weight < second->weight);
228 }
229
230
231 ngx_int_t 209 ngx_int_t
232 ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r, 210 ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
233 ngx_http_upstream_srv_conf_t *us) 211 ngx_http_upstream_srv_conf_t *us)
234 { 212 {
235 ngx_uint_t n; 213 ngx_uint_t n;