From d9e08fac978077172eff085989fe6c018c9fcaca Mon Sep 17 00:00:00 2001 From: Woo Xie Date: Mon, 1 Jun 2015 15:30:34 -0700 Subject: [PATCH] enrich network-quality HTTPHeader field with retransmission rate 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 | 17 +++++++++++++++++ folly/wangle/acceptor/TransportInfo.h | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/folly/wangle/acceptor/TransportInfo.cpp b/folly/wangle/acceptor/TransportInfo.cpp index 4f735b4f..16fd8094 100644 --- a/folly/wangle/acceptor/TransportInfo.cpp +++ b/folly/wangle/acceptor/TransportInfo.cpp @@ -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; } diff --git a/folly/wangle/acceptor/TransportInfo.h b/folly/wangle/acceptor/TransportInfo.h index 67203c7e..84ebfa8d 100644 --- a/folly/wangle/acceptor/TransportInfo.h +++ b/folly/wangle/acceptor/TransportInfo.h @@ -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) -- 2.34.1