-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5fcee7
commit 9979b80
Showing
5 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events; | ||
|
||
use Patchlevel\EventSourcing\Attribute\Event; | ||
use Patchlevel\EventSourcing\Attribute\SplitStream; | ||
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Normalizer\ProfileIdNormalizer; | ||
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId; | ||
|
||
#[Event('profile.reborn')] | ||
#[SplitStream] | ||
final class Reborn | ||
{ | ||
public function __construct( | ||
#[ProfileIdNormalizer] | ||
public ProfileId $profileId, | ||
public string $name, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Benchmark; | ||
|
||
use Doctrine\DBAL\Driver\PDO\SQLite\Driver; | ||
use Doctrine\DBAL\DriverManager; | ||
use Patchlevel\EventSourcing\EventBus\Decorator\SplitStreamDecorator; | ||
use Patchlevel\EventSourcing\EventBus\DefaultEventBus; | ||
use Patchlevel\EventSourcing\EventBus\EventBus; | ||
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; | ||
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory; | ||
use Patchlevel\EventSourcing\Repository\DefaultRepository; | ||
use Patchlevel\EventSourcing\Repository\Repository; | ||
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector; | ||
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer; | ||
use Patchlevel\EventSourcing\Snapshot\Adapter\InMemorySnapshotAdapter; | ||
use Patchlevel\EventSourcing\Snapshot\DefaultSnapshotStore; | ||
use Patchlevel\EventSourcing\Snapshot\SnapshotStore; | ||
use Patchlevel\EventSourcing\Store\DoctrineDbalStore; | ||
use Patchlevel\EventSourcing\Store\Store; | ||
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Aggregate\Profile; | ||
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId; | ||
use PhpBench\Attributes as Bench; | ||
|
||
use function file_exists; | ||
use function unlink; | ||
|
||
#[Bench\BeforeMethods('setUp')] | ||
final class SplitStreamBench | ||
{ | ||
private const DB_PATH = __DIR__ . '/BasicImplementation/data/db.sqlite3'; | ||
|
||
private Store $store; | ||
Check failure on line 35 in tests/Benchmark/SplitStreamBench.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MissingConstructor
|
||
private EventBus $bus; | ||
Check failure on line 36 in tests/Benchmark/SplitStreamBench.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MissingConstructor
|
||
private SnapshotStore $snapshotStore; | ||
Check failure on line 37 in tests/Benchmark/SplitStreamBench.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MissingConstructor
|
||
private Repository $repository; | ||
Check failure on line 38 in tests/Benchmark/SplitStreamBench.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MissingConstructor
|
||
|
||
public function setUp(): void | ||
{ | ||
if (file_exists(self::DB_PATH)) { | ||
unlink(self::DB_PATH); | ||
} | ||
|
||
$connection = DriverManager::getConnection([ | ||
'driverClass' => Driver::class, | ||
'path' => self::DB_PATH, | ||
]); | ||
|
||
$this->bus = new DefaultEventBus(); | ||
|
||
$this->store = new DoctrineDbalStore( | ||
$connection, | ||
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']), | ||
(new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']), | ||
'eventstore', | ||
); | ||
|
||
$this->repository = new DefaultRepository( | ||
$this->store, | ||
$this->bus, | ||
Profile::metadata(), | ||
null, | ||
new SplitStreamDecorator( | ||
new AttributeEventMetadataFactory() | ||
) | ||
); | ||
|
||
$schemaDirector = new DoctrineSchemaDirector( | ||
$connection, | ||
$this->store, | ||
); | ||
|
||
$schemaDirector->create(); | ||
} | ||
|
||
public function provideData(): void | ||
{ | ||
$profile = Profile::create(ProfileId::fromString('1'), 'Peter'); | ||
|
||
for ($i = 0; $i < 10_000; $i++) { | ||
$profile->changeName(sprintf('Peter %d', $i)); | ||
|
||
if ($i % 100 === 0) { | ||
$profile->reborn(); | ||
} | ||
} | ||
|
||
$this->repository->save($profile); | ||
} | ||
|
||
#[Bench\Revs(20)] | ||
#[Bench\BeforeMethods("provideData")] | ||
public function benchLoad10000Events(): void | ||
{ | ||
$this->repository->load('1'); | ||
} | ||
|
||
#[Bench\Revs(20)] | ||
public function benchWrite10000Events(): void | ||
{ | ||
$profile = Profile::create(ProfileId::fromString('1'), 'Peter'); | ||
|
||
for ($i = 0; $i < 10_000; $i++) { | ||
$profile->changeName(sprintf('Peter %d', $i)); | ||
|
||
if ($i % 100 === 0) { | ||
$profile->reborn(); | ||
} | ||
} | ||
|
||
$this->repository->save($profile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters