Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: do not unnecessarily create per-request upstreams.

October 31, 2016 04:42PM
details: http://hg.nginx.org/nginx/rev/906ac20234ed
branches:
changeset: 6786:906ac20234ed
user: Ruslan Ermilov <ru@nginx.com>
date: Mon Oct 31 18:33:36 2016 +0300
description:
Upstream: do not unnecessarily create per-request upstreams.

If proxy_pass (and friends) with variables evaluates an upstream
specified with literal address, nginx always created a per-request
upstream.

Now, if there's a matching upstream specified in the configuration
(either implicit or explicit), it will be used instead.

diffstat:

src/http/ngx_http_upstream.c | 34 +++++++++++++++++-----------------
src/stream/ngx_stream_proxy_module.c | 34 +++++++++++++++++-----------------
2 files changed, 34 insertions(+), 34 deletions(-)

diffs (102 lines):

diff -r d1d0dd69a419 -r 906ac20234ed src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Mon Oct 31 18:33:33 2016 +0300
+++ b/src/http/ngx_http_upstream.c Mon Oct 31 18:33:36 2016 +0300
@@ -654,6 +654,23 @@ ngx_http_upstream_init_request(ngx_http_

host = &u->resolved->host;

+ umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
+
+ uscfp = umcf->upstreams.elts;
+
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
+
+ uscf = uscfp[i];
+
+ if (uscf->host.len == host->len
+ && ((uscf->port == 0 && u->resolved->no_port)
+ || uscf->port == u->resolved->port)
+ && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)
+ {
+ goto found;
+ }
+ }
+
if (u->resolved->sockaddr) {

if (u->resolved->port == 0
@@ -679,23 +696,6 @@ ngx_http_upstream_init_request(ngx_http_
return;
}

- umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
-
- uscfp = umcf->upstreams.elts;
-
- for (i = 0; i < umcf->upstreams.nelts; i++) {
-
- uscf = uscfp[i];
-
- if (uscf->host.len == host->len
- && ((uscf->port == 0 && u->resolved->no_port)
- || uscf->port == u->resolved->port)
- && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)
- {
- goto found;
- }
- }
-
if (u->resolved->port == 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"no port in upstream \"%V\"", host);
diff -r d1d0dd69a419 -r 906ac20234ed src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c Mon Oct 31 18:33:33 2016 +0300
+++ b/src/stream/ngx_stream_proxy_module.c Mon Oct 31 18:33:36 2016 +0300
@@ -433,6 +433,23 @@ ngx_stream_proxy_handler(ngx_stream_sess

host = &u->resolved->host;

+ umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module);
+
+ uscfp = umcf->upstreams.elts;
+
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
+
+ uscf = uscfp[i];
+
+ if (uscf->host.len == host->len
+ && ((uscf->port == 0 && u->resolved->no_port)
+ || uscf->port == u->resolved->port)
+ && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)
+ {
+ goto found;
+ }
+ }
+
if (u->resolved->sockaddr) {

if (u->resolved->port == 0
@@ -456,23 +473,6 @@ ngx_stream_proxy_handler(ngx_stream_sess
return;
}

- umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module);
-
- uscfp = umcf->upstreams.elts;
-
- for (i = 0; i < umcf->upstreams.nelts; i++) {
-
- uscf = uscfp[i];
-
- if (uscf->host.len == host->len
- && ((uscf->port == 0 && u->resolved->no_port)
- || uscf->port == u->resolved->port)
- && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)
- {
- goto found;
- }
- }
-
if (u->resolved->port == 0) {
ngx_log_error(NGX_LOG_ERR, c->log, 0,
"no port in upstream \"%V\"", host);

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

[nginx] Upstream: do not unnecessarily create per-request upstreams.

ru@nginx.com 521 October 31, 2016 04:42PM



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

Online Users

Guests: 305
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