Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf[MQB]: do not build temporary functors for every routed message #477

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
41 changes: 25 additions & 16 deletions src/groups/mqb/mqbblp/mqbblp_queueengineutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,17 @@ QueueEngineUtil_AppsDeliveryContext::QueueEngineUtil_AppsDeliveryContext(
, d_currentMessage(0)
, d_queue_p(queue)
, d_timeDelta()
, d_currentAppView_p(0)
, d_visitVisitor(
bdlf::BindUtil::bindS(allocator,
&QueueEngineUtil_AppsDeliveryContext::visit,
this,
bdlf::PlaceHolders::_1))
, d_broadcastVisitor(bdlf::BindUtil::bindS(
allocator,
&QueueEngineUtil_AppsDeliveryContext::visitBroadcast,
this,
bdlf::PlaceHolders::_1))
Copy link
Collaborator Author

@678098 678098 Oct 27, 2024

Choose a reason for hiding this comment

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

The alternative to this is to make Visitor functor and inherit from it locally.
Like here:
#481

Copy link
Collaborator

Choose a reason for hiding this comment

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

To implement new DeliveryContext interface...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's discuss it later then

{
BSLS_ASSERT_SAFE(queue);
}
Expand Down Expand Up @@ -670,12 +681,7 @@ bool QueueEngineUtil_AppsDeliveryContext::processApp(

if (d_queue_p->isDeliverAll()) {
// collect all handles
app.routing()->iterateConsumers(
bdlf::BindUtil::bind(
&QueueEngineUtil_AppsDeliveryContext::visitBroadcast,
this,
bdlf::PlaceHolders::_1),
d_currentMessage);
app.routing()->iterateConsumers(d_broadcastVisitor, d_currentMessage);

d_isReady = true;

Expand Down Expand Up @@ -708,13 +714,14 @@ bool QueueEngineUtil_AppsDeliveryContext::processApp(
// mapped file, which can delay the unmapping of files in case this
// message has a huge TTL and there are no consumers for this message.

Routers::Result result = app.selectConsumer(
bdlf::BindUtil::bind(&QueueEngineUtil_AppsDeliveryContext::visit,
this,
bdlf::PlaceHolders::_1,
appView),
d_currentMessage,
ordinal);
d_currentAppView_p = &appView;
Routers::Result result = app.selectConsumer(d_visitVisitor,
d_currentMessage,
ordinal);
// We use this pointer only from `d_visitVisitor`, so not cleaning it is
// okay, but we clean it to keep contract that `d_currentAppView_p` only
// points at the actual AppView.
d_currentAppView_p = NULL;

if (result == Routers::e_SUCCESS) {
// RootQueueEngine makes stat reports
Expand Down Expand Up @@ -749,14 +756,16 @@ bool QueueEngineUtil_AppsDeliveryContext::processApp(
}

bool QueueEngineUtil_AppsDeliveryContext::visit(
const Routers::Subscription* subscription,
const mqbi::AppMessage& appView)
const Routers::Subscription* subscription)
{
BSLS_ASSERT_SAFE(subscription);
BSLS_ASSERT_SAFE(
d_currentAppView_p &&
"`d_currentAppView_p` must be assigned before calling this function");

d_consumers[subscription->handle()].push_back(
bmqp::SubQueueInfo(subscription->d_downstreamSubscriptionId,
appView.d_rdaInfo));
d_currentAppView_p->d_rdaInfo));

return true;
}
Expand Down
19 changes: 17 additions & 2 deletions src/groups/mqb/mqbblp/mqbblp_queueengineutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,26 @@ struct QueueEngineUtil_AppsDeliveryContext {
mqbi::StorageIterator* d_currentMessage;
mqbi::Queue* d_queue_p;
bsl::optional<bsls::Types::Int64> d_timeDelta;

/// Mutable additional argument used in `visit()`, when it is called from
/// `d_visitVisitor` functor.
const mqbi::AppMessage* d_currentAppView_p;

/// Cached functor to `QueueEngineUtil_AppsDeliveryContext::visit`
const Routers::Visitor d_visitVisitor;

/// Cached functor to `QueueEngineUtil_AppsDeliveryContext::visitBroadcast`
const Routers::Visitor d_broadcastVisitor;

// Avoid reading the attributes if not necessary. Get timeDelta on demand.
// See comment in `QueueEngineUtil_AppsDeliveryContext::processApp`.

public:
// TRAITS
BSLMF_NESTED_TRAIT_DECLARATION(QueueEngineUtil_AppsDeliveryContext,
bslma::UsesBslmaAllocator)

// CREATORS
QueueEngineUtil_AppsDeliveryContext(mqbi::Queue* queue,
bslma::Allocator* allocator);

Expand Down Expand Up @@ -637,8 +653,7 @@ struct QueueEngineUtil_AppsDeliveryContext {
bool processApp(QueueEngineUtil_AppState& app, unsigned int ordina);

/// Collect and prepare data for the subsequent `deliverMessage` call.
bool visit(const Routers::Subscription* subscription,
const mqbi::AppMessage& appView);
bool visit(const Routers::Subscription* subscription);
bool visitBroadcast(const Routers::Subscription* subscription);

/// Deliver message to the previously processed handles.
Expand Down
Loading