From f2932dcbe561a9e23cdc2f88061a007a7a8cfc08 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 10 Dec 2007 12:29:43 +0000 Subject: [PATCH] optimize r->upstream usage --- src/http/ngx_http_upstream.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 3cab8efaf..8e83cb62a 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -381,7 +381,7 @@ ngx_http_upstream_init(ngx_http_request_t *r) } else { - host = &r->upstream->resolved->host; + host = &u->resolved->host; umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); @@ -840,10 +840,9 @@ ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u) return NGX_ERROR; } - ngx_memzero(&r->upstream->headers_in, - sizeof(ngx_http_upstream_headers_in_t)); + ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t)); - if (ngx_list_init(&r->upstream->headers_in.headers, r->pool, 8, + if (ngx_list_init(&u->headers_in.headers, r->pool, 8, sizeof(ngx_table_elt_t)) != NGX_OK) { @@ -1078,7 +1077,7 @@ ngx_http_upstream_process_header(ngx_event_t *rev) u->buffer.tag = u->output.tag; - if (ngx_list_init(&r->upstream->headers_in.headers, r->pool, 8, + if (ngx_list_init(&u->headers_in.headers, r->pool, 8, sizeof(ngx_table_elt_t)) != NGX_OK) { @@ -1247,11 +1246,11 @@ ngx_http_upstream_process_header(ngx_event_t *rev) umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); - if (r->upstream->headers_in.x_accel_redirect) { + if (u->headers_in.x_accel_redirect) { ngx_http_upstream_finalize_request(r, u, NGX_DECLINED); - part = &r->upstream->headers_in.headers.part; + part = &u->headers_in.headers.part; h = part->elts; for (i = 0; /* void */; i++) { @@ -1278,7 +1277,7 @@ ngx_http_upstream_process_header(ngx_event_t *rev) } } - uri = &r->upstream->headers_in.x_accel_redirect->value; + uri = &u->headers_in.x_accel_redirect->value; args.len = 0; args.data = NULL; flags = 0; @@ -1300,7 +1299,7 @@ ngx_http_upstream_process_header(ngx_event_t *rev) return; } - part = &r->upstream->headers_in.headers.part; + part = &u->headers_in.headers.part; h = part->elts; for (i = 0; /* void */; i++) { @@ -2164,9 +2163,9 @@ ngx_http_upstream_store(ngx_http_request_t *r, ngx_http_upstream_t *u) #endif - if (r->upstream->headers_in.last_modified) { + if (u->headers_in.last_modified) { - last_modified = &r->upstream->headers_in.last_modified->value; + last_modified = &u->headers_in.last_modified->value; lm = ngx_http_parse_time(last_modified->data, last_modified->len); @@ -2372,14 +2371,18 @@ ngx_http_upstream_cleanup(void *data) { ngx_http_request_t *r = data; + ngx_http_upstream_t *u; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "cleanup http upstream request: \"%V\"", &r->uri); - if (r->upstream->resolved && r->upstream->resolved->ctx) { - ngx_resolve_name_done(r->upstream->resolved->ctx); + u = r->upstream; + + if (u->resolved && u->resolved->ctx) { + ngx_resolve_name_done(u->resolved->ctx); } - ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE); + ngx_http_upstream_finalize_request(r, u, NGX_DONE); }