ATLAS Offline Software
Loading...
Searching...
No Matches
RemoteExecHiveEventLoopMgr.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ATHREMOTEEXECCORE_REMOTEEXECHIVEEVENTLOOPMGR_H
5#define ATHREMOTEEXECCORE_REMOTEEXECHIVEEVENTLOOPMGR_H
6
36
39
40#include <atomic>
41#include <chrono>
42#include <condition_variable>
43#include <cstddef>
44#include <deque>
45#include <map>
46#include <memory>
47#include <mutex>
48#include <string>
49#include <thread>
50#include <vector>
51
53#include "Gaudi/Property.h"
54
55class EventContext;
56class StoreGateSvc;
57
58namespace AthRemoteExec {
59
61 public:
62 RemoteExecHiveEventLoopMgr(const std::string& name, ISvcLocator* svcLoc);
63 virtual ~RemoteExecHiveEventLoopMgr() override;
64
65 virtual StatusCode initialize() override;
66 virtual StatusCode finalize() override;
67
70 virtual StatusCode nextEvent(int maxevt) override;
71
73 virtual StatusCode stopRun() override;
74
75 protected:
76 StatusCode eventFinished(const EventContext& ctx) override;
77 bool clearStoreOnEndAlgorithms() const override { return false; }
78
80 enum class Take {
84 };
85
87 virtual Take takeRequest(ExecuteRequest& request,
88 std::unique_ptr<Server::Job>& job);
89
91 virtual StatusCode startServing();
92
93 private:
94 using Clock = std::chrono::steady_clock;
95
97 struct InFlight {
100 std::unique_ptr<Server::Job> job;
101 Clock::time_point deadline;
102 bool hasDeadline = false;
105 bool answered = false;
106 };
107
111 struct Finished {
112 EventContext* ctx = nullptr;
113 Clock::time_point at;
114 };
115
118 void inputLoop();
119
122 void outputLoop();
123
125 void startHelpers();
126
128 void stopHelpers();
129
131 std::vector<Finished> takeFinished();
132
134 void drainPending();
135
138 std::string& diagnostics) const;
139
141 StatusCode dispatch(ExecuteRequest request,
142 std::unique_ptr<Server::Job> job);
143
145 StatusCode complete(const Finished& finished);
146
148 ExecuteReply buildReply(const EventContext& ctx, const InFlight& entry);
149
152 void expireDeadlines();
153
155 void respond(InFlight& entry, ExecuteReply reply);
156
158 void respondDirect(const ExecuteRequest& request,
159 const std::unique_ptr<Server::Job>& job,
161 const std::string& diagnostics);
162
164 std::string failedAlgorithms(const EventContext& ctx);
165
167 std::string replyKeyFor(const std::string& sequence) const;
168
170 void serverMessage(Server::Level level, const std::string& text);
171
172 // clang-format off
173
174 Gaudi::Property<std::vector<std::string>> m_sequences{
175 this, "Sequences", {}, "Names of the algorithm sequences (fragments) this server offers"};
176 Gaudi::Property<std::map<std::string, std::vector<std::string>>> m_inputKeys{
177 this, "Decoders", {}, "Per sequence, The boundaries the client must supply."};
178 Gaudi::Property<std::map<std::string, std::vector<std::string>>> m_outputKeys{
179 this, "Encoders", {}, "Per sequence, the boundaries returned to the client."};
180 Gaudi::Property<std::map<std::string, std::string>> m_replyKeys{
181 this, "ReplyKeys", {}, "Per sequence, the key its pack algorithm stages the reply under."};
182 Gaudi::Property<std::string> m_requestKey{
183 this, "RequestKey", "RemoteExecRequest", "StoreGate key that the request is recorded under."};
184
185 Gaudi::Property<std::string> m_address{
186 this, "Address", "0.0.0.0", "Interface the server binds to"};
187 Gaudi::Property<int> m_port{
188 this, "Port", 0, "TCP port to bind. 0 lets the OS choose."};
189 Gaudi::Property<std::string> m_portFile{
190 this, "PortFile", "", "If set, the bound port is written to this file once the server is up. Lets a test client discover a port chosen by the OS"};
191 Gaudi::Property<int> m_maxMessageBytes{
192 this, "MaxMessageBytes", 256 * 1024 * 1024, "Largest request or reply the server will accept."};
193 Gaudi::Property<size_t> m_queueLimit{
194 this, "QueueLimit", 128, "Maximum number of queued requests before clients are told the server is overloaded"};
195
196 Gaudi::Property<double> m_requestTimeout{
197 this, "RequestTimeout", 0.0, "Seconds before an in-flight request is answered with TIMEOUT. 0 disables the timeout."};
198 Gaudi::Property<unsigned int> m_pollInterval{
199 this, "PollInterval", 5, "Milliseconds between scheduler polls."};
200
201 Gaudi::Property<bool> m_reportTiming{
202 this, "ReportTiming", true, ""};
203
204 // clang-format on
205
206 std::unique_ptr<Server> m_server;
207 std::map<size_t, InFlight> m_inFlight;
208 size_t m_nextEvent = 0;
209 size_t m_completed = 0;
210
211 std::thread m_inputThread;
212 std::thread m_outputThread;
213 std::mutex m_pendingMutex;
214 std::condition_variable m_pending;
215 std::condition_variable m_inFlightCv;
216 std::condition_variable m_incomingRoom;
217 std::deque<std::unique_ptr<Server::Job>> m_incoming;
218 size_t m_incomingLimit = 1;
219 std::deque<Finished> m_finishedEvents;
221 bool m_inputDone = false;
222 bool m_helpersStopping = false;
223
224 std::mutex m_messageMutex;
225 std::atomic<bool> m_stopRequested{false};
226};
227
228} // namespace AthRemoteExec
229
230#endif // ATHREMOTEEXECCORE_REMOTEEXECHIVEEVENTLOOPMGR_H
The default ATLAS batch event loop manager.
Plain C++ interfaces of RPC wire.
Minimal RPC server; transport part of RemoteExecHiveEventLoopMgr.
@ None
StatusCode eventFinished(const EventContext &ctx) override
Process an event's result and decide whether the driving loop may continue.
std::string replyKeyFor(const std::string &sequence) const
The reply key of sequence, or an empty string if it declares none.
std::condition_variable m_pending
loop waits here
void inputLoop()
Loop and wait for incoming job.
std::map< size_t, InFlight > m_inFlight
keyed by whiteboard slot
StatusCode complete(const Finished &finished)
Read the result of one finished event and release its slot.
std::condition_variable m_incomingRoom
input thread waits here
void respond(InFlight &entry, ExecuteReply reply)
Reply to the request.
void respondDirect(const ExecuteRequest &request, const std::unique_ptr< Server::Job > &job, AthRemoteExec::Status status, const std::string &diagnostics)
Reply to the request that never got assigned to slot.
Gaudi::Property< std::map< std::string, std::vector< std::string > > > m_inputKeys
StatusCode dispatch(ExecuteRequest request, std::unique_ptr< Server::Job > job)
Give a request a slot and push it to the scheduler.
void expireDeadlines()
Reply to all request that passed their deadline.
virtual Take takeRequest(ExecuteRequest &request, std::unique_ptr< Server::Job > &job)
Take the next request from the incoming event queue.
void drainPending()
Answer to anything that the loop did not manage to finish.
virtual StatusCode startServing()
Create and start the server.
RemoteExecHiveEventLoopMgr(const std::string &name, ISvcLocator *svcLoc)
Gaudi::Property< std::map< std::string, std::vector< std::string > > > m_outputKeys
std::condition_variable m_inFlightCv
output thread waits here
virtual StatusCode initialize() override
implementation of IAppMgrUI::initalize
std::deque< std::unique_ptr< Server::Job > > m_incoming
ExecuteReply buildReply(const EventContext &ctx, const InFlight &entry)
Turn a finished event into the reply for its request.
AthRemoteExec::Status validate(const ExecuteRequest &request, std::string &diagnostics) const
Reject requests that cannot possibly run, before a slot is spent on them.
virtual StatusCode stopRun() override
Ask the loop to stop accepting work and drain what is in flight.
std::vector< Finished > takeFinished()
Take whatever the output thread has collected from finished event queue.
void outputLoop()
Loop and wait for finished job.
bool clearStoreOnEndAlgorithms() const override
Batch jobs clear in the algorithm context; external drivers can retain the store until eventFinished(...
Gaudi::Property< std::vector< std::string > > m_sequences
virtual StatusCode finalize() override
implementation of IAppMgrUI::finalize
void serverMessage(Server::Level level, const std::string &text)
Thread-safe log sink handed to the RPC server.
Gaudi::Property< std::map< std::string, std::string > > m_replyKeys
virtual StatusCode nextEvent(int maxevt) override
Serve requests.
std::string failedAlgorithms(const EventContext &ctx)
Names of the algorithms that failed in ctx. For the reply diagnostics.
Level
Severity levels, matching MSG::Level so the funnel can forward them.
Definition Server.h:42
virtual const std::string & name() const override
AthenaHiveEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
The Athena Transient Store API.
Status
RPC reply status.
Definition Protocol.h:32
A finished event, from the scheduler's point of view.
A request that has been given a slot and handed to the scheduler.
bool answered
Set once the client has been answered.
std::unique_ptr< Server::Job > job
The RPC job whose promise must be fulfilled.