$request_time has millisecond precision
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c index e4b861b..d3ebca4 100644 --- a/src/http/modules/ngx_http_log_module.c +++ b/src/http/modules/ngx_http_log_module.c
@@ -170,7 +170,8 @@ { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, ngx_http_log_time }, { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec }, - { ngx_string("request_time"), NGX_TIME_T_LEN, ngx_http_log_request_time }, + { ngx_string("request_time"), NGX_TIME_T_LEN + 4, + ngx_http_log_request_time }, { ngx_string("status"), 3, ngx_http_log_status }, { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN, @@ -394,11 +395,15 @@ ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) { - time_t elapsed; + ngx_time_t *tp; + ngx_msec_int_t ms; - elapsed = ngx_time() - r->start_time; + tp = ngx_timeofday(); - return ngx_sprintf(buf, "%T", elapsed); + ms = (tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec); + ms = (ms >= 0) ? ms : 0; + + return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000); }
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 7fa0ba3..76f5e98 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c
@@ -1353,8 +1353,6 @@ sr->headers_in = r->headers_in; - sr->start_time = ngx_time(); - ngx_http_clear_content_length(sr); ngx_http_clear_accept_ranges(sr); ngx_http_clear_last_modified(sr);
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 1a2e1bc..9b5d02f 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c
@@ -212,6 +212,7 @@ static void ngx_http_init_request(ngx_event_t *rev) { + ngx_time_t *tp; socklen_t len; ngx_uint_t i; struct sockaddr_in sin; @@ -421,7 +422,9 @@ r->main = r; - r->start_time = ngx_time(); + tp = ngx_timeofday(); + r->start_sec = tp->sec; + r->start_msec = tp->msec; r->method = NGX_HTTP_UNKNOWN;
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 414efd7..a380ac0 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h
@@ -342,7 +342,8 @@ ngx_http_request_body_t *request_body; time_t lingering_time; - time_t start_time; + time_t start_sec; + ngx_msec_t start_msec; ngx_uint_t method; ngx_uint_t http_version;
diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c index b25d07e..2015c43 100644 --- a/src/http/ngx_http_write_filter_module.c +++ b/src/http/ngx_http_write_filter_module.c
@@ -210,7 +210,7 @@ } if (r->limit_rate) { - to_send = r->limit_rate * (ngx_time() - r->start_time + 1) - c->sent; + to_send = r->limit_rate * (ngx_time() - r->start_sec + 1) - c->sent; if (to_send <= 0) { c->write->delayed = 1;