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

filter events in subscription engine #637

Merged
merged 6 commits into from
Dec 12, 2024

Conversation

DavidBadura
Copy link
Member

@DavidBadura DavidBadura commented Oct 6, 2024

This PR adds the option to filter the stream by events. This allows us to optimize the subscription engine so that we only load the events that the subscriptions need.

In other words, before the stream is loaded, all subscriptions that are currently being used are checked to see which events are needed. This list is then used to load the stream with a filter. As soon as a subscriber hears * (all), all events are always loaded.

This strategy is optional and can be tried out with the changed typehint for the store parameter in the subscription engine. The MessageLoader interface was introduced for this purpose.

$engine = new DefaultSubscriptionEngine(
    new EventFilteredStoreMessageLoader(
        $store, 
        new AttributeEventMetadataFactory(), 
        $subscriberRepository,
    ),
    $subscriberRepository,
);

@DavidBadura DavidBadura added this to the 3.5.0 milestone Oct 6, 2024
@DavidBadura DavidBadura added the enhancement New feature or request label Oct 6, 2024
Copy link

github-actions bot commented Oct 6, 2024

Hello 👋

here is the most recent benchmark result:

SubscriptionEngineBench
=======================

+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                               | memory                                     |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>  | Tag: base       | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 3.105s (±0.00%) | 3.094s (±0.00%) | +0.34%    | 46.883mb        | 34.743mb   | +34.94%     |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+

SubscriptionEngineBatchBench
============================

+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                                   | memory                                     |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>    | Tag: base         | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 73.573ms (±0.00%) | 72.200ms (±0.00%) | +1.90%    | 34.234mb        | 34.234mb   | 0.00%       |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+

SimpleSetupStreamStoreBench
===========================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 886.200μs (±0.00%) | 933.300μs (±0.00%) | -5.05%    | 34.744mb        | 34.744mb   | 0.00%       |
| benchLoad10000Events ()                | 46.285ms (±0.00%)  | 47.781ms (±0.00%)  | -3.13%    | 34.745mb        | 34.745mb   | 0.00%       |
| benchSave1Event ()                     | 1.008ms (±0.00%)   | 1.072ms (±0.00%)   | -5.95%    | 34.744mb        | 34.744mb   | 0.00%       |
| benchSave10000Events ()                | 205.293ms (±0.00%) | 223.916ms (±0.00%) | -8.32%    | 34.745mb        | 34.745mb   | 0.00%       |
| benchSave10000Aggregates ()            | 8.337s (±0.00%)    | 8.202s (±0.00%)    | +1.64%    | 34.745mb        | 34.745mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 4.741s (±0.00%)    | 4.749s (±0.00%)    | -0.15%    | 34.745mb        | 34.745mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SnapshotsBench
==============

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad10000EventsMissingSnapshot () | 49.414ms (±0.00%)  | 48.507ms (±0.00%)  | +1.87%    | 33.836mb        | 33.836mb   | 0.00%       |
| benchLoad10000Events ()                | 929.600μs (±0.00%) | 925.100μs (±0.00%) | +0.49%    | 33.836mb        | 33.836mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SplitStreamBench
================

+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                         | time (kde mode)                                     | memory                                     |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                 | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad10000Events () | 4.392ms (±0.00%)   | 4.324ms (±0.00%)   | +1.58%    | 37.072mb        | 37.072mb   | 0.00%       |
| benchSave10000Events () | 341.855ms (±0.00%) | 344.850ms (±0.00%) | -0.87%    | 37.144mb        | 37.145mb   | -0.00%      |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

PersonalDataBench
=================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 900.100μs (±0.00%) | 884.900μs (±0.00%) | +1.72%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchLoad10000Events ()                | 83.835ms (±0.00%)  | 83.836ms (±0.00%)  | -0.00%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchSave1Event ()                     | 1.542ms (±0.00%)   | 1.534ms (±0.00%)   | +0.51%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchSave10000Events ()                | 244.899ms (±0.00%) | 246.327ms (±0.00%) | -0.58%    | 34.897mb        | 34.897mb   | 0.00%       |
| benchSave10000Aggregates ()            | 12.413s (±0.00%)   | 12.366s (±0.00%)   | +0.38%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 8.858s (±0.00%)    | 8.816s (±0.00%)    | +0.47%    | 35.396mb        | 35.396mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SimpleSetupBench
================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 907.300μs (±0.00%) | 946.800μs (±0.00%) | -4.17%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchLoad10000Events ()                | 48.961ms (±0.00%)  | 50.245ms (±0.00%)  | -2.56%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave1Event ()                     | 1.060ms (±0.00%)   | 1.195ms (±0.00%)   | -11.25%   | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave10000Events ()                | 216.473ms (±0.00%) | 212.112ms (±0.00%) | +2.06%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave10000Aggregates ()            | 8.323s (±0.00%)    | 8.364s (±0.00%)    | -0.49%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 4.774s (±0.00%)    | 4.765s (±0.00%)    | +0.18%    | 33.765mb        | 33.765mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

This comment gets update everytime a new commit comes in!

@DavidBadura DavidBadura force-pushed the subscription-engine-filter-events branch from 113cd50 to 95c56c8 Compare October 6, 2024 08:34
Copy link
Member

@DanielBadura DanielBadura left a comment

Choose a reason for hiding this comment

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

Maybe we should also add a NOT IN event filter?

@DavidBadura
Copy link
Member Author

For which use case 🤔

@DanielBadura
Copy link
Member

Maybe for testing purposes, like checking what happens if an event will be dropped. It just came in my mind - nothing we need right away

@DavidBadura DavidBadura force-pushed the subscription-engine-filter-events branch from 4ed8b77 to bae4966 Compare October 15, 2024 11:36
@DavidBadura DavidBadura removed this from the 3.5.0 milestone Oct 16, 2024
@DavidBadura DavidBadura force-pushed the subscription-engine-filter-events branch from bae4966 to f3b413f Compare December 5, 2024 15:26
@DavidBadura DavidBadura changed the base branch from 3.5.x to 3.6.x December 5, 2024 15:26
@DavidBadura DavidBadura force-pushed the subscription-engine-filter-events branch from b2a83be to 96b8640 Compare December 8, 2024 11:59
@DavidBadura DavidBadura force-pushed the subscription-engine-filter-events branch from 4a76066 to ba4958e Compare December 12, 2024 11:54
@DavidBadura DavidBadura added this to the 3.6.0 milestone Dec 12, 2024
@DavidBadura DavidBadura force-pushed the subscription-engine-filter-events branch from 8b91a43 to be1020b Compare December 12, 2024 19:43
@DavidBadura DavidBadura merged commit 91dabc1 into 3.6.x Dec 12, 2024
39 of 40 checks passed
@DavidBadura DavidBadura deleted the subscription-engine-filter-events branch December 12, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants