Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: cached connections now tested against next_upstream.

Maxim Dounin
March 28, 2016 12:54PM
details: http://hg.nginx.org/nginx/rev/984687f25998
branches:
changeset: 6466:984687f25998
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon Mar 28 19:49:52 2016 +0300
description:
Upstream: cached connections now tested against next_upstream.

Much like normal connections, cached connections are now tested against
u->conf->next_upstream, and u->state->status is now always set.

This allows to disable additional tries even with upstream keepalive
by using "proxy_next_upstream off".

diffstat:

src/http/ngx_http_upstream.c | 115 ++++++++++++++++++++----------------------
1 files changed, 54 insertions(+), 61 deletions(-)

diffs (138 lines):

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -3947,42 +3947,36 @@ ngx_http_upstream_next(ngx_http_request_
"upstream timed out");
}

- if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR
- && (!u->request_sent || !r->request_body_no_buffering))
- {
- status = 0;
-
+ if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {
/* TODO: inform balancer instead */
-
u->peer.tries++;
-
- } else {
- switch (ft_type) {
-
- case NGX_HTTP_UPSTREAM_FT_TIMEOUT:
- status = NGX_HTTP_GATEWAY_TIME_OUT;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_500:
- status = NGX_HTTP_INTERNAL_SERVER_ERROR;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_403:
- status = NGX_HTTP_FORBIDDEN;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_404:
- status = NGX_HTTP_NOT_FOUND;
- break;
-
- /*
- * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING
- * never reach here
- */
-
- default:
- status = NGX_HTTP_BAD_GATEWAY;
- }
+ }
+
+ switch (ft_type) {
+
+ case NGX_HTTP_UPSTREAM_FT_TIMEOUT:
+ status = NGX_HTTP_GATEWAY_TIME_OUT;
+ break;
+
+ case NGX_HTTP_UPSTREAM_FT_HTTP_500:
+ status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ break;
+
+ case NGX_HTTP_UPSTREAM_FT_HTTP_403:
+ status = NGX_HTTP_FORBIDDEN;
+ break;
+
+ case NGX_HTTP_UPSTREAM_FT_HTTP_404:
+ status = NGX_HTTP_NOT_FOUND;
+ break;
+
+ /*
+ * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING
+ * never reach here
+ */
+
+ default:
+ status = NGX_HTTP_BAD_GATEWAY;
}

if (r->connection->error) {
@@ -3991,37 +3985,36 @@ ngx_http_upstream_next(ngx_http_request_
return;
}

- if (status) {
- u->state->status = status;
- timeout = u->conf->next_upstream_timeout;
-
- if (u->peer.tries == 0
- || !(u->conf->next_upstream & ft_type)
- || (u->request_sent && r->request_body_no_buffering)
- || (timeout && ngx_current_msec - u->peer.start_time >= timeout))
+ u->state->status = status;
+
+ timeout = u->conf->next_upstream_timeout;
+
+ if (u->peer.tries == 0
+ || !(u->conf->next_upstream & ft_type)
+ || (u->request_sent && r->request_body_no_buffering)
+ || (timeout && ngx_current_msec - u->peer.start_time >= timeout))
+ {
+#if (NGX_HTTP_CACHE)
+
+ if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
+ && (u->conf->cache_use_stale & ft_type))
{
-#if (NGX_HTTP_CACHE)
-
- if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
- && (u->conf->cache_use_stale & ft_type))
- {
- ngx_int_t rc;
-
- rc = u->reinit_request(r);
-
- if (rc == NGX_OK) {
- u->cache_status = NGX_HTTP_CACHE_STALE;
- rc = ngx_http_upstream_cache_send(r, u);
- }
-
- ngx_http_upstream_finalize_request(r, u, rc);
- return;
+ ngx_int_t rc;
+
+ rc = u->reinit_request(r);
+
+ if (rc == NGX_OK) {
+ u->cache_status = NGX_HTTP_CACHE_STALE;
+ rc = ngx_http_upstream_cache_send(r, u);
}
+
+ ngx_http_upstream_finalize_request(r, u, rc);
+ return;
+ }
#endif

- ngx_http_upstream_finalize_request(r, u, status);
- return;
- }
+ ngx_http_upstream_finalize_request(r, u, status);
+ return;
}

if (u->peer.connection) {

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Upstream: cached connections now tested against next_upstream.

Maxim Dounin 334 March 28, 2016 12:54PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 144
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready