Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Utilities/DataSampling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ o2_add_executable(datasampling-benchmark
SOURCES test/dataSamplingBenchmark.cxx
COMPONENT_NAME DataSampling
PUBLIC_LINK_LIBRARIES O2::Framework O2::DataSampling)

o2_add_executable(datasampling-shared-payload
SOURCES test/dataSamplingSharedPayload.cxx
COMPONENT_NAME DataSampling
PUBLIC_LINK_LIBRARIES O2::Framework O2::DataSampling)
2 changes: 1 addition & 1 deletion Utilities/DataSampling/include/DataSampling/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Dispatcher : public framework::Task
private:
DataSamplingHeader prepareDataSamplingHeader(const DataSamplingPolicy& policy, header::DataHeader const& original);
void reportStats(monitoring::Monitoring& monitoring) const;
void send(framework::DataAllocator& dataAllocator, const framework::DataRef& inputData, const framework::Output& output) const;
void send(framework::DataAllocator& dataAllocator, const framework::DataRef& inputData, fair::mq::Message* inputPayload, const framework::Output& output) const;

std::string mName;
DataSamplingHeader::DeviceIDType mDeviceID = "invalid";
Expand Down
19 changes: 13 additions & 6 deletions Utilities/DataSampling/src/Dispatcher.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
#include "DataSampling/DataSamplingHeader.h"
#include "Framework/DataProcessingHeader.h"
#include "Framework/DataSpecUtils.h"
#include "Framework/Logger.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/Monitoring.h"
#include "Framework/DataRefUtils.h"
#include "Framework/FairMQDeviceProxy.h"
#include "Framework/DataProcessingHelpers.h"
#include "Framework/DataRelayer.h"

#include <fairmq/Message.h>
#include <Configuration/ConfigurationInterface.h>
#include <Configuration/ConfigurationFactory.h>
#include <stdexcept>
Expand Down Expand Up @@ -137,7 +136,9 @@ void Dispatcher::run(ProcessingContext& ctx)
if (auto route = policy->match(inputMatcher); route != nullptr && policy->decide(firstPart)) {
auto routeAsConcreteDataType = DataSpecUtils::asConcreteDataTypeMatcher(*route);
auto dsheader = prepareDataSamplingHeader(*policy, *firstInputHeader);
for (const auto& part : inputIt.parts()) {
auto parts = inputIt.parts();
for (auto partIt = parts.begin(); partIt != parts.end(); ++partIt) {
const DataRef& part = *partIt;
if (part.header != nullptr) {
// We copy every header which is not DataHeader or DataProcessingHeader,
// so that custom data-dependent headers are passed forward,
Expand All @@ -152,7 +153,7 @@ void Dispatcher::run(ProcessingContext& ctx)
routeAsConcreteDataType.description,
partInputHeader->subSpecification,
std::move(headerStack)};
send(ctx.outputs(), part, output);
send(ctx.outputs(), part, parts.getPayloadAtIndices(partIt.indices()), output);
}
}
}
Expand Down Expand Up @@ -193,10 +194,16 @@ DataSamplingHeader Dispatcher::prepareDataSamplingHeader(const DataSamplingPolic
original};
}

void Dispatcher::send(DataAllocator& dataAllocator, const DataRef& inputData, const Output& output) const
void Dispatcher::send(DataAllocator& dataAllocator, const DataRef& inputData, fair::mq::Message* inputPayload, const Output& output) const
{
const auto* inputHeader = DataRefUtils::getHeader<header::DataHeader*>(inputData);
dataAllocator.snapshot(output, inputData.payload, DataRefUtils::getPayloadSize(inputData), inputHeader->payloadSerializationMethod);
const auto payloadSize = DataRefUtils::getPayloadSize(inputData);
// Shallow copy when we have the original message and it is exactly the payload described by the header.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which cases that would not be true?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed that is overly protective.

  • inputPayload->GetData() == inputData.payload should never happen, I will remove it.
  • inputPayload can be theoretically nullptr right ? I would keep it.
  • And inputPayload->GetSize() == payloadSize is improbable, I will remove it too.
    ok for you ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what was reduced, but I am wondering why not go further. Should we ever get a nullptr with valid data? If yes - will falling back to snapshot help? If not - shouldn't we just print an error and skip dispatching the message? And to be clear, I don't know the answers myself.

I would see a reason to keep the snapshot fallback for debugging/validating/comparing the new and old way, switched with an env var. But if we keep as it is now, it will be difficult to know if forwarding works in production or we just fall back silently into snapshot.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean and I agree.
Let's print a message and carry on then.

if (inputPayload) {
dataAllocator.forwardPayload(output, *inputPayload, inputHeader->payloadSerializationMethod);
} else {
LOG(error) << "DS: got an empty payload, skipping";
}
}

void Dispatcher::registerPolicy(std::unique_ptr<DataSamplingPolicy>&& policy)
Expand Down
Loading