Skip to content

Perf: concrete mqbi::DispatcherEvent events - #1116

Merged
678098 merged 3 commits into
bloomberg:mainfrom
678098:260213_dispatcher_event_inheritance
Apr 2, 2026
Merged

Perf: concrete mqbi::DispatcherEvent events#1116
678098 merged 3 commits into
bloomberg:mainfrom
678098:260213_dispatcher_event_inheritance

Conversation

@678098

@678098 678098 commented Feb 13, 2026

Copy link
Copy Markdown
Collaborator

Changes

  • Add new package group mqbevt.
  • Make mqbi::DispatcherEvent a base class for 12 concrete dispatcher event types. Move the sources of concrete event types to mqbevt package group.
  • Keep only the required minimum field set for each concrete dispatcher event type.
  • Include concrete event types in .cpp files, keep forward declarations to them in .h. This prevents leaking of heavy includes such as bmqp_protocol.h.
  • Make event type a static property of each dispatcher event implementation.
  • Get rid of isRelay where it's not needed.
  • Replace named concrete event accessors like asCallbackEvent() with templated ones like the<mqbevt::CallbackEvent>().
  • Manage separate shared object pools for different event types.

Benchmarks

Linux x86_64

Before:

Name                  | sizeof | constructor, ns/op
---------------------------------------------------
mqbi::DispatcherEvent |    768 |            46.6131               

After:

                       Name | sizeof | constructor, ns/op | reset (ns/op)
=========================================================================
           mqbevt::AckEvent |     96 |           6.145480 |      3.668200
      mqbevt::CallbackEvent |     64 |           6.136220 |      2.279000
  mqbevt::ClusterStateEvent |     48 |           5.440250 |      2.329530
       mqbevt::ConfirmEvent |     72 |           6.136910 |      3.357720
mqbevt::ControlMessageEvent |    208 |           9.437210 |      4.473490
    mqbevt::DispatcherEvent |    104 |           8.259750 |      2.133980
          mqbevt::PushEvent |    256 |          17.632800 |      5.508160
           mqbevt::PutEvent |    136 |           6.687370 |     12.936720
       mqbevt::ReceiptEvent |     48 |           5.165990 |      1.826960
      mqbevt::RecoveryEvent |     48 |           5.702260 |      2.432480
        mqbevt::RejectEvent |     80 |           5.820400 |      3.038740
       mqbevt::StorageEvent |     48 |           6.152550 |      2.431490

Mac M2

Before:

Name                  | sizeof | constructor, ns/op 
---------------------------------------------------
mqbi::DispatcherEvent |    768 |             197.51 

After:

                       Name | sizeof | constructor, ns/op | reset (ns/op)
=========================================================================
           mqbevt::AckEvent |     96 |          19.357500 |      9.600840
      mqbevt::CallbackEvent |     64 |          25.825420 |      5.437500
  mqbevt::ClusterStateEvent |     48 |          12.276250 |      5.537080
       mqbevt::ConfirmEvent |     72 |          13.469590 |      7.685420
mqbevt::ControlMessageEvent |    208 |          35.178330 |     17.594170
    mqbevt::DispatcherEvent |    104 |          34.957500 |      7.789590
          mqbevt::PushEvent |    256 |          65.809580 |     26.294170
           mqbevt::PutEvent |    136 |          52.033750 |     47.957500
       mqbevt::ReceiptEvent |     48 |           9.312500 |      4.004170
      mqbevt::RecoveryEvent |     48 |           8.900420 |      4.003750
        mqbevt::RejectEvent |     80 |          10.410410 |      5.669160
       mqbevt::StorageEvent |     48 |           8.735410 |      4.276250

