Mercurial > hg > nginx
diff src/http/ngx_http_upstream.c @ 5832:d09b689911ac
Upstream: limited next_upstream time and tries (ticket #544).
The new directives {proxy,fastcgi,scgi,uwsgi,memcached}_next_upstream_tries
and {proxy,fastcgi,scgi,uwsgi,memcached}_next_upstream_timeout limit
the number of upstreams tried and the maximum time spent for these tries
when searching for a valid upstream.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Fri, 12 Sep 2014 18:50:47 +0400 |
parents | 54e9b83d00f0 |
children | 106a8bfa4f42 |
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c Fri Sep 12 18:50:46 2014 +0400 +++ b/src/http/ngx_http_upstream.c Fri Sep 12 18:50:47 2014 +0400 @@ -698,6 +698,14 @@ return; } + u->peer.start_time = ngx_current_msec; + + if (u->conf->next_upstream_tries + && u->peer.tries > u->conf->next_upstream_tries) + { + u->peer.tries = u->conf->next_upstream_tries; + } + ngx_http_upstream_connect(r, u); } @@ -3421,6 +3429,7 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, ngx_uint_t ft_type) { + ngx_msec_t timeout; ngx_uint_t status, state; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -3490,9 +3499,12 @@ if (status) { u->state->status = status; - - if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type)) { - + timeout = u->conf->next_upstream_timeout; + + if (u->peer.tries == 0 + || !(u->conf->next_upstream & ft_type) + || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) + { #if (NGX_HTTP_CACHE) if (u->cache_status == NGX_HTTP_CACHE_EXPIRED