Skip to content

Commit 3483573

Browse files
authored
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
1 parent 7fba9d8 commit 3483573

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+497
-540
lines changed

Diff for: CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ endfunction()
9696

9797
add_subdirectory(src/batch-scheduler)
9898
add_subdirectory(src/endpoint)
99+
add_subdirectory(src/executor)
99100
add_subdirectory(src/flat)
100101
add_subdirectory(src/mpi)
101102
add_subdirectory(src/planner)
@@ -121,6 +122,7 @@ add_library(faabric
121122
faabric.cpp
122123
$<TARGET_OBJECTS:batch_scheduler_obj>
123124
$<TARGET_OBJECTS:endpoint_obj>
125+
$<TARGET_OBJECTS:executor_obj>
124126
$<TARGET_OBJECTS:flat_obj>
125127
$<TARGET_OBJECTS:mpi_obj>
126128
$<TARGET_OBJECTS:planner_obj>

Diff for: examples/server.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <faabric/endpoint/FaabricEndpoint.h>
2+
#include <faabric/executor/ExecutorFactory.h>
23
#include <faabric/runner/FaabricMain.h>
3-
#include <faabric/scheduler/ExecutorFactory.h>
44
#include <faabric/util/logging.h>
55

6-
using namespace faabric::scheduler;
6+
using namespace faabric::executor;
77

88
class ExampleExecutor : public Executor
99
{

Diff for: include/faabric/executor/Executor.h

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#pragma once
2+
3+
#include <faabric/executor/ExecutorTask.h>
4+
#include <faabric/proto/faabric.pb.h>
5+
#include <faabric/snapshot/SnapshotRegistry.h>
6+
#include <faabric/util/clock.h>
7+
#include <faabric/util/exception.h>
8+
#include <faabric/util/queue.h>
9+
#include <faabric/util/snapshot.h>
10+
11+
namespace faabric::executor {
12+
13+
class ChainedCallException : public faabric::util::FaabricException
14+
{
15+
public:
16+
explicit ChainedCallException(std::string message)
17+
: FaabricException(std::move(message))
18+
{}
19+
};
20+
21+
class Executor
22+
{
23+
public:
24+
std::string id;
25+
26+
explicit Executor(faabric::Message& msg);
27+
28+
// Must be marked virtual to permit proper calling of subclass destructors
29+
virtual ~Executor();
30+
31+
void executeTasks(std::vector<int> msgIdxs,
32+
std::shared_ptr<faabric::BatchExecuteRequest> req);
33+
34+
virtual void shutdown();
35+
36+
virtual void reset(faabric::Message& msg);
37+
38+
virtual int32_t executeTask(
39+
int threadPoolIdx,
40+
int msgIdx,
41+
std::shared_ptr<faabric::BatchExecuteRequest> req);
42+
43+
bool tryClaim();
44+
45+
void claim();
46+
47+
void releaseClaim();
48+
49+
std::shared_ptr<faabric::util::SnapshotData> getMainThreadSnapshot(
50+
faabric::Message& msg,
51+
bool createIfNotExists = false);
52+
53+
long getMillisSinceLastExec();
54+
55+
virtual std::span<uint8_t> getMemoryView();
56+
57+
virtual void restore(const std::string& snapshotKey);
58+
59+
faabric::Message& getBoundMessage();
60+
61+
bool isExecuting();
62+
63+
bool isShutdown() { return _isShutdown; }
64+
65+
void addChainedMessage(const faabric::Message& msg);
66+
67+
const faabric::Message& getChainedMessage(int messageId);
68+
69+
std::set<unsigned int> getChainedMessageIds();
70+
71+
std::vector<faabric::util::SnapshotDiff> mergeDirtyRegions(
72+
const Message& msg,
73+
const std::vector<char>& extraDirtyPages = {});
74+
75+
// FIXME: what is the right visibility?
76+
void setThreadResult(faabric::Message& msg,
77+
int32_t returnValue,
78+
const std::string& key,
79+
const std::vector<faabric::util::SnapshotDiff>& diffs);
80+
81+
virtual void setMemorySize(size_t newSize);
82+
83+
protected:
84+
virtual size_t getMaxMemorySize();
85+
86+
faabric::Message boundMessage;
87+
88+
faabric::snapshot::SnapshotRegistry& reg;
89+
90+
std::shared_ptr<faabric::util::DirtyTracker> tracker;
91+
92+
uint32_t threadPoolSize = 0;
93+
94+
std::map<int, std::shared_ptr<faabric::Message>> chainedMessages;
95+
96+
private:
97+
// ---- Accounting ----
98+
std::atomic<bool> claimed = false;
99+
std::atomic<bool> _isShutdown = false;
100+
std::atomic<int> batchCounter = 0;
101+
std::atomic<int> threadBatchCounter = 0;
102+
faabric::util::TimePoint lastExec;
103+
104+
// ---- Application threads ----
105+
std::shared_mutex threadExecutionMutex;
106+
std::vector<char> dirtyRegions;
107+
std::vector<std::vector<char>> threadLocalDirtyRegions;
108+
void deleteMainThreadSnapshot(const faabric::Message& msg);
109+
110+
// ---- Function execution thread pool ----
111+
std::mutex threadsMutex;
112+
std::vector<std::shared_ptr<std::jthread>> threadPoolThreads;
113+
std::set<int> availablePoolThreads;
114+
115+
std::vector<faabric::util::Queue<ExecutorTask>> threadTaskQueues;
116+
117+
void threadPoolThread(std::stop_token st, int threadPoolIdx);
118+
};
119+
}

Diff for: include/faabric/scheduler/ExecutorContext.h renamed to include/faabric/executor/ExecutorContext.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#pragma once
22

3+
#include <faabric/executor/Executor.h>
34
#include <faabric/proto/faabric.pb.h>
4-
#include <faabric/scheduler/Scheduler.h>
5+
#include <faabric/util/exception.h>
56

6-
namespace faabric::scheduler {
7+
namespace faabric::executor {
78

89
class ExecutorContextException : public faabric::util::FaabricException
910
{

Diff for: include/faabric/scheduler/ExecutorFactory.h renamed to include/faabric/executor/ExecutorFactory.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3-
#include <faabric/scheduler/Scheduler.h>
3+
#include <faabric/executor/Executor.h>
44

5-
namespace faabric::scheduler {
5+
namespace faabric::executor {
66

77
class ExecutorFactory
88
{

Diff for: include/faabric/executor/ExecutorTask.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <faabric/proto/faabric.pb.h>
4+
5+
namespace faabric::executor {
6+
7+
class ExecutorTask
8+
{
9+
public:
10+
ExecutorTask() = default;
11+
12+
ExecutorTask(int messageIndexIn,
13+
std::shared_ptr<BatchExecuteRequest> reqIn);
14+
15+
// Delete everything copy-related, default everything move-related
16+
ExecutorTask(const ExecutorTask& other) = delete;
17+
18+
ExecutorTask& operator=(const ExecutorTask& other) = delete;
19+
20+
ExecutorTask(ExecutorTask&& other) = default;
21+
22+
ExecutorTask& operator=(ExecutorTask&& other) = default;
23+
24+
std::shared_ptr<BatchExecuteRequest> req;
25+
int messageIndex = 0;
26+
};
27+
}

Diff for: include/faabric/runner/FaabricMain.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <faabric/scheduler/ExecutorFactory.h>
3+
#include <faabric/executor/ExecutorFactory.h>
44
#include <faabric/scheduler/FunctionCallServer.h>
55
#include <faabric/scheduler/Scheduler.h>
66
#include <faabric/snapshot/SnapshotServer.h>
@@ -12,7 +12,7 @@ namespace faabric::runner {
1212
class FaabricMain
1313
{
1414
public:
15-
FaabricMain(std::shared_ptr<faabric::scheduler::ExecutorFactory> fac);
15+
FaabricMain(std::shared_ptr<faabric::executor::ExecutorFactory> fac);
1616

1717
void startBackground();
1818

0 commit comments

Comments
 (0)