File Executor.h

namespace faabric
namespace executor
class ChainedCallException : public faabric::util::FaabricException

Public Functions

inline explicit ChainedCallException(std::string message)
class Executor

Public Functions

explicit Executor(faabric::Message &msg)
virtual ~Executor()
void executeTasks(std::vector<int> msgIdxs, std::shared_ptr<faabric::BatchExecuteRequest> req)
virtual void shutdown()

Shuts down the executor and clears all its state, including its thread pool.

This must be called before destructing an executor. This is because the tidy-up requires implementations of virtual methods held in subclasses, that may depend on state that those subclass instances hold. Because destructors run in inheritance order, this means that state may have been destructed before the executor destructor runs.

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()
inline bool 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 = {})
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)

Public Members

std::string id

Protected Functions

virtual size_t getMaxMemorySize()

Protected Attributes

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 Functions

void deleteMainThreadSnapshot(const faabric::Message &msg)
void threadPoolThread(std::stop_token st, int threadPoolIdx)

Private Members

std::atomic<bool> claimed = false
std::atomic<bool> _isShutdown = false
std::atomic<int> batchCounter = 0
std::atomic<int> threadBatchCounter = 0
faabric::util::TimePoint lastExec
std::shared_mutex threadExecutionMutex
std::vector<char> dirtyRegions
std::vector<std::vector<char>> threadLocalDirtyRegions
std::mutex threadsMutex
std::vector<std::shared_ptr<std::jthread>> threadPoolThreads
std::set<int> availablePoolThreads
std::vector<faabric::util::Queue<ExecutorTask>> threadTaskQueues