$tcpinfo_rtt

The $tcpinfo_rtt variable returns the round-trip time (RTT) of the TCP connection in microseconds. — NGINX Core (HTTP)

$tcpinfo_rtt NGINX Core (HTTP)

Description

The $tcpinfo_rtt variable is part of NGINX's TCP connection module and is utilized to provide metrics for the TCP connection performance. It returns the round-trip time (RTT) measurements for a TCP connection, reflecting the time it takes for a data packet to go from the sender to the receiver and back again. This variable is especially useful for diagnosing network latency and assessing the responsiveness of a server to incoming requests. The value of $tcpinfo_rtt is available only when the connection is established and may not be immediately set for incoming connections. Typically, it returns an integer value that represents the time in microseconds. For a new connection, if RTT information isn't yet available, it might return zero until the information can be gathered from the TCP stack. Practically, typical values can range widely depending on the network, and developers can use this indicator to fine-tune their applications to better handle latency-related adjustments. This variable can be leveraged in logging directives, where server administrators might want to track connection performance over time. By including this metric in access logs, administrators can analyze trends and identify potential bottlenecks in service delivery.

Config Example

log_format custom_log '$remote_addr - $remote_user [$time_local] "$request" $status $tcpinfo_rtt';
access_log /var/log/nginx/access.log custom_log;

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

The $tcpinfo_rtt variable may not be set for the very first requests due to connection establishment delays.

If the connection has not recently sent or received data, the RTT value might be inaccurate or return zero. Adjust logging for intervals that reflect actual traffic patterns.