Mercurial > hg > nginx
comparison 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 |
comparison
equal
deleted
inserted
replaced
5831:575175ebf4b4 | 5832:d09b689911ac |
---|---|
696 ngx_http_upstream_finalize_request(r, u, | 696 ngx_http_upstream_finalize_request(r, u, |
697 NGX_HTTP_INTERNAL_SERVER_ERROR); | 697 NGX_HTTP_INTERNAL_SERVER_ERROR); |
698 return; | 698 return; |
699 } | 699 } |
700 | 700 |
701 u->peer.start_time = ngx_current_msec; | |
702 | |
703 if (u->conf->next_upstream_tries | |
704 && u->peer.tries > u->conf->next_upstream_tries) | |
705 { | |
706 u->peer.tries = u->conf->next_upstream_tries; | |
707 } | |
708 | |
701 ngx_http_upstream_connect(r, u); | 709 ngx_http_upstream_connect(r, u); |
702 } | 710 } |
703 | 711 |
704 | 712 |
705 #if (NGX_HTTP_CACHE) | 713 #if (NGX_HTTP_CACHE) |
3419 | 3427 |
3420 static void | 3428 static void |
3421 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, | 3429 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u, |
3422 ngx_uint_t ft_type) | 3430 ngx_uint_t ft_type) |
3423 { | 3431 { |
3432 ngx_msec_t timeout; | |
3424 ngx_uint_t status, state; | 3433 ngx_uint_t status, state; |
3425 | 3434 |
3426 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 3435 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3427 "http next upstream, %xi", ft_type); | 3436 "http next upstream, %xi", ft_type); |
3428 | 3437 |
3488 return; | 3497 return; |
3489 } | 3498 } |
3490 | 3499 |
3491 if (status) { | 3500 if (status) { |
3492 u->state->status = status; | 3501 u->state->status = status; |
3493 | 3502 timeout = u->conf->next_upstream_timeout; |
3494 if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type)) { | 3503 |
3495 | 3504 if (u->peer.tries == 0 |
3505 || !(u->conf->next_upstream & ft_type) | |
3506 || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) | |
3507 { | |
3496 #if (NGX_HTTP_CACHE) | 3508 #if (NGX_HTTP_CACHE) |
3497 | 3509 |
3498 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED | 3510 if (u->cache_status == NGX_HTTP_CACHE_EXPIRED |
3499 && (u->conf->cache_use_stale & ft_type)) | 3511 && (u->conf->cache_use_stale & ft_type)) |
3500 { | 3512 { |