-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executor: move executor code to separate top-level directory (#365)
* executor: move executor code to separate top-level directory * tests: refactor tests to accomodate for change in source code structure * dist-tests: fix server compilation
- Loading branch information
1 parent
7fba9d8
commit 3483573
Showing
45 changed files
with
497 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#pragma once | ||
|
||
#include <faabric/executor/ExecutorTask.h> | ||
#include <faabric/proto/faabric.pb.h> | ||
#include <faabric/snapshot/SnapshotRegistry.h> | ||
#include <faabric/util/clock.h> | ||
#include <faabric/util/exception.h> | ||
#include <faabric/util/queue.h> | ||
#include <faabric/util/snapshot.h> | ||
|
||
namespace faabric::executor { | ||
|
||
class ChainedCallException : public faabric::util::FaabricException | ||
{ | ||
public: | ||
explicit ChainedCallException(std::string message) | ||
: FaabricException(std::move(message)) | ||
{} | ||
}; | ||
|
||
class Executor | ||
{ | ||
public: | ||
std::string id; | ||
|
||
explicit Executor(faabric::Message& msg); | ||
|
||
// Must be marked virtual to permit proper calling of subclass destructors | ||
virtual ~Executor(); | ||
|
||
void executeTasks(std::vector<int> msgIdxs, | ||
std::shared_ptr<faabric::BatchExecuteRequest> req); | ||
|
||
virtual void shutdown(); | ||
|
||
virtual void reset(faabric::Message& msg); | ||
|
||
virtual int32_t executeTask( | ||
int threadPoolIdx, | ||
int msgIdx, | ||
std::shared_ptr<faabric::BatchExecuteRequest> req); | ||
|
||
bool tryClaim(); | ||
|
||
void claim(); | ||
|
||
void releaseClaim(); | ||
|
||
std::shared_ptr<faabric::util::SnapshotData> getMainThreadSnapshot( | ||
faabric::Message& msg, | ||
bool createIfNotExists = false); | ||
|
||
long getMillisSinceLastExec(); | ||
|
||
virtual std::span<uint8_t> getMemoryView(); | ||
|
||
virtual void restore(const std::string& snapshotKey); | ||
|
||
faabric::Message& getBoundMessage(); | ||
|
||
bool isExecuting(); | ||
|
||
bool isShutdown() { return _isShutdown; } | ||
|
||
void addChainedMessage(const faabric::Message& msg); | ||
|
||
const faabric::Message& getChainedMessage(int messageId); | ||
|
||
std::set<unsigned int> getChainedMessageIds(); | ||
|
||
std::vector<faabric::util::SnapshotDiff> mergeDirtyRegions( | ||
const Message& msg, | ||
const std::vector<char>& extraDirtyPages = {}); | ||
|
||
// FIXME: what is the right visibility? | ||
void setThreadResult(faabric::Message& msg, | ||
int32_t returnValue, | ||
const std::string& key, | ||
const std::vector<faabric::util::SnapshotDiff>& diffs); | ||
|
||
virtual void setMemorySize(size_t newSize); | ||
|
||
protected: | ||
virtual size_t getMaxMemorySize(); | ||
|
||
faabric::Message boundMessage; | ||
|
||
faabric::snapshot::SnapshotRegistry& reg; | ||
|
||
std::shared_ptr<faabric::util::DirtyTracker> tracker; | ||
|
||
uint32_t threadPoolSize = 0; | ||
|
||
std::map<int, std::shared_ptr<faabric::Message>> chainedMessages; | ||
|
||
private: | ||
// ---- Accounting ---- | ||
std::atomic<bool> claimed = false; | ||
std::atomic<bool> _isShutdown = false; | ||
std::atomic<int> batchCounter = 0; | ||
std::atomic<int> threadBatchCounter = 0; | ||
faabric::util::TimePoint lastExec; | ||
|
||
// ---- Application threads ---- | ||
std::shared_mutex threadExecutionMutex; | ||
std::vector<char> dirtyRegions; | ||
std::vector<std::vector<char>> threadLocalDirtyRegions; | ||
void deleteMainThreadSnapshot(const faabric::Message& msg); | ||
|
||
// ---- Function execution thread pool ---- | ||
std::mutex threadsMutex; | ||
std::vector<std::shared_ptr<std::jthread>> threadPoolThreads; | ||
std::set<int> availablePoolThreads; | ||
|
||
std::vector<faabric::util::Queue<ExecutorTask>> threadTaskQueues; | ||
|
||
void threadPoolThread(std::stop_token st, int threadPoolIdx); | ||
}; | ||
} |
5 changes: 3 additions & 2 deletions
5
include/faabric/scheduler/ExecutorContext.h → include/faabric/executor/ExecutorContext.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
include/faabric/scheduler/ExecutorFactory.h → include/faabric/executor/ExecutorFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <faabric/proto/faabric.pb.h> | ||
|
||
namespace faabric::executor { | ||
|
||
class ExecutorTask | ||
{ | ||
public: | ||
ExecutorTask() = default; | ||
|
||
ExecutorTask(int messageIndexIn, | ||
std::shared_ptr<BatchExecuteRequest> reqIn); | ||
|
||
// Delete everything copy-related, default everything move-related | ||
ExecutorTask(const ExecutorTask& other) = delete; | ||
|
||
ExecutorTask& operator=(const ExecutorTask& other) = delete; | ||
|
||
ExecutorTask(ExecutorTask&& other) = default; | ||
|
||
ExecutorTask& operator=(ExecutorTask&& other) = default; | ||
|
||
std::shared_ptr<BatchExecuteRequest> req; | ||
int messageIndex = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.