Skip to content
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
36 changes: 36 additions & 0 deletions tests/Benchmark/BasicImplementation/Projection/NoopProjector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection;

use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Attribute\Setup;
use Patchlevel\EventSourcing\Attribute\Subscribe;
use Patchlevel\EventSourcing\Attribute\Teardown;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\NameChanged;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\ProfileCreated;

#[Projector('noop_profile')]
final class NoopProjector
{
#[Setup]
public function create(): void
{
}

#[Teardown]
public function drop(): void
{
}

#[Subscribe(ProfileCreated::class)]
public function onProfileCreated(ProfileCreated $profileCreated): void
{
}

#[Subscribe(NameChanged::class)]
public function onNameChanged(NameChanged $nameChanged): void
{
}
}
96 changes: 96 additions & 0 deletions tests/Benchmark/NoopSubscriptionEngineBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Tests\Benchmark;

use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Schema\ChainDoctrineSchemaConfigurator;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\EventFilteredStoreMessageLoader;
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\ThrowOnErrorSubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Profile;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection\NoopProjector;
use Patchlevel\EventSourcing\Tests\DbalManager;
use PhpBench\Attributes as Bench;

#[Bench\BeforeMethods('setUp')]
final class NoopSubscriptionEngineBench
{
private Store $store;
private Repository $repository;

private SubscriptionEngine $subscriptionEngine;

private AggregateRootId $id;

public function setUp(): void
{
$connection = DbalManager::createConnection();

$this->store = new DoctrineDbalStore(
$connection,
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
);

$this->repository = new DefaultRepository($this->store, Profile::metadata());

$subscriptionStore = new DoctrineSubscriptionStore($connection);

$schemaDirector = new DoctrineSchemaDirector(
$connection,
new ChainDoctrineSchemaConfigurator([
$this->store,
$subscriptionStore,
]),
);

$schemaDirector->create();

$this->id = ProfileId::generate();

$profile = Profile::create($this->id, 'Peter');

for ($i = 1; $i <= 10_000; $i++) {
$profile->changeEmail('peter' . $i . '@example.com');
$profile->changeName('Peter ' . $i);
}

$this->repository->save($profile);

$subscriberAccessorRepository = new MetadataSubscriberAccessorRepository(
[
new NoopProjector(),
],
);

$this->subscriptionEngine = new ThrowOnErrorSubscriptionEngine(new DefaultSubscriptionEngine(
new EventFilteredStoreMessageLoader(
$this->store,
new AttributeEventMetadataFactory(),
$subscriberAccessorRepository,
),
$subscriptionStore,
$subscriberAccessorRepository,
));
}

#[Bench\Revs(10)]
public function benchHandle10000Events(): void
{
$this->subscriptionEngine->setup();
$this->subscriptionEngine->boot();
$this->subscriptionEngine->remove();
}
}
11 changes: 5 additions & 6 deletions tests/Benchmark/SubscriptionEngineBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\EventFilteredStoreMessageLoader;
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\ThrowOnErrorSubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Processor\SendEmailProcessor;
Expand Down Expand Up @@ -46,9 +47,7 @@ public function setUp(): void

$this->repository = new DefaultRepository($this->store, Profile::metadata());

$subscriptionStore = new DoctrineSubscriptionStore(
$connection,
);
$subscriptionStore = new DoctrineSubscriptionStore($connection);

$schemaDirector = new DoctrineSchemaDirector(
$connection,
Expand All @@ -64,7 +63,7 @@ public function setUp(): void

$profile = Profile::create($this->id, 'Peter');

for ($i = 1; $i < 10_000; $i++) {
for ($i = 1; $i <= 10_000; $i++) {
$profile->changeEmail('peter' . $i . '@example.com');
$profile->changeName('Peter ' . $i);
}
Expand All @@ -78,15 +77,15 @@ public function setUp(): void
],
);

$this->subscriptionEngine = new DefaultSubscriptionEngine(
$this->subscriptionEngine = new ThrowOnErrorSubscriptionEngine(new DefaultSubscriptionEngine(
new EventFilteredStoreMessageLoader(
$this->store,
new AttributeEventMetadataFactory(),
$subscriberAccessorRepository,
),
$subscriptionStore,
$subscriberAccessorRepository,
);
));
}

#[Bench\Revs(10)]
Expand Down
Loading