Mercurial > hg > nginx
comparison src/http/modules/ngx_http_upstream_hash_module.c @ 6121:b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Now that peers are stored as a list, the weighted and unweighted
cases became nearly identical.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 21 Apr 2015 19:09:04 +0300 |
parents | 3264b7828f72 |
children | bf8b6534db3a |
comparison
equal
deleted
inserted
replaced
6118:1bdfceda86a9 | 6121:b6047abf5f30 |
---|---|
168 u_char buf[NGX_INT_T_LEN]; | 168 u_char buf[NGX_INT_T_LEN]; |
169 size_t size; | 169 size_t size; |
170 uint32_t hash; | 170 uint32_t hash; |
171 ngx_int_t w; | 171 ngx_int_t w; |
172 uintptr_t m; | 172 uintptr_t m; |
173 ngx_uint_t i, n, p; | 173 ngx_uint_t n, p; |
174 ngx_http_upstream_rr_peer_t *peer; | 174 ngx_http_upstream_rr_peer_t *peer; |
175 | 175 |
176 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | 176 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
177 "get hash peer, try: %ui", pc->tries); | 177 "get hash peer, try: %ui", pc->tries); |
178 | 178 |
209 hash = (hash >> 16) & 0x7fff; | 209 hash = (hash >> 16) & 0x7fff; |
210 | 210 |
211 hp->hash += hash; | 211 hp->hash += hash; |
212 hp->rehash++; | 212 hp->rehash++; |
213 | 213 |
214 if (!hp->rrp.peers->weighted) { | 214 w = hp->hash % hp->rrp.peers->total_weight; |
215 p = hp->hash % hp->rrp.peers->number; | 215 peer = hp->rrp.peers->peer; |
216 | 216 p = 0; |
217 peer = hp->rrp.peers->peer; | 217 |
218 for (i = 0; i < p; i++) { | 218 while (w >= peer->weight) { |
219 peer = peer->next; | 219 w -= peer->weight; |
220 } | 220 peer = peer->next; |
221 | 221 p++; |
222 } else { | |
223 w = hp->hash % hp->rrp.peers->total_weight; | |
224 | |
225 for (peer = hp->rrp.peers->peer, i = 0; | |
226 peer; | |
227 peer = peer->next, i++) | |
228 { | |
229 w -= peer->weight; | |
230 if (w < 0) { | |
231 break; | |
232 } | |
233 } | |
234 | |
235 p = i; | |
236 } | 222 } |
237 | 223 |
238 n = p / (8 * sizeof(uintptr_t)); | 224 n = p / (8 * sizeof(uintptr_t)); |
239 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); | 225 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); |
240 | 226 |