$request_time

$request_time contains the total time taken to process the request, in seconds with millisecond precision. — NGINX Core (HTTP)

$request_time NGINX Core (HTTP)

Description

The $request_time variable provides an accurate measurement of the time taken to handle a client request in NGINX. This variable is calculated when the request is completed, capturing the duration from the moment it is received to when the response is sent back to the client. Specifically, $request_time records this time in seconds and fractions of a second, allowing you to assess performance and troubleshoot latency issues in your application. The value of $request_time is set during the processing phase of the request, immediately before NGINX sends the response. It's important to note that the time recorded can be influenced by several factors including network latency, server processing time, and client behavior (such as connection speed). As a result, typical values for $request_time vary widely depending on the application and server load; they can range from a few milliseconds to several seconds, especially under high traffic conditions or resource-intensive operations.

Config Example

log_format custom '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" request_time: $request_time';

access_log /var/log/nginx/access.log custom;

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

Always remember that $request_time does not include the time spent waiting for a connection if persistent connections are utilized.

If your NGINX configuration has multiple requests per connection (like in keep-alive), $request_time will only reflect the time for the last response, not the total for the connection. Use $upstream_response_time if you need backend response times instead.