Skip to content

Commit

Permalink
[core] Fixed idle link activation by higher weight
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Jan 13, 2021
1 parent 26adb8b commit dccaf76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
33 changes: 15 additions & 18 deletions srtcore/group.cpp
Expand Up @@ -3044,7 +3044,7 @@ bool CUDTGroup::sendBackup_CheckSendStatus(gli_t
int32_t& w_curseq,
vector<gli_t>& w_parallel,
int& w_final_stat,
set<uint16_t>& w_sendable_pri,
uint16_t& w_max_sendable_weight,
size_t& w_nsuccessful,
bool& w_is_unstable)
{
Expand Down Expand Up @@ -3113,7 +3113,7 @@ bool CUDTGroup::sendBackup_CheckSendStatus(gli_t
none_succeeded = false;
w_final_stat = stat;
++w_nsuccessful;
w_sendable_pri.insert(d->weight);
w_max_sendable_weight = max(w_max_sendable_weight, d->weight);
}
else if (erc == SRT_EASYNCSND)
{
Expand Down Expand Up @@ -3178,7 +3178,7 @@ void CUDTGroup::sendBackup_Buffering(const char* buf, const int len, int32_t& w_
bool CUDTGroup::sendBackup_IsActivationNeeded(const vector<gli_t>& idlers,
const vector<gli_t>& unstable,
const vector<gli_t>& sendable,
const set<uint16_t> sendable_pri,
const uint16_t max_sendable_weight,
string& activate_reason ATR_UNUSED) const
{
SRT_ASSERT(sendable.size() >= unstable.size());
Expand All @@ -3190,12 +3190,12 @@ bool CUDTGroup::sendBackup_IsActivationNeeded(const vector<gli_t>& idlers,
log << "grp/sendBackup: all " << sendable.size() << " links unstable - will activate an idle link");
IF_HEAVY_LOGGING(activate_reason = "no stable links");
}
else if (sendable_pri.empty() ||
(!idlers.empty() && FPriorityOrder::check(idlers[0]->weight, *sendable_pri.begin())))
else if (sendable.empty() ||
(!idlers.empty() && idlers[0]->weight > max_sendable_weight))
{
need_activate = true;
#if ENABLE_HEAVY_LOGGING
if (sendable_pri.empty())
if (sendable.empty())
{
activate_reason = "no successful links found";
LOGC(gslog.Debug, log << "grp/sendBackup: no active links were successful - will activate an idle link");
Expand All @@ -3209,19 +3209,18 @@ bool CUDTGroup::sendBackup_IsActivationNeeded(const vector<gli_t>& idlers,
}
else
{
// Only now we are granted that both sendable_pri and idlers are nonempty
LOGC(gslog.Debug,
log << "grp/sendBackup: found link pri " << idlers[0]->weight << " PREF OVER "
<< (*sendable_pri.begin()) << " (highest from sendable) - will activate an idle link");
activate_reason = "found higher pri link";
log << "grp/sendBackup: found link weight " << idlers[0]->weight << " PREF OVER "
<< max_sendable_weight << " (highest from sendable) - will activate an idle link");
activate_reason = "found higher weight link";
}
#endif
}
else
{
HLOGC(gslog.Debug,
log << "grp/sendBackup: sendable_pri (" << sendable_pri.size() << "): " << Printable(sendable_pri)
<< " first idle pri: " << (idlers.size() > 0 ? int(idlers[0]->weight) : -1)
log << "grp/sendBackup: sendable max weight " << max_sendable_weight << ",: "
<< " first idle wight: " << (idlers.size() > 0 ? int(idlers[0]->weight) : -1)
<< " - will NOT activate an idle link");
}

Expand Down Expand Up @@ -3927,10 +3926,8 @@ int CUDTGroup::sendBackup(const char* buf, int len, SRT_MSGCTRL& w_mc)
int32_t curseq = SRT_SEQNO_NONE;
size_t nsuccessful = 0;

// Collect priorities from sendable links, added only after sending is successful.
// This will be used to check if any of the idlers have higher priority
// and therefore need to be activated.
set<uint16_t> sendable_pri;
// Maximum weight of sendable links.
uint16_t max_sendable_weight = 0;

// We believe that we need to send the payload over every sendable link anyway.
for (vector<gli_t>::iterator snd = sendable.begin(); snd != sendable.end(); ++snd)
Expand Down Expand Up @@ -3966,7 +3963,7 @@ int CUDTGroup::sendBackup(const char* buf, int len, SRT_MSGCTRL& w_mc)
(curseq),
(parallel),
(final_stat),
(sendable_pri),
(max_sendable_weight),
(nsuccessful),
(is_unstable));

Expand Down Expand Up @@ -4057,7 +4054,7 @@ int CUDTGroup::sendBackup(const char* buf, int len, SRT_MSGCTRL& w_mc)
sendBackup_Buffering(buf, len, (curseq), (w_mc));

string activate_reason;
if (sendBackup_IsActivationNeeded(idlers, unstable, sendable, sendable_pri, activate_reason))
if (sendBackup_IsActivationNeeded(idlers, unstable, sendable, max_sendable_weight, activate_reason))
{
if (idlers.empty())
{
Expand Down
6 changes: 3 additions & 3 deletions srtcore/group.h
Expand Up @@ -249,7 +249,7 @@ class CUDTGroup
/// @param[out] w_curseq Group's current sequence number (either -1 or the value used already for other links)
/// @param[out] w_parallel Parallel link container (will be filled inside this function)
/// @param[out] w_final_stat Status to be reported by this function eventually
/// @param[out] w_sendable_pri Weight value from every link (will auto-sort)
/// @param[out] w_max_sendable_weight Maximum weight value of sendable links
/// @param[out] w_nsuccessful Updates the number of successful links
/// @param[out] w_is_unstable Set true if sending resulted in AGAIN error.
///
Expand All @@ -264,7 +264,7 @@ class CUDTGroup
int32_t& w_curseq,
std::vector<gli_t>& w_parallel,
int& w_final_stat,
std::set<uint16_t>& w_sendable_pri,
uint16_t& w_max_sendable_weight,
size_t& w_nsuccessful,
bool& w_is_unstable);
void sendBackup_Buffering(const char* buf, const int len, int32_t& curseq, SRT_MSGCTRL& w_mc);
Expand All @@ -285,7 +285,7 @@ class CUDTGroup
bool sendBackup_IsActivationNeeded(const std::vector<CUDTGroup::gli_t>& idlers,
const std::vector<gli_t>& unstable,
const std::vector<gli_t>& sendable,
const std::set<uint16_t> sendable_pri,
const uint16_t max_sendable_weight,
std::string& activate_reason) const;

size_t sendBackup_TryActivateIdleLink(const std::vector<gli_t>& idlers,
Expand Down

0 comments on commit dccaf76

Please sign in to comment.