@678098
678098 requested a review from a team as a code owner February 13, 2026 21:42
@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch from a2689f8 to f132bff Compare February 18, 2026 17:24
@678098 678098 changed the title wip: Perf: fix mqbi::DispatcherEvent inheritance, event sources per event type Perf: fix mqbi::DispatcherEvent inheritance, event sources per event type Feb 18, 2026
@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch from 5333fc9 to e227be8 Compare February 18, 2026 21:20
@678098 678098 changed the title Perf: fix mqbi::DispatcherEvent inheritance, event sources per event type Perf: invert mqbi::DispatcherEvent inheritance Feb 18, 2026
@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch 5 times, most recently from 26a6afd to 78775ae Compare February 20, 2026 17:24
@678098 678098 changed the title Perf: invert mqbi::DispatcherEvent inheritance Perf: concrete mqbi::DispatcherEvent events Feb 20, 2026
@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch 5 times, most recently from ade84c9 to 28ee596 Compare February 27, 2026 20:50
@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch 8 times, most recently from e4b0209 to f4a0012 Compare March 25, 2026 19:07
.setSource(&d_cs) // DispatcherClient *value
.setPutHeader(putHeader)
.setBlob(eventBlob) // const bsl::shared_ptr<bdlbb::Blob>& value
.setCompressionAlgorithmType(cat);

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 have simplified isRelay usage. For some event types, it is always true or always false. In such cases, possible to remove this flag fully.
Also I have removed other unused fields. In this case, we don't access compression algorithm type for PUT events, so there is no need to set it or keep it.
With concrete event types, it is easier to keep track on what is used and what is not used.

@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch 3 times, most recently from ba08272 to cfcc2b7 Compare March 30, 2026 18:13

/// Execute the specified `functor`, using the `e_CALLBACK` event
/// type, in the processor associated to this object.
void execute(const mqbi::Dispatcher::VoidFunctor& functor);

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.

Only the mqbs::FileStore has dispatchEvent and execute.
These functions might be defined for mqbi::DispatcherClient and be used more often by its implementations. It can be done in the next refactor, here I decided not to add this to the diff.

@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch 12 times, most recently from cda39c1 to 21bebcf Compare March 30, 2026 20:56
bmqt::CompressionAlgorithmType::Enum d_compressionAlgorithmType;

/// Whether the associated PUSH message is out-of-order.
bool d_isOutOfOrderPush;

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 did not try to optimize memory layouts in this PR for simplicity, will do it later. We can win a few more bytes in some cases.

@678098 678098 left a comment

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.

Self-review is ok

@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch 2 times, most recently from 262fb89 to ffa6d14 Compare March 30, 2026 21:06
@678098
678098 requested a review from hallfox March 30, 2026 21:07
@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch from ffa6d14 to 757f955 Compare March 30, 2026 21:42
Comment thread src/groups/mqb/mqba/mqba_clientsession.cpp Outdated
Comment thread src/groups/mqb/mqba/mqba_dispatchereventsource.cpp Outdated
Comment thread src/groups/mqb/mqbblp/mqbblp_cluster.cpp Outdated
Comment thread src/groups/mqb/mqbblp/mqbblp_cluster.cpp Outdated
Comment thread src/groups/mqb/mqbblp/mqbblp_cluster.h Outdated
Comment thread src/groups/mqb/mqbevt/package/mqbevt.dep Outdated
Comment thread src/groups/mqb/mqbi/mqbi_dispatcher.h Outdated
Comment thread src/groups/mqb/mqbi/mqbi_dispatcher.h Outdated
Comment thread src/groups/mqb/mqbi/mqbi_dispatcher.h Outdated
Comment thread src/groups/mqb/mqbi/mqbi_dispatcher.h Outdated
678098 added 2 commits April 1, 2026 07:38
Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
@678098
678098 force-pushed the 260213_dispatcher_event_inheritance branch from 757f955 to f2aec06 Compare April 1, 2026 11:38
@678098

678098 commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator Author

@hallfox applied fixes in the second commit


namespace {
const int k_POOL_GROW_BY = 1024;
BSLS_KEYWORD_CONSTEXPR int k_POOL_GROW_BY = 1024;

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.

Since this compiles to nothing on Solaris it's still good to have the const qualifier here. According to the BDE docs this is a recommended way for using the CONSTEXPR keyword.

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.

Fixed

Signed-off-by: Evgenii Malygin <emalygin@bloomberg.net>
@678098
678098 requested a review from hallfox April 1, 2026 18:28
@678098
678098 merged commit a2b0b0b into bloomberg:main Apr 2, 2026
45 of 46 checks passed
@678098
678098 deleted the 260213_dispatcher_event_inheritance branch April 2, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants