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

POC: command bus #644

Draft
wants to merge 4 commits into
base: 3.6.x
Choose a base branch
from
Draft

POC: command bus #644

wants to merge 4 commits into from

Conversation

DavidBadura
Copy link
Member

@DavidBadura DavidBadura commented Nov 8, 2024

use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot;
use Patchlevel\EventSourcing\Attribute\Aggregate;
use Patchlevel\EventSourcing\Attribute\Apply;
use Patchlevel\EventSourcing\Attribute\Handle;
use Patchlevel\EventSourcing\Attribute\Id;

#[Aggregate('profile')]
final class Profile extends BasicAggregateRoot
{
    #[Id]
    private ProfileId $id;
    private string $name;

    #[Handle]
    public static function create(CreateProfile $command): self
    {
        $self = new self();
        $self->recordThat(new ProfileCreated($command->id, $command->name));

        return $self;
    }

    #[Handle]
    public function changeName(ChangeProfileName $command): void
    {
        $this->recordThat(new NameChanged($command->name));
    }

    #[Apply]
    protected function applyProfileCreated(ProfileCreated $event): void
    {
        $this->id = $event->profileId;
        $this->name = $event->name;
    }

    #[Apply]
    protected function applyNameChanged(NameChanged $event): void
    {
        $this->name = $event->name;
    }

    public function name(): string
    {
        return $this->name;
    }
}
use Patchlevel\EventSourcing\Attribute\HandledBy;

#[HandledBy(Profile::class)]
final class CreateProfile
{
    public function __construct(
        public readonly ProfileId $id,
        public readonly string $name,
    ) {
    }
}
use Patchlevel\EventSourcing\Attribute\HandledBy;
use Patchlevel\EventSourcing\Attribute\Id;

#[HandledBy(Profile::class)]
final class ChangeProfileName
{
    public function __construct(
        #[Id]
        public readonly ProfileId $id,
        public readonly string $name,
    ) {
    }
}
use Patchlevel\EventSourcing\CommandBus\DefaultCommandBus;

$commandBus = DefaultCommandBus::createDefault($repositoryManager);

$commandBus->dispatch(new CreateProfile($profileId, 'John'));
$commandBus->dispatch(new ChangeProfileName($profileId, 'John Doe'));

@DavidBadura DavidBadura added the enhancement New feature or request label Nov 8, 2024
Copy link

github-actions bot commented Nov 8, 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.065s (±0.00%) | 3.073s (±0.00%) | -0.24%    | 34.734mb        | 34.742mb   | -0.02%      |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+

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

+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                                   | memory                                     |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>    | Tag: base         | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 69.131ms (±0.00%) | 69.513ms (±0.00%) | -0.55%    | 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 ()                     | 919.300μs (±0.00%) | 921.500μs (±0.00%) | -0.24%    | 34.744mb        | 34.744mb   | 0.00%       |
| benchLoad10000Events ()                | 48.256ms (±0.00%)  | 48.995ms (±0.00%)  | -1.51%    | 34.744mb        | 34.744mb   | 0.00%       |
| benchSave1Event ()                     | 970.100μs (±0.00%) | 1.035ms (±0.00%)   | -6.25%    | 34.744mb        | 34.744mb   | 0.00%       |
| benchSave10000Events ()                | 209.193ms (±0.00%) | 220.218ms (±0.00%) | -5.01%    | 34.744mb        | 34.744mb   | 0.00%       |
| benchSave10000Aggregates ()            | 8.194s (±0.00%)    | 8.385s (±0.00%)    | -2.27%    | 34.744mb        | 34.744mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 4.733s (±0.00%)    | 4.715s (±0.00%)    | +0.40%    | 34.744mb        | 34.744mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

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

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad10000EventsMissingSnapshot () | 48.774ms (±0.00%)  | 48.698ms (±0.00%)  | +0.16%    | 33.836mb        | 33.836mb   | 0.00%       |
| benchLoad10000Events ()                | 912.200μs (±0.00%) | 916.600μs (±0.00%) | -0.48%    | 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.428ms (±0.00%)   | 4.314ms (±0.00%)   | +2.65%    | 37.072mb        | 37.072mb   | 0.00%       |
| benchSave10000Events () | 338.920ms (±0.00%) | 346.838ms (±0.00%) | -2.28%    | 37.144mb        | 37.144mb   | -0.00%      |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

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

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 923.800μs (±0.00%) | 886.400μs (±0.00%) | +4.22%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchLoad10000Events ()                | 82.570ms (±0.00%)  | 82.636ms (±0.00%)  | -0.08%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchSave1Event ()                     | 1.514ms (±0.00%)   | 1.584ms (±0.00%)   | -4.43%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchSave10000Events ()                | 241.774ms (±0.00%) | 242.346ms (±0.00%) | -0.24%    | 34.897mb        | 34.897mb   | 0.00%       |
| benchSave10000Aggregates ()            | 12.337s (±0.00%)   | 12.590s (±0.00%)   | -2.01%    | 34.895mb        | 34.895mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 8.818s (±0.00%)    | 8.802s (±0.00%)    | +0.18%    | 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 ()                     | 939.900μs (±0.00%) | 948.200μs (±0.00%) | -0.88%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchLoad10000Events ()                | 49.451ms (±0.00%)  | 48.159ms (±0.00%)  | +2.68%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave1Event ()                     | 986.000μs (±0.00%) | 1.035ms (±0.00%)   | -4.74%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave10000Events ()                | 218.974ms (±0.00%) | 217.176ms (±0.00%) | +0.83%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave10000Aggregates ()            | 8.379s (±0.00%)    | 8.161s (±0.00%)    | +2.68%    | 33.765mb        | 33.765mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 4.748s (±0.00%)    | 4.730s (±0.00%)    | +0.37%    | 33.765mb        | 33.765mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

This comment gets update everytime a new commit comes in!

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.

1 participant