Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: $upstream_header_time variable.

Homutov Vladimir
January 15, 2015 08:54AM
details: http://hg.nginx.org/nginx/rev/0a198a517eaf
branches:
changeset: 5964:0a198a517eaf
user: Vladimir Homutov <vl@nginx.com>
date: Wed Jan 14 09:03:35 2015 +0300
description:
Upstream: $upstream_header_time variable.

Keeps time spent on obtaining the header from an upstream server. The value is
formatted similar to the $upstream_response_time variable.

diffstat:

src/http/ngx_http_upstream.c | 24 ++++++++++++++++++++++--
src/http/ngx_http_upstream.h | 2 ++
2 files changed, 24 insertions(+), 2 deletions(-)

diffs (74 lines):

diff -r e0920ea61632 -r 0a198a517eaf src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Tue Jan 13 20:13:16 2015 +0300
+++ b/src/http/ngx_http_upstream.c Wed Jan 14 09:03:35 2015 +0300
@@ -359,6 +359,10 @@ static ngx_http_variable_t ngx_http_ups
ngx_http_upstream_status_variable, 0,
NGX_HTTP_VAR_NOCACHEABLE, 0 },

+ { ngx_string("upstream_header_time"), NULL,
+ ngx_http_upstream_response_time_variable, 1,
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
{ ngx_string("upstream_response_time"), NULL,
ngx_http_upstream_response_time_variable, 0,
NGX_HTTP_VAR_NOCACHEABLE, 0 },
@@ -1315,6 +1319,7 @@ ngx_http_upstream_connect(ngx_http_reque
tp = ngx_timeofday();
u->state->response_sec = tp->sec;
u->state->response_msec = tp->msec;
+ u->state->header_sec = (time_t) NGX_ERROR;

rc = ngx_event_connect_peer(&u->peer);

@@ -1836,6 +1841,7 @@ ngx_http_upstream_process_header(ngx_htt
{
ssize_t n;
ngx_int_t rc;
+ ngx_time_t *tp;
ngx_connection_t *c;

c = u->peer.connection;
@@ -1956,6 +1962,10 @@ ngx_http_upstream_process_header(ngx_htt

/* rc == NGX_OK */

+ tp = ngx_timeofday();
+ u->state->header_sec = tp->sec - u->state->response_sec;
+ u->state->header_msec = tp->msec - u->state->response_msec;
+
if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {

if (ngx_http_upstream_test_next(r, u) == NGX_OK) {
@@ -4822,8 +4832,18 @@ ngx_http_upstream_response_time_variable

for ( ;; ) {
if (state[i].status) {
- ms = (ngx_msec_int_t)
- (state[i].response_sec * 1000 + state[i].response_msec);
+
+ if (data
+ && state[i].header_sec != (time_t) NGX_ERROR)
+ {
+ ms = (ngx_msec_int_t)
+ (state[i].header_sec * 1000 + state[i].header_msec);
+
+ } else {
+ ms = (ngx_msec_int_t)
+ (state[i].response_sec * 1000 + state[i].response_msec);
+ }
+
ms = ngx_max(ms, 0);
p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000);

diff -r e0920ea61632 -r 0a198a517eaf src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h Tue Jan 13 20:13:16 2015 +0300
+++ b/src/http/ngx_http_upstream.h Wed Jan 14 09:03:35 2015 +0300
@@ -60,6 +60,8 @@ typedef struct {
ngx_uint_t status;
time_t response_sec;
ngx_uint_t response_msec;
+ time_t header_sec;
+ ngx_uint_t header_msec;
off_t response_length;

ngx_str_t *peer;

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

[nginx] Upstream: $upstream_header_time variable.

Homutov Vladimir 2076 January 15, 2015 08:54AM



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

Online Users

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