mirror of
https://github.com/nginx/nginx.git
synced 2024-12-18 21:23:36 -06:00
Upstream: improved peer selection concurrency for hash and ip_hash.
This commit is contained in:
parent
63e8a1d926
commit
2eab9efbe4
@ -176,7 +176,7 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
||||
"get hash peer, try: %ui", pc->tries);
|
||||
|
||||
ngx_http_upstream_rr_peers_wlock(hp->rrp.peers);
|
||||
ngx_http_upstream_rr_peers_rlock(hp->rrp.peers);
|
||||
|
||||
if (hp->tries > 20 || hp->rrp.peers->single) {
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
@ -228,10 +228,13 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
goto next;
|
||||
}
|
||||
|
||||
ngx_http_upstream_rr_peer_lock(hp->rrp.peers, peer);
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
||||
"get hash peer, value:%uD, peer:%ui", hp->hash, p);
|
||||
|
||||
if (peer->down) {
|
||||
ngx_http_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@ -239,10 +242,12 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
&& peer->fails >= peer->max_fails
|
||||
&& now - peer->checked <= peer->fail_timeout)
|
||||
{
|
||||
ngx_http_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (peer->max_conns && peer->conns >= peer->max_conns) {
|
||||
ngx_http_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@ -268,6 +273,7 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
peer->checked = now;
|
||||
}
|
||||
|
||||
ngx_http_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
|
||||
hp->rrp.tried[n] |= m;
|
||||
|
@ -161,7 +161,7 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
|
||||
/* TODO: cached */
|
||||
|
||||
ngx_http_upstream_rr_peers_wlock(iphp->rrp.peers);
|
||||
ngx_http_upstream_rr_peers_rlock(iphp->rrp.peers);
|
||||
|
||||
if (iphp->tries > 20 || iphp->rrp.peers->single) {
|
||||
ngx_http_upstream_rr_peers_unlock(iphp->rrp.peers);
|
||||
@ -201,7 +201,10 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
||||
"get ip hash peer, hash: %ui %04XL", p, (uint64_t) m);
|
||||
|
||||
ngx_http_upstream_rr_peer_lock(iphp->rrp.peers, peer);
|
||||
|
||||
if (peer->down) {
|
||||
ngx_http_upstream_rr_peer_unlock(iphp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@ -209,10 +212,12 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
&& peer->fails >= peer->max_fails
|
||||
&& now - peer->checked <= peer->fail_timeout)
|
||||
{
|
||||
ngx_http_upstream_rr_peer_unlock(iphp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (peer->max_conns && peer->conns >= peer->max_conns) {
|
||||
ngx_http_upstream_rr_peer_unlock(iphp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@ -238,6 +243,7 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
peer->checked = now;
|
||||
}
|
||||
|
||||
ngx_http_upstream_rr_peer_unlock(iphp->rrp.peers, peer);
|
||||
ngx_http_upstream_rr_peers_unlock(iphp->rrp.peers);
|
||||
|
||||
iphp->rrp.tried[n] |= m;
|
||||
|
@ -176,7 +176,7 @@ ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pc->log, 0,
|
||||
"get hash peer, try: %ui", pc->tries);
|
||||
|
||||
ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers);
|
||||
ngx_stream_upstream_rr_peers_rlock(hp->rrp.peers);
|
||||
|
||||
if (hp->tries > 20 || hp->rrp.peers->single) {
|
||||
ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
@ -227,10 +227,13 @@ ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
goto next;
|
||||
}
|
||||
|
||||
ngx_stream_upstream_rr_peer_lock(hp->rrp.peers, peer);
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_STREAM, pc->log, 0,
|
||||
"get hash peer, value:%uD, peer:%ui", hp->hash, p);
|
||||
|
||||
if (peer->down) {
|
||||
ngx_stream_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@ -238,10 +241,12 @@ ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
&& peer->fails >= peer->max_fails
|
||||
&& now - peer->checked <= peer->fail_timeout)
|
||||
{
|
||||
ngx_stream_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (peer->max_conns && peer->conns >= peer->max_conns) {
|
||||
ngx_stream_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@ -267,6 +272,7 @@ ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
peer->checked = now;
|
||||
}
|
||||
|
||||
ngx_stream_upstream_rr_peer_unlock(hp->rrp.peers, peer);
|
||||
ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
|
||||
hp->rrp.tried[n] |= m;
|
||||
|
Loading…
Reference in New Issue
Block a user