From 986a8b3fb332e04f24f1a652b503bde5e37737dc Mon Sep 17 00:00:00 2001 From: Thomas Sanchez Date: Sat, 31 Aug 2013 16:57:08 +0200 Subject: [PATCH 1/2] Add method to get the RTT kernel estimation --- service/connection_handler.h | 3 +++ service/transport.cc | 17 +++++++++++++++++ service/transport.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/service/connection_handler.h b/service/connection_handler.h index 409af51e..01dff5fc 100644 --- a/service/connection_handler.h +++ b/service/connection_handler.h @@ -177,6 +177,9 @@ struct ConnectionHandler { return *transport_; } + virtual double getEstimatedRTT() + { return transport().getEstimatedRTT(); } + const TransportBase & transport() const { if (!transport_) diff --git a/service/transport.cc b/service/transport.cc index 0f26cfc3..0f32075f 100644 --- a/service/transport.cc +++ b/service/transport.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -1026,5 +1027,21 @@ closePeer() return peer().close(); } +double +SocketTransport::getEstimatedRTT() +{ + tcp_info tcpinfo; + int len = sizeof(tcpinfo); + + int success = peer().get_option(IPPROTO_TCP, TCP_INFO, &tcpinfo, &len); + if (success != -1) { + // usec -> msec + return tcpinfo.tcpi_rtt / double(1000); + } else { + return double(-1); + } +} + + } // namespace Datacratic diff --git a/service/transport.h b/service/transport.h index f56bc93b..8fcec054 100644 --- a/service/transport.h +++ b/service/transport.h @@ -58,6 +58,8 @@ struct TransportBase : public std::enable_shared_from_this { virtual int handleAsync(const boost::function & callback, const char * name, Date dateSet); + virtual double getEstimatedRTT() { return double(-1);} + virtual ssize_t send(const char * buf, size_t len, int flags) = 0; virtual ssize_t recv(char * buf, size_t buf_size, int flags) = 0; @@ -604,6 +606,7 @@ struct SocketTransport virtual ssize_t send(const char * buf, size_t len, int flags); virtual ssize_t recv(char * buf, size_t buf_size, int flags); virtual int closePeer(); + virtual double getEstimatedRTT(); ACE_SOCK_Stream & peer() { return peer_; } const ACE_SOCK_Stream & peer() const { return peer_; } From 068042224be5b3e81dbe418d91d52af5ed1f45b3 Mon Sep 17 00:00:00 2001 From: Thomas Sanchez Date: Sat, 31 Aug 2013 17:50:22 +0200 Subject: [PATCH 2/2] Add safety levels to RTT --- service/transport.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/service/transport.cc b/service/transport.cc index 0f32075f..1b9d5546 100644 --- a/service/transport.cc +++ b/service/transport.cc @@ -21,6 +21,7 @@ #include #include #include +#include using namespace std; @@ -1035,8 +1036,18 @@ SocketTransport::getEstimatedRTT() int success = peer().get_option(IPPROTO_TCP, TCP_INFO, &tcpinfo, &len); if (success != -1) { - // usec -> msec - return tcpinfo.tcpi_rtt / double(1000); + + std::chrono::milliseconds rtt = std::chrono::duration_cast(std::chrono::microseconds(tcpinfo.tcpi_rtt)); + std::chrono::milliseconds rtt_var = std::chrono::duration_cast(std::chrono::microseconds(tcpinfo.tcpi_rttvar)); + + /* + * As discussed on the ML: + * We could also add some 'safety' levels to account for user-level + * overhead and weird values that could be returned from this i.e. + * rtt = tcp_rtt+3 * var_rtt + 2ms clamp to range (2ms, 50ms) + */ + return rtt.count() + 3 * rtt_var.count() + 2; + } else { return double(-1); }