Search code examples
performancenginxquery-performance

When does nginx $upstream_response_time start/stop specifically


Does anyone know when, specifically, the clock for $upstream_response_time begins and ends?

The documentation seems a bit vague:

keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.

There is also an $upstream_header_time value, which adds more confusion.

  1. I assume $upstream_connect_time stops once the connection is established, but before it is accepted upstream?

  2. After this what does $upstream_response_time include?

    • Time spent waiting for upstream to accept?
    • Time spent sending the request?
    • Time spent sending the response header?

Solution

  • A more specific definition is in their blog.

    $request_time – Full request time, starting when NGINX reads the first byte from the client and ending when NGINX sends the last byte of the response body

    $upstream_connect_time – Time spent establishing a connection with an upstream server

    $upstream_header_time – Time between establishing a connection to an upstream server and receiving the first byte of the response header

    $upstream_response_time – Time between establishing a connection to an upstream server and receiving the last byte of the response body

    So

    • $upstream_header_time is included in $upstream_response_time.
    • Time spent connecting to upstream is not included in both of them.
    • Time spent sending response to client is not included in both of them.