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

planner: implement compaction planner policy #430

Merged
merged 1 commit into from
Apr 25, 2024
Merged
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
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FAABRIC_VERSION=0.17.0
FAABRIC_CLI_IMAGE=faasm.azurecr.io/faabric:0.17.0
FAABRIC_VERSION=0.18.0
FAABRIC_CLI_IMAGE=faasm.azurecr.io/faabric:0.18.0
COMPOSE_PROJECT_NAME=faabric-dev
CONAN_CACHE_MOUNT_SOURCE=./conan-cache/
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
container:
image: faasm.azurecr.io/faabric:0.17.0
image: faasm.azurecr.io/faabric:0.18.0
env:
DEPLOYMENT_TYPE: gha-ci
steps:
Expand All @@ -34,7 +34,7 @@ jobs:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
container:
image: faasm.azurecr.io/faabric:0.17.0
image: faasm.azurecr.io/faabric:0.18.0
steps:
- name: "Check out code"
uses: actions/checkout@v4
Expand All @@ -45,7 +45,7 @@ jobs:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
container:
image: faasm.azurecr.io/faabric:0.17.0
image: faasm.azurecr.io/faabric:0.18.0
steps:
- name: "Check out code"
uses: actions/checkout@v4
Expand All @@ -65,7 +65,7 @@ jobs:
REDIS_QUEUE_HOST: redis
REDIS_STATE_HOST: redis
container:
image: faasm.azurecr.io/faabric:0.17.0
image: faasm.azurecr.io/faabric:0.18.0
options: --privileged
services:
redis:
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
REDIS_QUEUE_HOST: redis
REDIS_STATE_HOST: redis
container:
image: faasm.azurecr.io/faabric:0.17.0
image: faasm.azurecr.io/faabric:0.18.0
options: --privileged
services:
redis:
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
REDIS_QUEUE_HOST: redis
REDIS_STATE_HOST: redis
container:
image: faasm.azurecr.io/faabric:0.17.0
image: faasm.azurecr.io/faabric:0.18.0
services:
redis:
image: redis
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.0
0.18.0
6 changes: 5 additions & 1 deletion include/faabric/batch-scheduler/BatchScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ class BatchScheduler

static int numSlots(const Host& host) { return host->slots; }

static int numUsedSlots(const Host& host) { return host->usedSlots; }

static int numSlotsAvailable(const Host& host)
{
return std::max<int>(0, numSlots(host) - host->usedSlots);
return std::max<int>(0, numSlots(host) - numUsedSlots(host));
}

static void claimSlots(Host& host, int numSlotsToClaim)
Expand Down Expand Up @@ -120,4 +122,6 @@ class BatchScheduler
std::shared_ptr<BatchScheduler> getBatchScheduler();

void resetBatchScheduler();

void resetBatchScheduler(const std::string& newMode);
}
35 changes: 35 additions & 0 deletions include/faabric/batch-scheduler/CompactScheduler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <faabric/batch-scheduler/BatchScheduler.h>
#include <faabric/batch-scheduler/SchedulingDecision.h>
#include <faabric/util/batch.h>

namespace faabric::batch_scheduler {

// This batch scheduler behaves in the same way than BinPack for NEW and
// SCALE_CHANGE requests, but for DIST_CHANGE requests it tries to compact
// to the fewest number of VMs.
class CompactScheduler final : public BatchScheduler
{
public:
std::shared_ptr<SchedulingDecision> makeSchedulingDecision(
HostMap& hostMap,
const InFlightReqs& inFlightReqs,
std::shared_ptr<faabric::BatchExecuteRequest> req) override;

private:
bool isFirstDecisionBetter(
std::shared_ptr<SchedulingDecision> decisionA,
std::shared_ptr<SchedulingDecision> decisionB) override;

bool isFirstDecisionBetter(HostMap& hostMap,
std::shared_ptr<SchedulingDecision> decisionA,
std::shared_ptr<SchedulingDecision> decisionB);

std::vector<Host> getSortedHosts(
HostMap& hostMap,
const InFlightReqs& inFlightReqs,
std::shared_ptr<faabric::BatchExecuteRequest> req,
const DecisionType& decisionType) override;
};
}
2 changes: 2 additions & 0 deletions include/faabric/planner/Planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Planner

void printConfig() const;

void setPolicy(const std::string& newPolicy);

// ----------
// Util public API
// ----------
Expand Down
12 changes: 12 additions & 0 deletions src/batch-scheduler/BatchScheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <faabric/batch-scheduler/BatchScheduler.h>
#include <faabric/batch-scheduler/BinPackScheduler.h>
#include <faabric/batch-scheduler/CompactScheduler.h>
#include <faabric/util/config.h>
#include <faabric/util/logging.h>

Expand All @@ -20,6 +21,8 @@ std::shared_ptr<BatchScheduler> getBatchScheduler()

if (mode == "bin-pack") {
batchScheduler = std::make_shared<BinPackScheduler>();
} else if (mode == "compact") {
batchScheduler = std::make_shared<CompactScheduler>();
} else {
SPDLOG_ERROR("Unrecognised batch scheduler mode: {}", mode);
throw std::runtime_error("Unrecognised batch scheduler mode");
Expand All @@ -33,6 +36,15 @@ void resetBatchScheduler()
batchScheduler = nullptr;
}

void resetBatchScheduler(const std::string& newMode)
{
resetBatchScheduler();

faabric::util::getSystemConfig().batchSchedulerMode = newMode;

getBatchScheduler();
}

DecisionType BatchScheduler::getDecisionType(
const InFlightReqs& inFlightReqs,
std::shared_ptr<faabric::BatchExecuteRequest> req)
Expand Down
1 change: 1 addition & 0 deletions src/batch-scheduler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ faabric_lib(scheduling_util
faabric_lib(batch_scheduler
BatchScheduler.cpp
BinPackScheduler.cpp
CompactScheduler.cpp
)

target_link_libraries(batch_scheduler PRIVATE
Expand Down
Loading