Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 7397:860d3907da1c
Upstream: revised upstream response time variables.
Variables now do not depend on presence of the HTTP status code in response.
If the corresponding event occurred, variables contain time between request
creation and the event, and "-" otherwise.
Previously, intermediate value of the $upstream_response_time variable held
unix timestamp.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Wed, 21 Nov 2018 13:40:40 +0300 |
parents | 8b68d50090e4 |
children | e573d74299a0 |
comparison
equal
deleted
inserted
replaced
7396:e8bdd322d7a6 | 7397:860d3907da1c |
---|---|
1503 ngx_int_t rc; | 1503 ngx_int_t rc; |
1504 ngx_connection_t *c; | 1504 ngx_connection_t *c; |
1505 | 1505 |
1506 r->connection->log->action = "connecting to upstream"; | 1506 r->connection->log->action = "connecting to upstream"; |
1507 | 1507 |
1508 if (u->state && u->state->response_time) { | 1508 if (u->state && u->state->response_time == (ngx_msec_t) -1) { |
1509 u->state->response_time = ngx_current_msec - u->state->response_time; | 1509 u->state->response_time = ngx_current_msec - u->start_time; |
1510 } | 1510 } |
1511 | 1511 |
1512 u->state = ngx_array_push(r->upstream_states); | 1512 u->state = ngx_array_push(r->upstream_states); |
1513 if (u->state == NULL) { | 1513 if (u->state == NULL) { |
1514 ngx_http_upstream_finalize_request(r, u, | 1514 ngx_http_upstream_finalize_request(r, u, |
1516 return; | 1516 return; |
1517 } | 1517 } |
1518 | 1518 |
1519 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); | 1519 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); |
1520 | 1520 |
1521 u->state->response_time = ngx_current_msec; | 1521 u->start_time = ngx_current_msec; |
1522 | |
1523 u->state->response_time = (ngx_msec_t) -1; | |
1522 u->state->connect_time = (ngx_msec_t) -1; | 1524 u->state->connect_time = (ngx_msec_t) -1; |
1523 u->state->header_time = (ngx_msec_t) -1; | 1525 u->state->header_time = (ngx_msec_t) -1; |
1524 | 1526 |
1525 rc = ngx_event_connect_peer(&u->peer); | 1527 rc = ngx_event_connect_peer(&u->peer); |
1526 | 1528 |
2000 | 2002 |
2001 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | 2003 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2002 "http upstream send request"); | 2004 "http upstream send request"); |
2003 | 2005 |
2004 if (u->state->connect_time == (ngx_msec_t) -1) { | 2006 if (u->state->connect_time == (ngx_msec_t) -1) { |
2005 u->state->connect_time = ngx_current_msec - u->state->response_time; | 2007 u->state->connect_time = ngx_current_msec - u->start_time; |
2006 } | 2008 } |
2007 | 2009 |
2008 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { | 2010 if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) { |
2009 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); | 2011 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); |
2010 return; | 2012 return; |
2411 return; | 2413 return; |
2412 } | 2414 } |
2413 | 2415 |
2414 /* rc == NGX_OK */ | 2416 /* rc == NGX_OK */ |
2415 | 2417 |
2416 u->state->header_time = ngx_current_msec - u->state->response_time; | 2418 u->state->header_time = ngx_current_msec - u->start_time; |
2417 | 2419 |
2418 if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) { | 2420 if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) { |
2419 | 2421 |
2420 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { | 2422 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { |
2421 return; | 2423 return; |
4307 if (u->resolved && u->resolved->ctx) { | 4309 if (u->resolved && u->resolved->ctx) { |
4308 ngx_resolve_name_done(u->resolved->ctx); | 4310 ngx_resolve_name_done(u->resolved->ctx); |
4309 u->resolved->ctx = NULL; | 4311 u->resolved->ctx = NULL; |
4310 } | 4312 } |
4311 | 4313 |
4312 if (u->state && u->state->response_time) { | 4314 if (u->state && u->state->response_time == (ngx_msec_t) -1) { |
4313 u->state->response_time = ngx_current_msec - u->state->response_time; | 4315 u->state->response_time = ngx_current_msec - u->start_time; |
4314 | 4316 |
4315 if (u->pipe && u->pipe->read_length) { | 4317 if (u->pipe && u->pipe->read_length) { |
4316 u->state->bytes_received += u->pipe->read_length | 4318 u->state->bytes_received += u->pipe->read_length |
4317 - u->pipe->preread_size; | 4319 - u->pipe->preread_size; |
4318 u->state->response_length = u->pipe->read_length; | 4320 u->state->response_length = u->pipe->read_length; |
5417 | 5419 |
5418 i = 0; | 5420 i = 0; |
5419 state = r->upstream_states->elts; | 5421 state = r->upstream_states->elts; |
5420 | 5422 |
5421 for ( ;; ) { | 5423 for ( ;; ) { |
5422 if (state[i].status) { | 5424 |
5423 | 5425 if (data == 1) { |
5424 if (data == 1 && state[i].header_time != (ngx_msec_t) -1) { | 5426 ms = state[i].header_time; |
5425 ms = state[i].header_time; | 5427 |
5426 | 5428 } else if (data == 2) { |
5427 } else if (data == 2 && state[i].connect_time != (ngx_msec_t) -1) { | 5429 ms = state[i].connect_time; |
5428 ms = state[i].connect_time; | 5430 |
5429 | 5431 } else { |
5430 } else { | 5432 ms = state[i].response_time; |
5431 ms = state[i].response_time; | 5433 } |
5432 } | 5434 |
5433 | 5435 if (ms != -1) { |
5434 ms = ngx_max(ms, 0); | 5436 ms = ngx_max(ms, 0); |
5435 p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000); | 5437 p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000); |
5436 | 5438 |
5437 } else { | 5439 } else { |
5438 *p++ = '-'; | 5440 *p++ = '-'; |