comparison src/http/modules/ngx_http_upstream_ip_hash_module.c @ 5486:741aa3fde496

Upstream: simplified peer selection loop in the "ip_hash" module. Conditions for skipping ineligible peers are rewritten to make adding of new conditions simpler and be in line with the "round_robin" and "least_conn" modules. No functional changes.
author Vladimir Homutov <vl@nginx.com>
date Mon, 09 Dec 2013 13:43:27 +0400
parents 2fda9065d0f4
children a2bf26774cd3
comparison
equal deleted inserted replaced
5485:8958656a8060 5486:741aa3fde496
195 } 195 }
196 196
197 n = p / (8 * sizeof(uintptr_t)); 197 n = p / (8 * sizeof(uintptr_t));
198 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); 198 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t));
199 199
200 if (!(iphp->rrp.tried[n] & m)) { 200 if (iphp->rrp.tried[n] & m) {
201 201 goto next;
202 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0, 202 }
203 "get ip hash peer, hash: %ui %04XA", p, m); 203
204 204 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
205 peer = &iphp->rrp.peers->peer[p]; 205 "get ip hash peer, hash: %ui %04XA", p, m);
206 206
207 /* ngx_lock_mutex(iphp->rrp.peers->mutex); */ 207 peer = &iphp->rrp.peers->peer[p];
208 208
209 if (!peer->down) { 209 /* ngx_lock_mutex(iphp->rrp.peers->mutex); */
210 210
211 if (peer->max_fails == 0 || peer->fails < peer->max_fails) { 211 if (peer->down) {
212 break; 212 goto next_try;
213 } 213 }
214 214
215 if (now - peer->checked > peer->fail_timeout) { 215 if (peer->max_fails
216 peer->checked = now; 216 && peer->fails >= peer->max_fails
217 break; 217 && now - peer->checked <= peer->fail_timeout)
218 } 218 {
219 } 219 goto next_try;
220 220 }
221 iphp->rrp.tried[n] |= m; 221
222 222 break;
223 /* ngx_unlock_mutex(iphp->rrp.peers->mutex); */ 223
224 224 next_try:
225 pc->tries--; 225
226 } 226 iphp->rrp.tried[n] |= m;
227
228 /* ngx_unlock_mutex(iphp->rrp.peers->mutex); */
229
230 pc->tries--;
231
232 next:
227 233
228 if (++iphp->tries >= 20) { 234 if (++iphp->tries >= 20) {
229 return iphp->get_rr_peer(pc, &iphp->rrp); 235 return iphp->get_rr_peer(pc, &iphp->rrp);
230 } 236 }
231 } 237 }
233 iphp->rrp.current = p; 239 iphp->rrp.current = p;
234 240
235 pc->sockaddr = peer->sockaddr; 241 pc->sockaddr = peer->sockaddr;
236 pc->socklen = peer->socklen; 242 pc->socklen = peer->socklen;
237 pc->name = &peer->name; 243 pc->name = &peer->name;
244
245 if (now - peer->checked > peer->fail_timeout) {
246 peer->checked = now;
247 }
238 248
239 /* ngx_unlock_mutex(iphp->rrp.peers->mutex); */ 249 /* ngx_unlock_mutex(iphp->rrp.peers->mutex); */
240 250
241 iphp->rrp.tried[n] |= m; 251 iphp->rrp.tried[n] |= m;
242 iphp->hash = hash; 252 iphp->hash = hash;