Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weighed random load balancing #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
46 changes: 40 additions & 6 deletions src/XrdCms/XrdCmsCluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <cmath>
#include <random>

#include "XProtocol/YProtocol.hh"

Expand Down Expand Up @@ -1786,10 +1788,15 @@ XrdCmsNode *XrdCmsCluster::SelbyLoad(SMask_t mask, XrdCmsSelector &selR)
XrdCmsNode *np, *sp = 0;
bool Multi = false, reqSS = (selR.needSpace & XrdCmsNode::allowsSS) != 0;

// Scan for a node (preset possible, suspended, overloaded, full, and dead)
//
selR.Reset(); SelTcnt++;
for (int i = 0; i <= STHi; i++)
// Scan for a node (preset possible, suspended, overloaded, full, and dead)
//
selR.Reset(); SelTcnt++;
int selCap = 1;
int randomSel=1;
//default 0 to skip the node in random selection if the below checks fail
int *weighed = new int[STHi] {0};

for (int i = 0; i <= STHi; i++)
if ((np = NodeTab[i]) && (np->NodeMask & mask))
{if (!(selR.needNet & np->hasNet)) {selR.xNoNet= true; continue;}
selR.nPick++;
Expand All @@ -1800,7 +1807,17 @@ XrdCmsNode *XrdCmsCluster::SelbyLoad(SMask_t mask, XrdCmsSelector &selR)
|| (reqSS && np->isNoStage)))
{selR.xFull = true; continue;}
if (!sp) sp = np;
else{if (selR.needSpace)
else{
if (Config.P_randlb==1){
//add 1 to the inverse load, this is to allow some selection in case reported loads hit 100
weighed[i] = selCap + static_cast<int>(101 - np->myLoad +
std::pow(101 - np->myLoad,
std::log(100)-std::log(std::min(std::max(Config.P_fuzz,1),100)))/2);
selCap += static_cast<int>(101 - np->myLoad +
std::pow(101 - np->myLoad,
std::log(100)-std::log(std::min(std::max(Config.P_fuzz,1),100)))/2);
}
else{if (selR.needSpace)
{if (abs(sp->myMass - np->myMass) <= Config.P_fuzz)
{if (sp->RefW > (np->RefW+Config.DiskLinger)) sp=np;}
else if (sp->myMass > np->myMass) sp=np;
Expand All @@ -1816,12 +1833,29 @@ XrdCmsNode *XrdCmsCluster::SelbyLoad(SMask_t mask, XrdCmsSelector &selR)
}
Multi = true;
}
}
}

if (Config.P_randlb==1){
// pick a random weighed node
//
std::random_device rand_dev;
std::mt19937 generator(rand_dev());
std::uniform_int_distribution<int> distr(randomSel,selCap);
randomSel = distr(generator);
for(int i=0;i<=STHi;i++){
if(randomSel<=weighed[i]){
sp=NodeTab[i];
break;
}
}
}
delete [] weighed;
// Check for overloaded node and return result
//
if (!sp) return calcDelay(selR);
if (Config.P_randlb!=1){
RefCount(sp, Multi, selR.needSpace);
}
return sp;
}

Expand Down
4 changes: 3 additions & 1 deletion src/XrdCms/XrdCmsConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ void XrdCmsConfig::ConfigDefaults(void)
P_load = 0;
P_mem = 0;
P_pag = 0;
P_randlb = 0; // SelbyLoad algoruthm choice
AskPerf = 10; // Every 10 pings
AskPing = 60; // Every 1 minute
PingTick = 0;
Expand Down Expand Up @@ -2651,7 +2652,8 @@ int XrdCmsConfig::xsched(XrdSysError *eDest, XrdOucStream &CFile)
{"refreset", -1, &RefReset},
{"affinity", -2, 0},
{"affpath", -3, 0},
{"tryhname", 1, &V_hntry}
{"tryhname", 1, &V_hntry},
{"randlb", 1, &P_randlb}
};
int numopts = sizeof(scopts)/sizeof(struct schedopts);

Expand Down
1 change: 1 addition & 0 deletions src/XrdCms/XrdCmsConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ int P_io; // % I/O Capacity in load factor
int P_load; // % MSC Capacity in load factor
int P_mem; // % MEM Capacity in load factor
int P_pag; // % PAG Capacity in load factor
int P_randlb; // enable weighed random load balancing

char DoMWChk; // When true (default) perform multiple write check
char DoHnTry; // When true (default) use hostnames for try redirs
Expand Down
Loading