Mercurial > hg > nginx
comparison src/http/modules/ngx_http_upstream_hash_module.c @ 6102:3264b7828f72
Upstreams: locking.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 14 Apr 2015 19:01:23 +0300 |
parents | c44459611d91 |
children | b6047abf5f30 |
comparison
equal
deleted
inserted
replaced
6101:682d8222c6b1 | 6102:3264b7828f72 |
---|---|
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 |
179 ngx_http_upstream_rr_peers_wlock(hp->rrp.peers); | |
180 | |
179 if (hp->tries > 20 || hp->rrp.peers->single) { | 181 if (hp->tries > 20 || hp->rrp.peers->single) { |
182 ngx_http_upstream_rr_peers_unlock(hp->rrp.peers); | |
180 return hp->get_rr_peer(pc, &hp->rrp); | 183 return hp->get_rr_peer(pc, &hp->rrp); |
181 } | 184 } |
182 | 185 |
183 now = ngx_time(); | 186 now = ngx_time(); |
184 | 187 |
256 break; | 259 break; |
257 | 260 |
258 next: | 261 next: |
259 | 262 |
260 if (++hp->tries > 20) { | 263 if (++hp->tries > 20) { |
264 ngx_http_upstream_rr_peers_unlock(hp->rrp.peers); | |
261 return hp->get_rr_peer(pc, &hp->rrp); | 265 return hp->get_rr_peer(pc, &hp->rrp); |
262 } | 266 } |
263 } | 267 } |
264 | 268 |
265 hp->rrp.current = peer; | 269 hp->rrp.current = peer; |
271 peer->conns++; | 275 peer->conns++; |
272 | 276 |
273 if (now - peer->checked > peer->fail_timeout) { | 277 if (now - peer->checked > peer->fail_timeout) { |
274 peer->checked = now; | 278 peer->checked = now; |
275 } | 279 } |
280 | |
281 ngx_http_upstream_rr_peers_unlock(hp->rrp.peers); | |
276 | 282 |
277 hp->rrp.tried[n] |= m; | 283 hp->rrp.tried[n] |= m; |
278 | 284 |
279 return NGX_OK; | 285 return NGX_OK; |
280 } | 286 } |
463 | 469 |
464 hp = r->upstream->peer.data; | 470 hp = r->upstream->peer.data; |
465 hcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_hash_module); | 471 hcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_hash_module); |
466 | 472 |
467 hash = ngx_crc32_long(hp->key.data, hp->key.len); | 473 hash = ngx_crc32_long(hp->key.data, hp->key.len); |
474 | |
475 ngx_http_upstream_rr_peers_rlock(hp->rrp.peers); | |
476 | |
468 hp->hash = ngx_http_upstream_find_chash_point(hcf->points, hash); | 477 hp->hash = ngx_http_upstream_find_chash_point(hcf->points, hash); |
478 | |
479 ngx_http_upstream_rr_peers_unlock(hp->rrp.peers); | |
469 | 480 |
470 return NGX_OK; | 481 return NGX_OK; |
471 } | 482 } |
472 | 483 |
473 | 484 |
487 ngx_http_upstream_hash_srv_conf_t *hcf; | 498 ngx_http_upstream_hash_srv_conf_t *hcf; |
488 | 499 |
489 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | 500 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
490 "get consistent hash peer, try: %ui", pc->tries); | 501 "get consistent hash peer, try: %ui", pc->tries); |
491 | 502 |
503 ngx_http_upstream_rr_peers_wlock(hp->rrp.peers); | |
504 | |
492 pc->cached = 0; | 505 pc->cached = 0; |
493 pc->connection = NULL; | 506 pc->connection = NULL; |
494 | 507 |
495 now = ngx_time(); | 508 now = ngx_time(); |
496 hcf = hp->conf; | 509 hcf = hp->conf; |
559 | 572 |
560 hp->hash++; | 573 hp->hash++; |
561 hp->tries++; | 574 hp->tries++; |
562 | 575 |
563 if (hp->tries >= points->number) { | 576 if (hp->tries >= points->number) { |
577 ngx_http_upstream_rr_peers_unlock(hp->rrp.peers); | |
564 return NGX_BUSY; | 578 return NGX_BUSY; |
565 } | 579 } |
566 } | 580 } |
567 | 581 |
568 found: | 582 found: |
576 best->conns++; | 590 best->conns++; |
577 | 591 |
578 if (now - best->checked > best->fail_timeout) { | 592 if (now - best->checked > best->fail_timeout) { |
579 best->checked = now; | 593 best->checked = now; |
580 } | 594 } |
595 | |
596 ngx_http_upstream_rr_peers_unlock(hp->rrp.peers); | |
581 | 597 |
582 n = best_i / (8 * sizeof(uintptr_t)); | 598 n = best_i / (8 * sizeof(uintptr_t)); |
583 m = (uintptr_t) 1 << best_i % (8 * sizeof(uintptr_t)); | 599 m = (uintptr_t) 1 << best_i % (8 * sizeof(uintptr_t)); |
584 | 600 |
585 hp->rrp.tried[n] |= m; | 601 hp->rrp.tried[n] |= m; |