Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions service/connection_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ struct ConnectionHandler {
return *transport_;
}

virtual double getEstimatedRTT()
{ return transport().getEstimatedRTT(); }

const TransportBase & transport() const
{
if (!transport_)
Expand Down
28 changes: 28 additions & 0 deletions service/transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <sys/eventfd.h>
#include <linux/tcp.h>
#include <poll.h>
#include <chrono>


using namespace std;
Expand Down Expand Up @@ -1026,5 +1028,31 @@ 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) {

std::chrono::milliseconds rtt = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::microseconds(tcpinfo.tcpi_rtt));
std::chrono::milliseconds rtt_var = std::chrono::duration_cast<std::chrono::milliseconds>(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);
}
}


} // namespace Datacratic

3 changes: 3 additions & 0 deletions service/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct TransportBase : public std::enable_shared_from_this<TransportBase> {
virtual int handleAsync(const boost::function<void ()> & 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;

Expand Down Expand Up @@ -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_; }
Expand Down