[nginx] Upstream: times to obtain header/response are stored as ...
Ruslan Ermilov
ru at nginx.com
Fri May 15 22:32:42 UTC 2015
details: http://hg.nginx.org/nginx/rev/59fc60585f1e
branches:
changeset: 6146:59fc60585f1e
user: Ruslan Ermilov <ru at nginx.com>
date: Sat May 16 01:31:04 2015 +0300
description:
Upstream: times to obtain header/response are stored as ngx_msec_t.
diffstat:
src/http/ngx_http_upstream.c | 37 +++++++++++--------------------------
src/http/ngx_http_upstream.h | 6 ++----
2 files changed, 13 insertions(+), 30 deletions(-)
diffs (111 lines):
diff -r 0b8f6f75245d -r 59fc60585f1e src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Fri May 15 17:15:33 2015 +0300
+++ b/src/http/ngx_http_upstream.c Sat May 16 01:31:04 2015 +0300
@@ -1300,15 +1300,12 @@ static void
ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_int_t rc;
- ngx_time_t *tp;
ngx_connection_t *c;
r->connection->log->action = "connecting to upstream";
- if (u->state && u->state->response_sec) {
- tp = ngx_timeofday();
- u->state->response_sec = tp->sec - u->state->response_sec;
- u->state->response_msec = tp->msec - u->state->response_msec;
+ if (u->state && u->state->response_time) {
+ u->state->response_time = ngx_current_msec - u->state->response_time;
}
u->state = ngx_array_push(r->upstream_states);
@@ -1320,10 +1317,8 @@ ngx_http_upstream_connect(ngx_http_reque
ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
- tp = ngx_timeofday();
- u->state->response_sec = tp->sec;
- u->state->response_msec = tp->msec;
- u->state->header_sec = (time_t) NGX_ERROR;
+ u->state->response_time = ngx_current_msec;
+ u->state->header_time = (ngx_msec_t) -1;
rc = ngx_event_connect_peer(&u->peer);
@@ -2017,7 +2012,6 @@ 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;
@@ -2138,9 +2132,7 @@ 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;
+ u->state->header_time = ngx_current_msec - u->state->response_time;
if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {
@@ -3923,8 +3915,7 @@ static void
ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_int_t rc)
{
- ngx_uint_t flush;
- ngx_time_t *tp;
+ ngx_uint_t flush;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc);
@@ -3943,10 +3934,8 @@ ngx_http_upstream_finalize_request(ngx_h
u->resolved->ctx = NULL;
}
- if (u->state && u->state->response_sec) {
- tp = ngx_timeofday();
- u->state->response_sec = tp->sec - u->state->response_sec;
- u->state->response_msec = tp->msec - u->state->response_msec;
+ if (u->state && u->state->response_time) {
+ u->state->response_time = ngx_current_msec - u->state->response_time;
if (u->pipe && u->pipe->read_length) {
u->state->response_length = u->pipe->read_length;
@@ -5020,15 +5009,11 @@ ngx_http_upstream_response_time_variable
for ( ;; ) {
if (state[i].status) {
- if (data
- && state[i].header_sec != (time_t) NGX_ERROR)
- {
- ms = (ngx_msec_int_t)
- (state[i].header_sec * 1000 + state[i].header_msec);
+ if (data && state[i].header_time != (ngx_msec_t) -1) {
+ ms = state[i].header_time;
} else {
- ms = (ngx_msec_int_t)
- (state[i].response_sec * 1000 + state[i].response_msec);
+ ms = state[i].response_time;
}
ms = ngx_max(ms, 0);
diff -r 0b8f6f75245d -r 59fc60585f1e src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h Fri May 15 17:15:33 2015 +0300
+++ b/src/http/ngx_http_upstream.h Sat May 16 01:31:04 2015 +0300
@@ -58,10 +58,8 @@ typedef struct {
ngx_uint_t bl_state;
ngx_uint_t status;
- time_t response_sec;
- ngx_uint_t response_msec;
- time_t header_sec;
- ngx_uint_t header_msec;
+ ngx_msec_t response_time;
+ ngx_msec_t header_time;
off_t response_length;
ngx_str_t *peer;
More information about the nginx-devel
mailing list