You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c6e0fcd
Browse filesBrowse the repository at this point in the historyBrowse files
Factor the primary request out of the sim worker kernel
This moves the request for a chunk of primaries out of O2SimDevice::Kernel into
O2SimDevice::fetchChunk, without changing the behaviour.
- fetchChunk sends the request, waits for the answer, backs off while the server is busy and decodes the chunk.
- It reports whether there is work, nothing yet, the end-of-work marker, or nothing more to ask for, and Kernel acts on that as before.
This lets a multithreaded Geant4 worker request its work the same way as a worker process does now.
https://its.cern.ch/jira/browse/O2-7305
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fair::mq::MessagePtr request(requestchannel.NewSimpleMessage(PrimaryChunkRequest{workerID, -1, counter++})); // <-- don't need content; channel means -> give primaries
fair::mq::MessagePtr request(requestchannel.NewSimpleMessage(PrimaryChunkRequest{workerID, -1, counter++})); // <-- don't need content; channel means -> give primaries
223
+
fair::mq::Parts reply;
224
+
225
+
auto workerStr = [workerID]() {
226
+
std::stringstream str;
227
+
str << "[W" << workerID << "]";
228
+
return str.str();
229
+
};
230
+
173
231
doLogInfo(workerID, "Requesting work chunk");
174
232
int timeoutinMS = 2000;
175
233
auto sendcode = requestchannel.Send(request, timeoutinMS);
176
-
if (sendcode > 0) {
177
-
doLogInfo(workerID, "Waiting for answer");
178
-
// asking for primary generation
179
-
180
-
auto code = requestchannel.Receive(reply);
181
-
if (code > 0) {
182
-
doLogInfo(workerID, "Primary chunk received");
183
-
auto rawmessage = std::move(reply.At(0));
184
-
auto header = *(o2::PrimaryChunkAnswer*)(rawmessage->GetData());
185
-
if (!header.payload_attached) {
186
-
doLogInfo(workerID, "No payload; Server in stage " + std::string(PrimStateToString[(int)header.serverstate]));
187
-
// if no payload attached we inspect the server state, to see what to do
188
-
if (header.serverstate == O2PrimaryServerState::Initializing || header.serverstate == O2PrimaryServerState::WaitingEvent) {
189
-
sleep(1); // back-off and retry
190
-
returntrue;
191
-
}
192
-
// we need to decide what to do when the server is idle ---> if this happens immediately after a new batch request it means that the server might just lag a bit behind
193
-
returnfalse;
194
-
} else {
195
-
auto payload = std::move(reply.At(1));
196
-
// wrap incoming bytes as a TMessageWrapper which offers "adoption" of a buffer
197
-
auto message = newTMessageWrapper(payload->GetData(), payload->GetSize());
198
-
auto chunk = static_cast<o2::data::PrimaryChunk*>(message->ReadObjectAny(message->GetClass()));
199
-
200
-
bool goon = true;
201
-
// no particles and eventID == -1 --> indication for no more work
202
-
if (chunk->mParticles.size() == 0 && chunk->mSubEventInfo.eventID == -1) {
203
-
doLogInfo(workerID, "No particles in reply : quitting kernel");
LOG(info) << workerStr() << " No primary answer received from server (within timeout). Return code " << code;
253
-
}
254
-
} else {
234
+
if (sendcode <= 0) {
255
235
LOG(info) << workerStr() << " Requesting work from server not possible. Return code " << sendcode;
256
-
returnfalse;
236
+
return{ChunkStatus::Stop, nullptr};
257
237
}
258
-
returntrue;
238
+
doLogInfo(workerID, "Waiting for answer");
239
+
// asking for primary generation
240
+
auto code = requestchannel.Receive(reply);
241
+
if (code <= 0) {
242
+
LOG(info) << workerStr() << " No primary answer received from server (within timeout). Return code " << code;
243
+
return {ChunkStatus::Retry, nullptr};
244
+
}
245
+
doLogInfo(workerID, "Primary chunk received");
246
+
auto rawmessage = std::move(reply.At(0));
247
+
auto header = *(o2::PrimaryChunkAnswer*)(rawmessage->GetData());
248
+
if (!header.payload_attached) {
249
+
doLogInfo(workerID, "No payload; Server in stage " + std::string(PrimStateToString[(int)header.serverstate]));
250
+
// if no payload attached we inspect the server state, to see what to do
251
+
if (header.serverstate == O2PrimaryServerState::Initializing || header.serverstate == O2PrimaryServerState::WaitingEvent) {
252
+
sleep(1); // back-off and retry
253
+
return {ChunkStatus::Retry, nullptr};
254
+
}
255
+
// we need to decide what to do when the server is idle ---> if this happens immediately after a new batch request it means that the server might just lag a bit behind
256
+
return {ChunkStatus::Stop, nullptr};
257
+
}
258
+
auto payload = std::move(reply.At(1));
259
+
// wrap incoming bytes as a TMessageWrapper which offers "adoption" of a buffer
0 commit comments