Skip to content

Commit

Permalink
Add method to get unique hosts from scheduling decision (#346)
Browse files Browse the repository at this point in the history
decisions: add a couple of utility methods
  • Loading branch information
csegarragonz authored Aug 4, 2023
1 parent f3fab63 commit ccf99e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/faabric/batch-scheduler/SchedulingDecision.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class SchedulingDecision

SchedulingDecision(uint32_t appIdIn, int32_t groupIdIn);

bool operator==(const SchedulingDecision& rhs) const = default;

uint32_t appId = 0;

int32_t groupId = 0;
Expand Down Expand Up @@ -96,6 +98,8 @@ class SchedulingDecision
int32_t messageId,
int32_t appIdx,
int32_t groupIdx);

std::set<std::string> uniqueHosts();
};

}
5 changes: 5 additions & 0 deletions src/batch-scheduler/SchedulingDecision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ SchedulingDecision SchedulingDecision::fromPointToPointMappings(

return decision;
}

std::set<std::string> SchedulingDecision::uniqueHosts()
{
return std::set<std::string>(hosts.begin(), hosts.end());
}
}
13 changes: 12 additions & 1 deletion tests/test/batch-scheduler/test_scheduling_decisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ TEST_CASE_METHOD(ConfFixture, "Test building scheduling decisions", "[util]")
std::string hostC = "hostC";

std::string thisHost = conf.endpointHost;
std::set<std::string> expectedUniqueHosts;

bool expectSingleHost = false;
SECTION("Multi-host") {}
SECTION("Multi-host") { expectedUniqueHosts = { hostA, hostB, hostC }; }

SECTION("Only remote hosts")
{
hostB = "hostA";
hostC = "hostA";

expectSingleHost = false;
expectedUniqueHosts = { "hostA" };
}

SECTION("All this host")
Expand All @@ -39,6 +41,7 @@ TEST_CASE_METHOD(ConfFixture, "Test building scheduling decisions", "[util]")
hostC = thisHost;

expectSingleHost = true;
expectedUniqueHosts = { thisHost };
}

SECTION("All this host single host optimisations off")
Expand All @@ -50,6 +53,7 @@ TEST_CASE_METHOD(ConfFixture, "Test building scheduling decisions", "[util]")
hostC = thisHost;

expectSingleHost = false;
expectedUniqueHosts = { thisHost };
}

auto req = faabric::util::batchExecFactory("foo", "bar", 3);
Expand All @@ -75,8 +79,15 @@ TEST_CASE_METHOD(ConfFixture, "Test building scheduling decisions", "[util]")
REQUIRE(decision.nFunctions == 3);
REQUIRE(decision.messageIds == expectedMsgIds);
REQUIRE(decision.hosts == expectedHosts);
REQUIRE(decision.uniqueHosts() == expectedUniqueHosts);
REQUIRE(decision.appIdxs == expectedAppIdxs);
REQUIRE(decision.isSingleHost() == expectSingleHost);

// We can compare decisions with the == operator
auto newDecision = decision;
REQUIRE(newDecision == decision);
newDecision.groupId = 1338;
REQUIRE(newDecision != decision);
}

TEST_CASE("Test converting point-to-point mappings to scheduling decisions",
Expand Down

0 comments on commit ccf99e8

Please sign in to comment.