enrich network-quality HTTPHeader field with retransmission rate
authorWoo Xie <woo@fb.com>
Mon, 1 Jun 2015 22:30:34 +0000 (15:30 -0700)
committerNoam Lerner <noamler@fb.com>
Wed, 3 Jun 2015 16:53:26 +0000 (09:53 -0700)
Summary:
estimating tcp retransmission rate of the socket

Test Plan: unit tests

Reviewed By: afrind@fb.com

Subscribers: folly-diffs@, njormrod, bmatheny, trunkagent, chalfant, yfeldblum, jsedgwick

FB internal diff: D2097198

Tasks: 4888253

Signature: t1:2097198:1433196365:16db26dfd721514481497eddfc7820a453618d33

folly/wangle/acceptor/TransportInfo.cpp
folly/wangle/acceptor/TransportInfo.h

index 4f735b4f03c21cc02dc23fe94df6e8e05dc30959..16fd80944a4855329f6c4c71f6811a97cae2545e 100644 (file)
@@ -26,10 +26,27 @@ bool TransportInfo::initWithSocket(const AsyncSocket* sock) {
     return false;
   }
   rtt = microseconds(tcpinfo.tcpi_rtt);
+  /* The ratio of packet retransmission (rtx) is a good indicator of network
+   * bandwidth condition. Unfortunately, the number of segmentOut is not
+   * available in current tcpinfo.  To workaround this limitation, totalBytes
+   * and MSS are used to estimate it.
+   */
+  if (tcpinfo.tcpi_total_retrans == 0) {
+    rtx = 0;
+  } else if (tcpinfo.tcpi_total_retrans > 0 && tcpinfo.tcpi_snd_mss > 0 &&
+      totalBytes > 0) {
+    // numSegmentOut is the underestimation of the number of tcp packets sent
+    double numSegmentOut = double(totalBytes) / tcpinfo.tcpi_snd_mss;
+    // so rtx is the overestimation of actual packet retransmission rate
+    rtx = tcpinfo.tcpi_total_retrans / numSegmentOut;
+  } else {
+    rtx = -1;
+  }
   validTcpinfo = true;
 #else
   tcpinfoErrno = EINVAL;
   rtt = microseconds(-1);
+  rtx = -1;
 #endif
   return true;
 }
index 67203c7e687e63cfcae57fd4fb09d68001f604a7..84ebfa8d4922ec5534fdce143e30c0b597e5cd3c 100644 (file)
@@ -47,6 +47,11 @@ struct TransportInfo {
    */
   std::chrono::microseconds rtt{0};
 
+  /*
+   *  the estimated ratio of packet retransmisions in current socket
+   */
+  double rtx{-1};
+
 #if defined(__linux__) || defined(__FreeBSD__)
   /*
    * TCP information as fetched from getsockopt(2)