Adjusting capacity impact calculation to yield a more even distribution of jobs

This commit is contained in:
Ian Roddis
2021-12-23 11:47:55 -04:00
parent 85d252f43c
commit dd473ab8f0
3 changed files with 11 additions and 14 deletions

View File

@@ -2,6 +2,8 @@
#include <rapidjson/document.h>
#include <random>
#include "TaskExecutor.hpp"
namespace rj = rapidjson;

View File

@@ -146,11 +146,11 @@ std::future<AttemptRecord> DaggyRunnerTaskExecutor::execute(
auto curCap = capacityFromJSON(doc["current"]);
auto totCap = capacityFromJSON(doc["total"]);
double cores = curCap.cores < 0 ? totCap.cores : curCap.cores;
double memoryMB = curCap.memoryMB < 0 ? totCap.memoryMB : curCap.memoryMB;
double cores = (curCap.cores - taskUsed.cores);
double memoryMB = (curCap.memoryMB - taskUsed.memoryMB);
double impact =
std::max(taskUsed.cores / cores, taskUsed.memoryMB / memoryMB);
std::min(cores / totCap.cores, memoryMB / totCap.memoryMB);
impacts.emplace_back(runner, impact);
}
catch (const std::exception &_) {
@@ -167,15 +167,12 @@ std::future<AttemptRecord> DaggyRunnerTaskExecutor::execute(
return fut;
}
auto cit = impacts.begin();
for (auto it = impacts.begin(); it != impacts.end(); ++it) {
std::cout << it->first << " impact is " << it->second << std::endl;
if (it->second < cit->second)
cit = it;
}
std::sort(impacts.begin(), impacts.end());
auto runner = impacts.back();
std::stringstream ss;
ss << cit->first << "/v1/task/" << runID << "/" << taskName;
ss << runner.first << "/v1/task/" << runID << "/" << taskName;
auto url = ss.str();
const auto response = HTTP_REQUEST(url, taskToJSON(task), "POST");
@@ -185,7 +182,7 @@ std::future<AttemptRecord> DaggyRunnerTaskExecutor::execute(
RunningTask rt{.prom{},
.runID = runID,
.taskName = taskName,
.runnerURL = cit->first,
.runnerURL = runner.first,
.retries = 3};
auto fut = rt.prom.get_future();