Skip to content

Commit 8568b60

Browse files
committed
Add free SHM based TF rate throttling to raw proxy
1 parent db201de commit 8568b60

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

Framework/Core/include/Framework/ExternalFairMQDeviceProxy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ std::string defaultOutputProxyChannelSelector(InputSpec const& input, const std:
8383
DataProcessorSpec specifyExternalFairMQDeviceProxy(char const* label,
8484
std::vector<OutputSpec> const& outputs,
8585
const char* defaultChannelConfig,
86-
InjectorFunction converter);
86+
InjectorFunction converter,
87+
uint64_t minSHM = 0);
8788

8889
DataProcessorSpec specifyFairMQDeviceOutputProxy(char const* label,
8990
Inputs const& inputSpecs,

Framework/Core/src/ExternalFairMQDeviceProxy.cxx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Framework/ControlService.h"
2323
#include "Framework/SourceInfoHeader.h"
2424
#include "Framework/ConfigParamRegistry.h"
25+
#include "Framework/RunningWorkflowInfo.h"
2526
#include "Headers/DataHeader.h"
2627
#include "Headers/Stack.h"
2728

@@ -30,6 +31,7 @@
3031

3132
#include <fairmq/FairMQParts.h>
3233
#include <fairmq/FairMQDevice.h>
34+
#include <fairmq/shmem/Monitor.h>
3335
#include <cstring>
3436
#include <cassert>
3537
#include <memory>
@@ -347,7 +349,8 @@ DataProcessorSpec specifyExternalFairMQDeviceProxy(char const* name,
347349
std::function<void(FairMQDevice&,
348350
FairMQParts&,
349351
ChannelRetriever)>
350-
converter)
352+
converter,
353+
uint64_t minSHM)
351354
{
352355
DataProcessorSpec spec;
353356
spec.name = strdup(name);
@@ -356,7 +359,7 @@ DataProcessorSpec specifyExternalFairMQDeviceProxy(char const* name,
356359
// The Init method will register a new "Out of band" channel and
357360
// attach an OnData to it which is responsible for converting incoming
358361
// messages into DPL messages.
359-
spec.algorithm = AlgorithmSpec{[converter, channel = spec.name](InitContext& ctx) {
362+
spec.algorithm = AlgorithmSpec{[converter, channel = spec.name, minSHM](InitContext& ctx) {
360363
auto device = ctx.services().get<RawDeviceService>().device();
361364
// make a copy of the output routes and pass to the lambda by move
362365
auto outputRoutes = ctx.services().get<RawDeviceService>().spec().outputs;
@@ -411,7 +414,7 @@ DataProcessorSpec specifyExternalFairMQDeviceProxy(char const* name,
411414
}
412415
};
413416

414-
auto runHandler = [dataHandler, device, channel](ProcessingContext& ctx) {
417+
auto runHandler = [dataHandler, device, channel, minSHM](ProcessingContext& ctx) {
415418
static int64_t consumedTimeframes = 0;
416419
static int64_t sentTimeframes = 0;
417420
auto device = ctx.services().get<RawDeviceService>().device();
@@ -439,6 +442,23 @@ DataProcessorSpec specifyExternalFairMQDeviceProxy(char const* name,
439442
LOG(important) << (sentTimeframes - consumedTimeframes) << " / " << maxTFInFlight << " TF in flight, continuing to publish";
440443
}
441444
}
445+
if (minSHM) {
446+
int waitMessage = 0;
447+
auto& runningWorkflow = ctx.services().get<RunningWorkflowInfo const>();
448+
while (true) {
449+
uint64_t freeSHM = fair::mq::shmem::Monitor::GetFreeMemory(fair::mq::shmem::SessionId{device->fConfig->GetProperty<std::string>("session")}, runningWorkflow.shmSegmentId);
450+
if (freeSHM > minSHM) {
451+
if (waitMessage) {
452+
LOG(important) << "Sufficient SHM memory free (" << freeSHM << " >= " << minSHM << "), continuing to publish";
453+
}
454+
break;
455+
}
456+
if (waitMessage == 0) {
457+
LOG(alarm) << "Free SHM memory too low: " << freeSHM << " < " << minSHM << ", waiting";
458+
waitMessage = 1;
459+
}
460+
}
461+
}
442462

443463
FairMQParts parts;
444464
device->Receive(parts, channel, 0);

Framework/Utils/src/raw-proxy.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
3434
workflowOptions.push_back(
3535
ConfigParamSpec{
3636
"throwOnUnmatched", VariantType::Bool, false, {"throw if unmatched input data is found"}});
37+
38+
workflowOptions.push_back(
39+
ConfigParamSpec{
40+
"timeframes-shm-limit", VariantType::String, "0", {"Minimum amount of SHM required in order to publish data"}});
3741
}
3842

3943
#include "Framework/runDataProcessing.h"
@@ -43,6 +47,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& config)
4347
std::string processorName = config.options().get<std::string>("proxy-name");
4448
std::string outputconfig = config.options().get<std::string>("dataspec");
4549
bool throwOnUnmatched = config.options().get<bool>("throwOnUnmatched");
50+
uint64_t minSHM = std::stoul(config.options().get<std::string>("timeframes-shm-limit"));
4651
std::vector<InputSpec> matchers = select(outputconfig.c_str());
4752
Outputs readoutProxyOutput;
4853
for (auto const& matcher : matchers) {
@@ -55,7 +60,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& config)
5560
processorName.c_str(),
5661
std::move(readoutProxyOutput),
5762
"type=pair,method=connect,address=ipc:///tmp/readout-pipe-0,rateLogging=1,transport=shmem",
58-
dplModelAdaptor(filterSpecs, throwOnUnmatched));
63+
dplModelAdaptor(filterSpecs, throwOnUnmatched), minSHM);
5964

6065
WorkflowSpec workflow;
6166
workflow.emplace_back(readoutProxy);

0 commit comments

Comments
 (0)