Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_upstream_ip_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 | 55dc5f7eb921 |
children | f01ab2dbcfdc |
comparison
equal
deleted
inserted
replaced
6118:1bdfceda86a9 | 6121:b6047abf5f30 |
---|---|
179 | 179 |
180 for (i = 0; i < (ngx_uint_t) iphp->addrlen; i++) { | 180 for (i = 0; i < (ngx_uint_t) iphp->addrlen; i++) { |
181 hash = (hash * 113 + iphp->addr[i]) % 6271; | 181 hash = (hash * 113 + iphp->addr[i]) % 6271; |
182 } | 182 } |
183 | 183 |
184 if (!iphp->rrp.peers->weighted) { | 184 w = hash % iphp->rrp.peers->total_weight; |
185 p = hash % iphp->rrp.peers->number; | 185 peer = iphp->rrp.peers->peer; |
186 | 186 p = 0; |
187 peer = iphp->rrp.peers->peer; | 187 |
188 for (i = 0; i < p; i++) { | 188 while (w >= peer->weight) { |
189 peer = peer->next; | 189 w -= peer->weight; |
190 } | 190 peer = peer->next; |
191 | 191 p++; |
192 } else { | |
193 w = hash % iphp->rrp.peers->total_weight; | |
194 | |
195 for (peer = iphp->rrp.peers->peer, i = 0; | |
196 peer; | |
197 peer = peer->next, i++) | |
198 { | |
199 w -= peer->weight; | |
200 if (w < 0) { | |
201 break; | |
202 } | |
203 } | |
204 | |
205 p = i; | |
206 } | 192 } |
207 | 193 |
208 n = p / (8 * sizeof(uintptr_t)); | 194 n = p / (8 * sizeof(uintptr_t)); |
209 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); | 195 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); |
210 | 196 |