Fixed balancer for new lib merge
This commit is contained in:
parent
467b1cc877
commit
8ac88c4612
1 changed files with 30 additions and 31 deletions
|
@ -80,21 +80,21 @@ private:
|
||||||
std::map<std::string, struct streamDetails> streams;
|
std::map<std::string, struct streamDetails> streams;
|
||||||
std::set<std::string> conf_streams;
|
std::set<std::string> conf_streams;
|
||||||
std::map<std::string, outUrl> outputs;
|
std::map<std::string, outUrl> outputs;
|
||||||
unsigned int cpu;
|
uint32_t cpu;
|
||||||
unsigned long long ramMax;
|
uint64_t ramMax;
|
||||||
unsigned long long ramCurr;
|
uint64_t ramCurr;
|
||||||
unsigned int upSpeed;
|
uint32_t upSpeed;
|
||||||
unsigned int downSpeed;
|
uint32_t downSpeed;
|
||||||
unsigned int total;
|
uint32_t total;
|
||||||
unsigned long long upPrev;
|
uint64_t upPrev;
|
||||||
unsigned long long downPrev;
|
uint64_t downPrev;
|
||||||
unsigned long long prevTime;
|
uint64_t prevTime;
|
||||||
unsigned long long addBandwidth;
|
uint64_t addBandwidth;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string host;
|
std::string host;
|
||||||
char binHost[16];
|
char binHost[16];
|
||||||
unsigned long long availBandwidth;
|
uint64_t availBandwidth;
|
||||||
JSON::Value geoDetails;
|
JSON::Value geoDetails;
|
||||||
double servLati, servLongi;
|
double servLati, servLongi;
|
||||||
std::string servLoc;
|
std::string servLoc;
|
||||||
|
@ -140,24 +140,23 @@ public:
|
||||||
void fillState(JSON::Value &r){
|
void fillState(JSON::Value &r){
|
||||||
if (!hostMutex){hostMutex = new tthread::mutex();}
|
if (!hostMutex){hostMutex = new tthread::mutex();}
|
||||||
tthread::lock_guard<tthread::mutex> guard(*hostMutex);
|
tthread::lock_guard<tthread::mutex> guard(*hostMutex);
|
||||||
r["cpu"] = (long long)(cpu / 10);
|
r["cpu"] = cpu / 10;
|
||||||
if (ramMax){r["ram"] = (long long)((ramCurr * 100) / ramMax);}
|
if (ramMax){r["ram"] = (ramCurr * 100) / ramMax;}
|
||||||
r["up"] = (long long)upSpeed;
|
r["up"] = upSpeed;
|
||||||
r["up_add"] = (long long)addBandwidth;
|
r["up_add"] = addBandwidth;
|
||||||
r["down"] = (long long)downSpeed;
|
r["down"] = downSpeed;
|
||||||
r["streams"] = (long long)streams.size();
|
r["streams"] = streams.size();
|
||||||
r["viewers"] = (long long)total;
|
r["viewers"] = total;
|
||||||
r["bwlimit"] = (long long)availBandwidth;
|
r["bwlimit"] = availBandwidth;
|
||||||
if (servLati || servLongi){
|
if (servLati || servLongi){
|
||||||
r["geo"]["lat"] = servLati;
|
r["geo"]["lat"] = servLati;
|
||||||
r["geo"]["lon"] = servLongi;
|
r["geo"]["lon"] = servLongi;
|
||||||
r["geo"]["loc"] = servLoc;
|
r["geo"]["loc"] = servLoc;
|
||||||
}
|
}
|
||||||
if (ramMax && availBandwidth){
|
if (ramMax && availBandwidth){
|
||||||
r["score"]["cpu"] = (long long)(weight_cpu - (cpu * weight_cpu) / 1000);
|
r["score"]["cpu"] = (weight_cpu - (cpu * weight_cpu) / 1000);
|
||||||
r["score"]["ram"] = (long long)(weight_ram - ((ramCurr * weight_ram) / ramMax));
|
r["score"]["ram"] = (weight_ram - ((ramCurr * weight_ram) / ramMax));
|
||||||
r["score"]["bw"] =
|
r["score"]["bw"] = (weight_bw - (((upSpeed + addBandwidth) * weight_bw) / availBandwidth));
|
||||||
(long long)(weight_bw - (((upSpeed + addBandwidth) * weight_bw) / availBandwidth));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Fills out a by reference given JSON::Value with current streams.
|
/// Fills out a by reference given JSON::Value with current streams.
|
||||||
|
@ -482,7 +481,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (stream.size()){
|
if (stream.size()){
|
||||||
long long count = 0;
|
uint32_t count = 0;
|
||||||
for (HOSTLOOP){
|
for (HOSTLOOP){
|
||||||
HOSTCHECK;
|
HOSTCHECK;
|
||||||
count += HOST(i).details->getViewers(stream);
|
count += HOST(i).details->getViewers(stream);
|
||||||
|
@ -611,7 +610,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
|
|
||||||
void handleServer(void *hostEntryPointer){
|
void handleServer(void *hostEntryPointer){
|
||||||
hostEntry *entry = (hostEntry *)hostEntryPointer;
|
hostEntry *entry = (hostEntry *)hostEntryPointer;
|
||||||
JSON::Value bandwidth = 128 * 1024 * 1024ll; // assume 1G connection
|
JSON::Value bandwidth = 128 * 1024 * 1024; // assume 1G connection
|
||||||
HTTP::URL url(entry->name);
|
HTTP::URL url(entry->name);
|
||||||
if (!url.protocol.size()){url.protocol = "http";}
|
if (!url.protocol.size()){url.protocol = "http";}
|
||||||
if (!url.port.size()){url.port = "4242";}
|
if (!url.port.size()){url.port = "4242";}
|
||||||
|
@ -703,7 +702,7 @@ int main(int argc, char **argv){
|
||||||
opt["short"] = "p";
|
opt["short"] = "p";
|
||||||
opt["long"] = "port";
|
opt["long"] = "port";
|
||||||
opt["help"] = "TCP port to listen on";
|
opt["help"] = "TCP port to listen on";
|
||||||
opt["value"].append((long long)8042);
|
opt["value"].append(8042);
|
||||||
conf.addOption("port", opt);
|
conf.addOption("port", opt);
|
||||||
|
|
||||||
opt["arg"] = "string";
|
opt["arg"] = "string";
|
||||||
|
@ -738,35 +737,35 @@ int main(int argc, char **argv){
|
||||||
opt["short"] = "R";
|
opt["short"] = "R";
|
||||||
opt["long"] = "ram";
|
opt["long"] = "ram";
|
||||||
opt["help"] = "Weight for RAM scoring";
|
opt["help"] = "Weight for RAM scoring";
|
||||||
opt["value"].append((long long)weight_ram);
|
opt["value"].append(weight_ram);
|
||||||
conf.addOption("ram", opt);
|
conf.addOption("ram", opt);
|
||||||
|
|
||||||
opt["arg"] = "integer";
|
opt["arg"] = "integer";
|
||||||
opt["short"] = "C";
|
opt["short"] = "C";
|
||||||
opt["long"] = "cpu";
|
opt["long"] = "cpu";
|
||||||
opt["help"] = "Weight for CPU scoring";
|
opt["help"] = "Weight for CPU scoring";
|
||||||
opt["value"].append((long long)weight_cpu);
|
opt["value"].append(weight_cpu);
|
||||||
conf.addOption("cpu", opt);
|
conf.addOption("cpu", opt);
|
||||||
|
|
||||||
opt["arg"] = "integer";
|
opt["arg"] = "integer";
|
||||||
opt["short"] = "B";
|
opt["short"] = "B";
|
||||||
opt["long"] = "bw";
|
opt["long"] = "bw";
|
||||||
opt["help"] = "Weight for BW scoring";
|
opt["help"] = "Weight for BW scoring";
|
||||||
opt["value"].append((long long)weight_bw);
|
opt["value"].append(weight_bw);
|
||||||
conf.addOption("bw", opt);
|
conf.addOption("bw", opt);
|
||||||
|
|
||||||
opt["arg"] = "integer";
|
opt["arg"] = "integer";
|
||||||
opt["short"] = "G";
|
opt["short"] = "G";
|
||||||
opt["long"] = "geo";
|
opt["long"] = "geo";
|
||||||
opt["help"] = "Weight for geo scoring";
|
opt["help"] = "Weight for geo scoring";
|
||||||
opt["value"].append((long long)weight_geo);
|
opt["value"].append(weight_geo);
|
||||||
conf.addOption("geo", opt);
|
conf.addOption("geo", opt);
|
||||||
|
|
||||||
opt["arg"] = "integer";
|
opt["arg"] = "integer";
|
||||||
opt["short"] = "X";
|
opt["short"] = "X";
|
||||||
opt["long"] = "extra";
|
opt["long"] = "extra";
|
||||||
opt["help"] = "Weight for extra scoring when stream exists";
|
opt["help"] = "Weight for extra scoring when stream exists";
|
||||||
opt["value"].append((long long)weight_bonus);
|
opt["value"].append(weight_bonus);
|
||||||
conf.addOption("extra", opt);
|
conf.addOption("extra", opt);
|
||||||
|
|
||||||
opt.null();
|
opt.null();
|
||||||
|
|
Loading…
Add table
Reference in a new issue