fw: Use ndn-cxx's RttEstimator in AsfStrategy

Refs: #4887
Change-Id: Ice718be99f2b96f183bb35c5df84930be54a9f8e
This commit is contained in:
Ernest McCracken authored and Davide Pesavento committed 2019-08-13 13:15:50 -04:00
1 parent 6be9387a4f
commit 1402fa153d
4 files changed
+47 -66

No files matched your search

+11 -27
View File
@@ -32,8 +32,8 @@ namespace asf {
NFD_LOG_INIT(AsfMeasurements);
const RttStats::Rtt RttStats::RTT_TIMEOUT(-1.0);
const RttStats::Rtt RttStats::RTT_NO_MEASUREMENT(0.0);
const time::nanoseconds RttStats::RTT_TIMEOUT(-1);
const time::nanoseconds RttStats::RTT_NO_MEASUREMENT(0);
const double RttStats::ALPHA = 0.125;
RttStats::RttStats()
@@ -43,23 +43,11 @@ RttStats::RttStats()
}
void
RttStats::addRttMeasurement(RttEstimator::Duration& durationRtt)
RttStats::addRttMeasurement(time::nanoseconds durationRtt)
{
m_rtt = static_cast<RttStats::Rtt>(durationRtt.count());
m_rttEstimator.addMeasurement(durationRtt);
m_srtt = computeSrtt(m_srtt, m_rtt);
}
RttStats::Rtt
RttStats::computeSrtt(Rtt previousSrtt, Rtt currentRtt)
{
if (previousSrtt == RTT_NO_MEASUREMENT) {
return currentRtt;
}
return Rtt(ALPHA * currentRtt + (1 - ALPHA) * previousSrtt);
m_rtt = durationRtt;
m_rttEstimator.addMeasurement(durationRtt, 1);
m_srtt = m_rttEstimator.getSmoothedRtt();
}
////////////////////////////////////////////////////////////////////////////////
@@ -122,14 +110,9 @@ FaceInfo::recordRtt(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace)
return;
}
time::steady_clock::Duration steadyRtt = time::steady_clock::now() - outRecord->getLastRenewed();
auto durationRtt = time::duration_cast<RttEstimator::Duration>(steadyRtt);
m_rttStats.addRttMeasurement(durationRtt);
m_rttStats.addRttMeasurement(time::steady_clock::now() - outRecord->getLastRenewed());
NFD_LOG_TRACE("Recording RTT for FaceId: " << inFace.getId()
<< " RTT: " << m_rttStats.getRtt()
<< " SRTT: " << m_rttStats.getSrtt());
<< " RTT: " << m_rttStats.getRtt() << " SRTT: " << m_rttStats.getSrtt());
}
void
@@ -167,9 +150,10 @@ NamespaceInfo::getOrCreateFaceInfo(const fib::Entry&, FaceId faceId)
FaceInfo* info = nullptr;
if (it == m_fit.end()) {
const auto& pair = m_fit.emplace(faceId, FaceInfo());
const auto& pair = m_fit.emplace(std::piecewise_construct,
std::forward_as_tuple(faceId),
std::forward_as_tuple());
info = &pair.first->second;
extendFaceInfoLifetime(*info, faceId);
}
else {
+20 -23
View File
@@ -26,10 +26,11 @@
#ifndef NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
#define NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
#include "core/rtt-estimator.hpp"
#include "fw/strategy-info.hpp"
#include "table/measurements-accessor.hpp"
#include <ndn-cxx/util/rtt-estimator.hpp>
namespace nfd {
namespace fw {
namespace asf {
@@ -37,12 +38,10 @@ namespace asf {
class RttStats
{
public:
typedef time::duration<double, boost::micro> Rtt;
RttStats();
void
addRttMeasurement(RttEstimator::Duration& durationRtt);
addRttMeasurement(time::nanoseconds rtt);
void
recordTimeout()
@@ -50,36 +49,32 @@ public:
m_rtt = RTT_TIMEOUT;
}
Rtt
time::nanoseconds
getRtt() const
{
return m_rtt;
}
Rtt
time::nanoseconds
getSrtt() const
{
return m_srtt;
}
RttEstimator::Duration
time::nanoseconds
computeRto() const
{
return m_rttEstimator.computeRto();
return m_rttEstimator.getEstimatedRto();
}
private:
static Rtt
computeSrtt(Rtt previousSrtt, Rtt currentRtt);
public:
static const Rtt RTT_TIMEOUT;
static const Rtt RTT_NO_MEASUREMENT;
static const time::nanoseconds RTT_TIMEOUT;
static const time::nanoseconds RTT_NO_MEASUREMENT;
private:
Rtt m_srtt;
Rtt m_rtt;
RttEstimator m_rttEstimator;
time::nanoseconds m_srtt;
time::nanoseconds m_rtt;
ndn::util::RttEstimator m_rttEstimator;
static const double ALPHA;
};
@@ -142,19 +137,19 @@ public:
return getRtt() == RttStats::RTT_TIMEOUT;
}
RttEstimator::Duration
time::nanoseconds
computeRto() const
{
return m_rttStats.computeRto();
}
RttStats::Rtt
time::nanoseconds
getRtt() const
{
return m_rttStats.getRtt();
}
RttStats::Rtt
time::nanoseconds
getSrtt() const
{
return m_rttStats.getSrtt();
@@ -203,7 +198,7 @@ typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/** \brief stores stategy information about each face in this namespace
/** \brief stores strategy information about each face in this namespace
*/
class NamespaceInfo : public StrategyInfo
{
@@ -251,10 +246,12 @@ public:
return m_fit.end();
}
const FaceInfoTable::iterator
FaceInfoTable::iterator
insert(FaceId faceId)
{
return m_fit.emplace(faceId, FaceInfo()).first;
return m_fit.emplace(std::piecewise_construct,
std::forward_as_tuple(faceId),
std::forward_as_tuple()).first;
}
bool
+11 -11
View File
@@ -247,7 +247,7 @@ AsfStrategy::forwardInterest(const Interest& interest,
if (!faceInfo.isTimeoutScheduled()) {
// Estimate and schedule timeout
RttEstimator::Duration timeout = faceInfo.computeRto();
auto timeout = faceInfo.computeRto();
NFD_LOG_TRACE("Scheduling timeout for " << fibEntry.getPrefix() << " to: " << egress
<< " in " << time::duration_cast<time::milliseconds>(timeout) << " ms");
@@ -261,27 +261,27 @@ AsfStrategy::forwardInterest(const Interest& interest,
struct FaceStats
{
Face* face;
RttStats::Rtt rtt;
RttStats::Rtt srtt;
time::nanoseconds rtt;
time::nanoseconds srtt;
uint64_t cost;
};
double
time::nanoseconds
getValueForSorting(const FaceStats& stats)
{
// These values allow faces with no measurements to be ranked better than timeouts
// srtt < RTT_NO_MEASUREMENT < RTT_TIMEOUT
static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max();
static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
static const time::nanoseconds SORTING_RTT_TIMEOUT = time::nanoseconds::max();
static const time::nanoseconds SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
if (stats.rtt == RttStats::RTT_TIMEOUT) {
return SORTING_RTT_TIMEOUT.count();
return SORTING_RTT_TIMEOUT;
}
else if (stats.rtt == RttStats::RTT_NO_MEASUREMENT) {
return SORTING_RTT_NO_MEASUREMENT.count();
return SORTING_RTT_NO_MEASUREMENT;
}
else {
return stats.srtt.count();
return stats.srtt;
}
}
@@ -298,8 +298,8 @@ AsfStrategy::getBestFaceForForwarding(const fib::Entry& fibEntry, const Interest
FaceStatsSet rankedFaces(
[] (const FaceStats& lhs, const FaceStats& rhs) -> bool {
// Sort by RTT and then by cost
double lhsValue = getValueForSorting(lhs);
double rhsValue = getValueForSorting(rhs);
time::nanoseconds lhsValue = getValueForSorting(lhs);
time::nanoseconds rhsValue = getValueForSorting(rhs);
if (lhsValue < rhsValue) {
return true;
+5 -5
View File
@@ -50,7 +50,7 @@ BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoFixture)
BOOST_CHECK_EQUAL(stats.getSrtt(), RttStats::RTT_NO_MEASUREMENT);
// Receive Data back in 50ms
RttEstimator::Duration rtt(50_ms);
time::nanoseconds rtt(50_ms);
stats.addRttMeasurement(rtt);
BOOST_CHECK_EQUAL(stats.getRtt(), rtt);
@@ -63,7 +63,7 @@ BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoFixture)
BOOST_CHECK_EQUAL(stats.getSrtt(), rtt);
// Receive Data back with a higher RTT
RttEstimator::Duration higherRtt(100_ms);
time::nanoseconds higherRtt(100_ms);
stats.addRttMeasurement(higherRtt);
BOOST_CHECK_EQUAL(stats.getRtt(), higherRtt);
@@ -71,7 +71,7 @@ BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoFixture)
BOOST_CHECK_LT(stats.getSrtt(), higherRtt);
// Simulate timeout
RttStats::Rtt previousSrtt = stats.getSrtt();
auto previousSrtt = stats.getSrtt();
stats.recordTimeout();
@@ -104,8 +104,8 @@ BOOST_FIXTURE_TEST_CASE(Basic, GlobalIoTimeFixture)
pitEntry->insertOrUpdateOutRecord(*face, 0, *interest);
RttEstimator::Duration rtt(50);
this->advanceClocks(5_ms, rtt);
time::nanoseconds rtt(5_ms);
this->advanceClocks(5_ms);
info.recordRtt(pitEntry, *face);
info.cancelTimeoutEvent(interestName);