Skip to content

Commit

Permalink
core: implement suppression curve
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jul 13, 2023
1 parent 09252c4 commit 69ecfd3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
30 changes: 28 additions & 2 deletions ndn-svs/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ SVSyncCore::SVSyncCore(ndn::Face& face,
, m_securityOptions(securityOptions)
, m_id(nid)
, m_onUpdate(onUpdate)
, m_maxSuppressionTime(100)
, m_periodicSyncTime(30000)
, m_periodicSyncJitter(0.1)
, m_rng(ndn::random::getRandomNumberEngine())
, m_retxDist(30000 * 0.9, 30000 * 1.1)
, m_intrReplyDist(0, 75)
, m_retxDist(m_periodicSyncTime * (1.0 - m_periodicSyncJitter), m_periodicSyncTime * (1.0 + m_periodicSyncJitter))
, m_intrReplyDist(0, m_maxSuppressionTime)
, m_keyChainMem("pib-memory:", "tpm-memory:")
, m_scheduler(m_face.getIoService())
{
Expand All @@ -56,6 +59,24 @@ SVSyncCore::SVSyncCore(ndn::Face& face,
});
}

inline int
suppressionCurve(int constFactor, int value)
{
/**
* This curve increases the probability that only one or a few
* nodes pick lower values for timers compared to other nodes.
* This leads to better suppression results.
* Increasing the curve factor makes the curve steeper =>
* better for more nodes, but worse for fewer nodes.
*/

double c = constFactor;
double v = value;
double f = 10.0; // curve factor

return (int) (c * (1.0 - std::exp((v - c) / (c / f))));
}

void
SVSyncCore::sendInitialInterest()
{
Expand Down Expand Up @@ -161,6 +182,11 @@ SVSyncCore::onSyncInterestValidated(const Interest &interest)
// Check how much time is left on the timer,
// reset to ~m_intrReplyDist if more than that.
int delay = m_intrReplyDist(m_rng);

// Curve the delay for better suppression in large groups
// TODO: efficient curve depends on number of active nodes
delay = suppressionCurve(m_maxSuppressionTime, delay);

if (getCurrentTime() + delay * 1000 < m_nextSyncInterest)
{
retxSyncInterest(false, delay);
Expand Down
10 changes: 10 additions & 0 deletions ndn-svs/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ class SVSyncCore : noncopyable
GetExtraBlockCallback m_getExtraBlock;
RecvExtraBlockCallback m_recvExtraBlock;

// Max suppression time; this value is roughly
// correlated to the network diameter
int m_maxSuppressionTime;

This comment has been minimized.

Copy link
@Pesa

Pesa Jul 13, 2023

Member

If this is a time value, shouldn't it be a time::milliseconds or nanoseconds or whatever, instead of int?

Same below.

// Periodic timer value; can be set to lower
// for highly lossy networks.
int m_periodicSyncTime;
// Fraction of jitter in the periodic timer value.
// Correlated to network diameter.
double m_periodicSyncJitter;

// Random Engine
ndn::random::RandomNumberEngine& m_rng;
// Milliseconds between sending two sync interests
Expand Down

0 comments on commit 69ecfd3

Please sign in to comment.