5
5
#include < faabric/scheduler/FunctionCallClient.h>
6
6
#include < faabric/scheduler/InMemoryMessageQueue.h>
7
7
#include < faabric/snapshot/SnapshotClient.h>
8
+ #include < faabric/util/asio.h>
8
9
#include < faabric/util/config.h>
9
10
#include < faabric/util/func.h>
10
11
#include < faabric/util/queue.h>
11
12
#include < faabric/util/scheduling.h>
12
13
#include < faabric/util/snapshot.h>
13
14
#include < faabric/util/timing.h>
14
15
16
+ #include < atomic>
17
+ #include < condition_variable>
18
+ #include < cstdint>
19
+ #include < functional>
15
20
#include < future>
21
+ #include < optional>
16
22
#include < shared_mutex>
17
23
18
24
#define AVAILABLE_HOST_SET " available_hosts"
@@ -55,6 +61,8 @@ class Executor
55
61
56
62
void finish ();
57
63
64
+ virtual void setup (faabric::Message& msg);
65
+
58
66
virtual void reset (faabric::Message& msg);
59
67
60
68
virtual int32_t executeTask (
@@ -73,6 +81,8 @@ class Executor
73
81
protected:
74
82
virtual void restore (faabric::Message& msg);
75
83
84
+ virtual void softShutdown ();
85
+
76
86
virtual void postFinish ();
77
87
78
88
faabric::Message boundMessage;
@@ -88,11 +98,37 @@ class Executor
88
98
std::vector<std::shared_ptr<std::thread>> threadPoolThreads;
89
99
std::vector<std::shared_ptr<std::thread>> deadThreads;
90
100
101
+ std::mutex setupMutex;
102
+ std::atomic_bool setupDone;
103
+
91
104
std::vector<faabric::util::Queue<ExecutorTask>> threadTaskQueues;
92
105
93
106
void threadPoolThread (int threadPoolIdx);
94
107
};
95
108
109
+ struct MessageLocalResult final
110
+ {
111
+ std::promise<std::unique_ptr<faabric::Message>> promise;
112
+ int event_fd = -1 ;
113
+
114
+ MessageLocalResult ();
115
+ MessageLocalResult (const MessageLocalResult&) = delete ;
116
+ inline MessageLocalResult (MessageLocalResult&& other)
117
+ {
118
+ this ->operator =(std::move (other));
119
+ }
120
+ MessageLocalResult& operator =(const MessageLocalResult&) = delete ;
121
+ inline MessageLocalResult& operator =(MessageLocalResult&& other)
122
+ {
123
+ this ->promise = std::move (other.promise );
124
+ this ->event_fd = other.event_fd ;
125
+ other.event_fd = -1 ;
126
+ return *this ;
127
+ }
128
+ ~MessageLocalResult ();
129
+ void set_value (std::unique_ptr<faabric::Message>&& msg);
130
+ };
131
+
96
132
class Scheduler
97
133
{
98
134
public:
@@ -128,6 +164,12 @@ class Scheduler
128
164
129
165
faabric::Message getFunctionResult (unsigned int messageId, int timeout);
130
166
167
+ void getFunctionResultAsync (unsigned int messageId,
168
+ int timeoutMs,
169
+ asio::io_context& ioc,
170
+ asio::any_io_executor& executor,
171
+ std::function<void (faabric::Message&)> handler);
172
+
131
173
void setThreadResult (const faabric::Message& msg, int32_t returnValue);
132
174
133
175
void pushSnapshotDiffs (
@@ -183,7 +225,15 @@ class Scheduler
183
225
184
226
ExecGraph getFunctionExecGraph (unsigned int msgId);
185
227
228
+ void updateMonitoring ();
229
+
230
+ std::atomic_int32_t monitorLocallyScheduledTasks;
231
+ std::atomic_int32_t monitorStartedTasks;
232
+ std::atomic_int32_t monitorWaitingTasks;
233
+
186
234
private:
235
+ int monitorFd = -1 ;
236
+
187
237
std::string thisHost;
188
238
189
239
faabric::util::SystemConfig& conf;
@@ -208,8 +258,7 @@ class Scheduler
208
258
std::set<std::string> availableHostsCache;
209
259
std::unordered_map<std::string, std::set<std::string>> registeredHosts;
210
260
211
- std::unordered_map<uint32_t ,
212
- std::promise<std::unique_ptr<faabric::Message>>>
261
+ std::unordered_map<uint32_t , std::shared_ptr<MessageLocalResult>>
213
262
localResults;
214
263
std::mutex localResultsMutex;
215
264
@@ -221,9 +270,7 @@ class Scheduler
221
270
std::vector<std::string> getUnregisteredHosts (const std::string& funcStr,
222
271
bool noCache = false );
223
272
224
- std::shared_ptr<Executor> claimExecutor (
225
- faabric::Message& msg,
226
- faabric::util::FullLock& schedulerLock);
273
+ std::shared_ptr<Executor> claimExecutor (faabric::Message& msg);
227
274
228
275
faabric::HostResources getHostResources (const std::string& host);
229
276
0 commit comments