Opened 8 years ago

Last modified 8 years ago

#1036 new enhancement

Add tcpi_total_retrans to tcp_info variables

Reported by: craigt Owned by:
Priority: minor Milestone:
Component: other Version: 1.11.x
Keywords: Cc:
uname -a:
nginx -V: nginx version: nginx/1.11.0

Description

I would like to be able to assess the impact of changes to transport protocol parameters more easily. Per session retransmission counters are really valuable for this measurement, where the global counters are too coarse.

Please add at least 'tcpi_total_retrans' to the existing list of tcp_info variables. Ideally the complete list would be made available, or a way to use the full set exposed by the kernel without further code changes.

I can think of use cases for several of the other data points also. Super-set here:
https://github.com/torvalds/linux/blob/master/include/uapi/linux/tcp.h

Thanks...

Change History (1)

comment:1 by Alexey Ivanov, 8 years ago

You can try following unofficial patch:

exporting patch:
# HG changeset patch
# User Alexey Ivanov <SaveTheRbtz@GMail.com>
# Date 1482209934 28800
#      Mon Dec 19 20:58:54 2016 -0800
# Branch tcpi_total_retrans
# Node ID 4b328bcfac27f9306617f878084962d3b5712a56
# Parent  01adb18a5d23910c518062d7e6f30fdf7653e310
HTTP: the $tcpinfo_total_retrans variable.

This metric is one of the most important KPIs for measuring network
performance. For example it can be used to find regressions on peering/transit
links or issues in the backbone network. It can also be grouped by ASN or GeoIP
data to find issues that are affecting a specific ISP/Country.

diff --git a/auto/unix b/auto/unix
--- a/auto/unix
+++ b/auto/unix
@@ -476,6 +476,28 @@
 . auto/feature
 
 
+ngx_feature="tcpi_total_retrans"
+ngx_feature_name="NGX_HAVE_TCP_INFO_TOTAL_RETRANS"
+ngx_feature_run=no
+ngx_feature_incs="#include <netinet/tcp.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="struct tcp_info ti;
+                  ti.tcpi_total_retrans"
+. auto/feature
+
+
+ngx_feature="tcpi_snd_rexmitpack"
+ngx_feature_name="NGX_HAVE_TCP_INFO_SND_REXMITPACK"
+ngx_feature_run=no
+ngx_feature_incs="#include <netinet/tcp.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="struct tcp_info ti;
+                  ti.tcpi_snd_rexmitpack"
+. auto/feature
+
+
 ngx_feature="accept4()"
 ngx_feature_name="NGX_HAVE_ACCEPT4"
 ngx_feature_run=no
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -354,6 +354,11 @@
 
     { ngx_string("tcpinfo_rcv_space"), NULL, ngx_http_variable_tcpinfo,
       3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
+#if (NGX_HAVE_TCP_INFO_TOTAL_RETRANS) || (NGX_HAVE_TCP_INFO_SND_REXMITPACK)
+    { ngx_string("tcpinfo_total_retrans"), NULL, ngx_http_variable_tcpinfo,
+      4, NGX_HTTP_VAR_NOCACHEABLE, 0 },
+#endif
 #endif
 
     { ngx_null_string, NULL, NULL, 0, 0, 0 }
@@ -1036,6 +1041,12 @@
     socklen_t        len;
     uint32_t         value;
 
+    /*
+     * TODO: cache whole tcp_info for the request to prevent multiple
+     * getsockopt(2) calls when multiple $tcpinfo_* variables are requested
+     * for the same request
+     */
+    /* TODO: add $upstream_tcpinfo_* counterpart */
     len = sizeof(struct tcp_info);
     if (getsockopt(r->connection->fd, IPPROTO_TCP, TCP_INFO, &ti, &len) == -1) {
         v->not_found = 1;
@@ -1064,6 +1075,16 @@
         value = ti.tcpi_rcv_space;
         break;
 
+#if (NGX_HAVE_TCP_INFO_TOTAL_RETRANS) || (NGX_HAVE_TCP_INFO_SND_REXMITPACK)
+    case 4:
+#if (NGX_HAVE_TCP_INFO_TOTAL_RETRANS)
+        value = ti.tcpi_total_retrans;
+#elif (NGX_HAVE_TCP_INFO_SND_REXMITPACK)
+        value = ti.tcpi_snd_rexmitpack;
+#endif
+        break;
+#endif
+
     /* suppress warning */
     default:
         value = 0;

Version 1, edited 8 years ago by Alexey Ivanov (previous) (next) (diff)
Note: See TracTickets for help on using tickets.