diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c index f7c4bd2f5..7ca4d22ec 100644 --- a/src/http/modules/ngx_http_log_module.c +++ b/src/http/modules/ngx_http_log_module.c @@ -838,13 +838,9 @@ static u_char * ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) { - ngx_time_t *tp; - ngx_msec_int_t ms; + ngx_msec_int_t ms; - tp = ngx_timeofday(); - - ms = (ngx_msec_int_t) - ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); + ms = (ngx_msec_int_t) (ngx_current_msec - r->start_time); ms = ngx_max(ms, 0); return ngx_sprintf(buf, "%T.%03M", (time_t) ms / 1000, ms % 1000); diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 4e1c67282..07b967ecd 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -2391,7 +2391,6 @@ ngx_http_subrequest(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr, ngx_http_post_subrequest_t *ps, ngx_uint_t flags) { - ngx_time_t *tp; ngx_connection_t *c; ngx_http_request_t *sr; ngx_http_core_srv_conf_t *cscf; @@ -2545,9 +2544,7 @@ ngx_http_subrequest(ngx_http_request_t *r, sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1; sr->subrequests = r->subrequests - 1; - tp = ngx_timeofday(); - sr->start_sec = tp->sec; - sr->start_msec = tp->msec; + sr->start_time = ngx_current_msec; r->main->count++; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index a5cd44dcc..d4b10a043 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -570,7 +570,6 @@ static ngx_http_request_t * ngx_http_alloc_request(ngx_connection_t *c) { ngx_pool_t *pool; - ngx_time_t *tp; ngx_http_request_t *r; ngx_http_connection_t *hc; ngx_http_core_srv_conf_t *cscf; @@ -645,9 +644,7 @@ ngx_http_alloc_request(ngx_connection_t *c) r->main = r; r->count = 1; - tp = ngx_timeofday(); - r->start_sec = tp->sec; - r->start_msec = tp->msec; + r->start_time = ngx_current_msec; r->method = NGX_HTTP_UNKNOWN; r->http_version = NGX_HTTP_VERSION_10; diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 6d18cc3c6..2cb67d851 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -412,8 +412,7 @@ struct ngx_http_request_s { ngx_http_request_body_t *request_body; time_t lingering_time; - time_t start_sec; - ngx_msec_t start_msec; + ngx_msec_t start_time; ngx_uint_t method; ngx_uint_t http_version; diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c index 37cd0d287..4f04d0482 100644 --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -2270,7 +2270,6 @@ ngx_http_variable_request_time(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) { u_char *p; - ngx_time_t *tp; ngx_msec_int_t ms; p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4); @@ -2278,10 +2277,7 @@ ngx_http_variable_request_time(ngx_http_request_t *r, return NGX_ERROR; } - tp = ngx_timeofday(); - - ms = (ngx_msec_int_t) - ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); + ms = (ngx_msec_int_t) (ngx_current_msec - r->start_time); ms = ngx_max(ms, 0); v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p; diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c index 9188ee948..d67dfba20 100644 --- a/src/http/ngx_http_write_filter_module.c +++ b/src/http/ngx_http_write_filter_module.c @@ -268,7 +268,8 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) r->limit_rate_after_set = 1; } - limit = (off_t) r->limit_rate * (ngx_time() - r->start_sec + 1) + limit = (off_t) r->limit_rate + * (ngx_current_msec / 1000 - r->start_time / 1000 + 1) - (c->sent - r->limit_rate_after); if (limit <= 0) { diff --git a/src/stream/ngx_stream.h b/src/stream/ngx_stream.h index 9bc689e99..1fd8f3899 100644 --- a/src/stream/ngx_stream.h +++ b/src/stream/ngx_stream.h @@ -264,8 +264,7 @@ struct ngx_stream_session_s { ngx_connection_t *connection; off_t received; - time_t start_sec; - ngx_msec_t start_msec; + ngx_msec_t start_time; ngx_log_handler_pt log_handler; diff --git a/src/stream/ngx_stream_handler.c b/src/stream/ngx_stream_handler.c index a7ffc6e61..d3f9fca6d 100644 --- a/src/stream/ngx_stream_handler.c +++ b/src/stream/ngx_stream_handler.c @@ -23,7 +23,6 @@ ngx_stream_init_connection(ngx_connection_t *c) u_char text[NGX_SOCKADDR_STRLEN]; size_t len; ngx_uint_t i; - ngx_time_t *tp; ngx_event_t *rev; struct sockaddr *sa; ngx_stream_port_t *port; @@ -173,9 +172,7 @@ ngx_stream_init_connection(ngx_connection_t *c) return; } - tp = ngx_timeofday(); - s->start_sec = tp->sec; - s->start_msec = tp->msec; + s->start_time = ngx_current_msec; rev = c->read; rev->handler = ngx_stream_session_handler; diff --git a/src/stream/ngx_stream_variables.c b/src/stream/ngx_stream_variables.c index 4658104e1..7984c3d05 100644 --- a/src/stream/ngx_stream_variables.c +++ b/src/stream/ngx_stream_variables.c @@ -776,7 +776,6 @@ ngx_stream_variable_session_time(ngx_stream_session_t *s, ngx_stream_variable_value_t *v, uintptr_t data) { u_char *p; - ngx_time_t *tp; ngx_msec_int_t ms; p = ngx_pnalloc(s->connection->pool, NGX_TIME_T_LEN + 4); @@ -784,10 +783,7 @@ ngx_stream_variable_session_time(ngx_stream_session_t *s, return NGX_ERROR; } - tp = ngx_timeofday(); - - ms = (ngx_msec_int_t) - ((tp->sec - s->start_sec) * 1000 + (tp->msec - s->start_msec)); + ms = (ngx_msec_int_t) (ngx_current_msec - s->start_time); ms = ngx_max(ms, 0); v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p;