Opened 8 years ago

Last modified 7 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, 7 years ago

You can try following unofficial patch:

diff -r 01adb18a5d23 auto/unix
--- a/auto/unix	Mon Dec 19 14:02:39 2016 +0300
+++ b/auto/unix	Mon Dec 19 18:16:07 2016 -0800
@@ -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 -r 01adb18a5d23 src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c	Mon Dec 19 14:02:39 2016 +0300
+++ b/src/http/ngx_http_variables.c	Mon Dec 19 18:16:07 2016 -0800
@@ -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 0, edited 7 years ago by Alexey Ivanov (next)
Note: See TracTickets for help on using tickets.