comparison src/http/ngx_http_upstream.c @ 5964:0a198a517eaf

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.
author Vladimir Homutov <vl@nginx.com>
date Wed, 14 Jan 2015 09:03:35 +0300
parents e9effef98874
children 99639bfdfa2a
comparison
equal deleted inserted replaced
5963:e0920ea61632 5964:0a198a517eaf
357 357
358 { ngx_string("upstream_status"), NULL, 358 { ngx_string("upstream_status"), NULL,
359 ngx_http_upstream_status_variable, 0, 359 ngx_http_upstream_status_variable, 0,
360 NGX_HTTP_VAR_NOCACHEABLE, 0 }, 360 NGX_HTTP_VAR_NOCACHEABLE, 0 },
361 361
362 { ngx_string("upstream_header_time"), NULL,
363 ngx_http_upstream_response_time_variable, 1,
364 NGX_HTTP_VAR_NOCACHEABLE, 0 },
365
362 { ngx_string("upstream_response_time"), NULL, 366 { ngx_string("upstream_response_time"), NULL,
363 ngx_http_upstream_response_time_variable, 0, 367 ngx_http_upstream_response_time_variable, 0,
364 NGX_HTTP_VAR_NOCACHEABLE, 0 }, 368 NGX_HTTP_VAR_NOCACHEABLE, 0 },
365 369
366 { ngx_string("upstream_response_length"), NULL, 370 { ngx_string("upstream_response_length"), NULL,
1313 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); 1317 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
1314 1318
1315 tp = ngx_timeofday(); 1319 tp = ngx_timeofday();
1316 u->state->response_sec = tp->sec; 1320 u->state->response_sec = tp->sec;
1317 u->state->response_msec = tp->msec; 1321 u->state->response_msec = tp->msec;
1322 u->state->header_sec = (time_t) NGX_ERROR;
1318 1323
1319 rc = ngx_event_connect_peer(&u->peer); 1324 rc = ngx_event_connect_peer(&u->peer);
1320 1325
1321 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1326 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1322 "http upstream connect: %i", rc); 1327 "http upstream connect: %i", rc);
1834 static void 1839 static void
1835 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) 1840 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
1836 { 1841 {
1837 ssize_t n; 1842 ssize_t n;
1838 ngx_int_t rc; 1843 ngx_int_t rc;
1844 ngx_time_t *tp;
1839 ngx_connection_t *c; 1845 ngx_connection_t *c;
1840 1846
1841 c = u->peer.connection; 1847 c = u->peer.connection;
1842 1848
1843 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, 1849 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
1953 NGX_HTTP_INTERNAL_SERVER_ERROR); 1959 NGX_HTTP_INTERNAL_SERVER_ERROR);
1954 return; 1960 return;
1955 } 1961 }
1956 1962
1957 /* rc == NGX_OK */ 1963 /* rc == NGX_OK */
1964
1965 tp = ngx_timeofday();
1966 u->state->header_sec = tp->sec - u->state->response_sec;
1967 u->state->header_msec = tp->msec - u->state->response_msec;
1958 1968
1959 if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) { 1969 if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {
1960 1970
1961 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { 1971 if (ngx_http_upstream_test_next(r, u) == NGX_OK) {
1962 return; 1972 return;
4820 i = 0; 4830 i = 0;
4821 state = r->upstream_states->elts; 4831 state = r->upstream_states->elts;
4822 4832
4823 for ( ;; ) { 4833 for ( ;; ) {
4824 if (state[i].status) { 4834 if (state[i].status) {
4825 ms = (ngx_msec_int_t) 4835
4826 (state[i].response_sec * 1000 + state[i].response_msec); 4836 if (data
4837 && state[i].header_sec != (time_t) NGX_ERROR)
4838 {
4839 ms = (ngx_msec_int_t)
4840 (state[i].header_sec * 1000 + state[i].header_msec);
4841
4842 } else {
4843 ms = (ngx_msec_int_t)
4844 (state[i].response_sec * 1000 + state[i].response_msec);
4845 }
4846
4827 ms = ngx_max(ms, 0); 4847 ms = ngx_max(ms, 0);
4828 p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000); 4848 p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000);
4829 4849
4830 } else { 4850 } else {
4831 *p++ = '-'; 4851 *p++ = '-';