comparison src/http/ngx_http_upstream.c @ 6146:59fc60585f1e

Upstream: times to obtain header/response are stored as ngx_msec_t.
author Ruslan Ermilov <ru@nginx.com>
date Sat, 16 May 2015 01:31:04 +0300
parents 4dc8e7b62216
children 74b6ef56ea56
comparison
equal deleted inserted replaced
6145:0b8f6f75245d 6146:59fc60585f1e
1298 1298
1299 static void 1299 static void
1300 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) 1300 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
1301 { 1301 {
1302 ngx_int_t rc; 1302 ngx_int_t rc;
1303 ngx_time_t *tp;
1304 ngx_connection_t *c; 1303 ngx_connection_t *c;
1305 1304
1306 r->connection->log->action = "connecting to upstream"; 1305 r->connection->log->action = "connecting to upstream";
1307 1306
1308 if (u->state && u->state->response_sec) { 1307 if (u->state && u->state->response_time) {
1309 tp = ngx_timeofday(); 1308 u->state->response_time = ngx_current_msec - u->state->response_time;
1310 u->state->response_sec = tp->sec - u->state->response_sec;
1311 u->state->response_msec = tp->msec - u->state->response_msec;
1312 } 1309 }
1313 1310
1314 u->state = ngx_array_push(r->upstream_states); 1311 u->state = ngx_array_push(r->upstream_states);
1315 if (u->state == NULL) { 1312 if (u->state == NULL) {
1316 ngx_http_upstream_finalize_request(r, u, 1313 ngx_http_upstream_finalize_request(r, u,
1318 return; 1315 return;
1319 } 1316 }
1320 1317
1321 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); 1318 ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
1322 1319
1323 tp = ngx_timeofday(); 1320 u->state->response_time = ngx_current_msec;
1324 u->state->response_sec = tp->sec; 1321 u->state->header_time = (ngx_msec_t) -1;
1325 u->state->response_msec = tp->msec;
1326 u->state->header_sec = (time_t) NGX_ERROR;
1327 1322
1328 rc = ngx_event_connect_peer(&u->peer); 1323 rc = ngx_event_connect_peer(&u->peer);
1329 1324
1330 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1325 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1331 "http upstream connect: %i", rc); 1326 "http upstream connect: %i", rc);
2015 static void 2010 static void
2016 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u) 2011 ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
2017 { 2012 {
2018 ssize_t n; 2013 ssize_t n;
2019 ngx_int_t rc; 2014 ngx_int_t rc;
2020 ngx_time_t *tp;
2021 ngx_connection_t *c; 2015 ngx_connection_t *c;
2022 2016
2023 c = u->peer.connection; 2017 c = u->peer.connection;
2024 2018
2025 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, 2019 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
2136 return; 2130 return;
2137 } 2131 }
2138 2132
2139 /* rc == NGX_OK */ 2133 /* rc == NGX_OK */
2140 2134
2141 tp = ngx_timeofday(); 2135 u->state->header_time = ngx_current_msec - u->state->response_time;
2142 u->state->header_sec = tp->sec - u->state->response_sec;
2143 u->state->header_msec = tp->msec - u->state->response_msec;
2144 2136
2145 if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) { 2137 if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {
2146 2138
2147 if (ngx_http_upstream_test_next(r, u) == NGX_OK) { 2139 if (ngx_http_upstream_test_next(r, u) == NGX_OK) {
2148 return; 2140 return;
3921 3913
3922 static void 3914 static void
3923 ngx_http_upstream_finalize_request(ngx_http_request_t *r, 3915 ngx_http_upstream_finalize_request(ngx_http_request_t *r,
3924 ngx_http_upstream_t *u, ngx_int_t rc) 3916 ngx_http_upstream_t *u, ngx_int_t rc)
3925 { 3917 {
3926 ngx_uint_t flush; 3918 ngx_uint_t flush;
3927 ngx_time_t *tp;
3928 3919
3929 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 3920 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3930 "finalize http upstream request: %i", rc); 3921 "finalize http upstream request: %i", rc);
3931 3922
3932 if (u->cleanup == NULL) { 3923 if (u->cleanup == NULL) {
3941 if (u->resolved && u->resolved->ctx) { 3932 if (u->resolved && u->resolved->ctx) {
3942 ngx_resolve_name_done(u->resolved->ctx); 3933 ngx_resolve_name_done(u->resolved->ctx);
3943 u->resolved->ctx = NULL; 3934 u->resolved->ctx = NULL;
3944 } 3935 }
3945 3936
3946 if (u->state && u->state->response_sec) { 3937 if (u->state && u->state->response_time) {
3947 tp = ngx_timeofday(); 3938 u->state->response_time = ngx_current_msec - u->state->response_time;
3948 u->state->response_sec = tp->sec - u->state->response_sec;
3949 u->state->response_msec = tp->msec - u->state->response_msec;
3950 3939
3951 if (u->pipe && u->pipe->read_length) { 3940 if (u->pipe && u->pipe->read_length) {
3952 u->state->response_length = u->pipe->read_length; 3941 u->state->response_length = u->pipe->read_length;
3953 } 3942 }
3954 } 3943 }
5018 state = r->upstream_states->elts; 5007 state = r->upstream_states->elts;
5019 5008
5020 for ( ;; ) { 5009 for ( ;; ) {
5021 if (state[i].status) { 5010 if (state[i].status) {
5022 5011
5023 if (data 5012 if (data && state[i].header_time != (ngx_msec_t) -1) {
5024 && state[i].header_sec != (time_t) NGX_ERROR) 5013 ms = state[i].header_time;
5025 {
5026 ms = (ngx_msec_int_t)
5027 (state[i].header_sec * 1000 + state[i].header_msec);
5028 5014
5029 } else { 5015 } else {
5030 ms = (ngx_msec_int_t) 5016 ms = state[i].response_time;
5031 (state[i].response_sec * 1000 + state[i].response_msec);
5032 } 5017 }
5033 5018
5034 ms = ngx_max(ms, 0); 5019 ms = ngx_max(ms, 0);
5035 p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000); 5020 p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000);
5036 5021