diff options
author | Roman Arutyunyan <arut@nginx.com> | 2014-09-12 18:50:47 +0400 |
---|---|---|
committer | Roman Arutyunyan <arut@nginx.com> | 2014-09-12 18:50:47 +0400 |
commit | 02ce6c415f07ea8d7fa6b59a17ee2f02e77ab66b (patch) | |
tree | 9d7fbdf388e15bfe1f2c4577e0d786156c5db77a /src/http/ngx_http_upstream.c | |
parent | cfc3db1972f1eb96accaf4c04095912e176aecd3 (diff) | |
download | nginx-02ce6c415f07ea8d7fa6b59a17ee2f02e77ab66b.tar.gz nginx-02ce6c415f07ea8d7fa6b59a17ee2f02e77ab66b.zip |
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.
Diffstat (limited to 'src/http/ngx_http_upstream.c')
-rw-r--r-- | src/http/ngx_http_upstream.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 996dc8a85..000c6de69 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -698,6 +698,14 @@ found: 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 @@ static void 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 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, if (status) { u->state->status = status; + timeout = u->conf->next_upstream_timeout; - if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type)) { - + 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 |