Skip to content

Commit

Permalink
Merge pull request #518 from patchlevel/use-postgres-in-benchmarks
Browse files Browse the repository at this point in the history
use postgres in benchmarks
  • Loading branch information
DavidBadura authored Mar 3, 2024
2 parents 569fcc1 + 0217853 commit f10a683
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 80 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ jobs:

runs-on: ${{ matrix.operating-system }}

services:
postgres:
# Docker Hub image
image: "postgres:16.1"
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: eventstore
options: >-
--health-cmd "pg_isready"
ports:
- "5432:5432"

strategy:
matrix:
dependencies:
Expand All @@ -20,6 +33,9 @@ jobs:
operating-system:
- "ubuntu-latest"

env:
DB_URL: 'pdo-pgsql://postgres:postgres@localhost:5432/eventstore?charset=utf8'

steps:
- name: "Install PHP"
uses: "shivammathur/[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ test: phpunit

.PHONY: benchmark
benchmark: vendor ## run benchmarks
vendor/bin/phpbench run tests/Benchmark --report=default
DB_URL=sqlite3:///:memory: vendor/bin/phpbench run tests/Benchmark --report=default

.PHONY: benchmark-diff-test
benchmark-diff-test: vendor ## run benchmarks
benchmark-diff-test: vendor ## run benchmarks
vendor/bin/phpbench run tests/Benchmark --revs=1 --report=default --progress=none --tag=base
vendor/bin/phpbench run tests/Benchmark --revs=1 --report=diff --progress=none --ref=base

Expand Down
1 change: 0 additions & 1 deletion tests/Benchmark/BasicImplementation/data/.gitignore

This file was deleted.

19 changes: 3 additions & 16 deletions tests/Benchmark/ProjectionistBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Patchlevel\EventSourcing\Tests\Benchmark;

use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\DriverManager;
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
Expand All @@ -23,16 +21,12 @@
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Processor\SendEmailProcessor;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection\ProfileProjector;
use Patchlevel\EventSourcing\Tests\DbalManager;
use PhpBench\Attributes as Bench;

use function file_exists;
use function unlink;

#[Bench\BeforeMethods('setUp')]
final class ProjectionistBench
{
private const DB_PATH = __DIR__ . '/BasicImplementation/data/db.sqlite3';

private Store $store;
private EventBus $bus;
private Repository $repository;
Expand All @@ -43,14 +37,7 @@ final class ProjectionistBench

public function setUp(): void
{
if (file_exists(self::DB_PATH)) {
unlink(self::DB_PATH);
}

$connection = DriverManager::getConnection([
'driverClass' => Driver::class,
'path' => self::DB_PATH,
]);
$connection = DbalManager::createConnection();

$this->bus = DefaultEventBus::create();

Expand Down Expand Up @@ -96,7 +83,7 @@ public function setUp(): void
);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchHandle10000Events(): void
{
$this->projectionist->boot();
Expand Down
25 changes: 6 additions & 19 deletions tests/Benchmark/SimpleSetupBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Patchlevel\EventSourcing\Tests\Benchmark;

use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\DriverManager;
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
Expand All @@ -17,16 +15,12 @@
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId;
use Patchlevel\EventSourcing\Tests\DbalManager;
use PhpBench\Attributes as Bench;

use function file_exists;
use function unlink;

#[Bench\BeforeMethods('setUp')]
final class SimpleSetupBench
{
private const DB_PATH = __DIR__ . '/BasicImplementation/data/db.sqlite3';

private Store $store;
private EventBus $bus;
private Repository $repository;
Expand All @@ -35,14 +29,7 @@ final class SimpleSetupBench

public function setUp(): void
{
if (file_exists(self::DB_PATH)) {
unlink(self::DB_PATH);
}

$connection = DriverManager::getConnection([
'driverClass' => Driver::class,
'path' => self::DB_PATH,
]);
$connection = DbalManager::createConnection();

$this->bus = DefaultEventBus::create();

Expand Down Expand Up @@ -72,20 +59,20 @@ public function setUp(): void
$this->repository->save($profile);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchLoad10000Events(): void
{
$this->repository->load($this->id);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchSave1Event(): void
{
$profile = Profile::create(ProfileId::v7(), 'Peter');
$this->repository->save($profile);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchSave10000Events(): void
{
$profile = Profile::create(ProfileId::v7(), 'Peter');
Expand All @@ -106,7 +93,7 @@ public function benchSave10000Aggregates(): void
}
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchSave10000AggregatesTransaction(): void
{
$this->store->transactional(function (): void {
Expand Down
21 changes: 4 additions & 17 deletions tests/Benchmark/SnapshotsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Patchlevel\EventSourcing\Tests\Benchmark;

use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\DriverManager;
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
Expand All @@ -20,16 +18,12 @@
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId;
use Patchlevel\EventSourcing\Tests\DbalManager;
use PhpBench\Attributes as Bench;

use function file_exists;
use function unlink;

#[Bench\BeforeMethods('setUp')]
final class SnapshotsBench
{
private const DB_PATH = __DIR__ . '/BasicImplementation/data/db.sqlite3';

private Store $store;
private EventBus $bus;
private SnapshotStore $snapshotStore;
Expand All @@ -41,14 +35,7 @@ final class SnapshotsBench

public function setUp(): void
{
if (file_exists(self::DB_PATH)) {
unlink(self::DB_PATH);
}

$connection = DriverManager::getConnection([
'driverClass' => Driver::class,
'path' => self::DB_PATH,
]);
$connection = DbalManager::createConnection();

$this->bus = DefaultEventBus::create();

Expand Down Expand Up @@ -82,14 +69,14 @@ public function setUp(): void
$this->snapshotStore->save($profile);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchLoad10000EventsMissingSnapshot(): void
{
$this->adapter->clear();
$this->repository->load($this->id);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchLoad10000Events(): void
{
$this->repository->load($this->id);
Expand Down
22 changes: 4 additions & 18 deletions tests/Benchmark/SplitStreamBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Patchlevel\EventSourcing\Tests\Benchmark;

use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\DriverManager;
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
Expand All @@ -15,39 +13,27 @@
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
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 Patchlevel\EventSourcing\Tests\DbalManager;
use PhpBench\Attributes as Bench;

use function file_exists;
use function sprintf;
use function unlink;

#[Bench\BeforeMethods('setUp')]
final class SplitStreamBench
{
private const DB_PATH = __DIR__ . '/BasicImplementation/data/db.sqlite3';

private Store $store;
private EventBus $bus;
private SnapshotStore $snapshotStore;
private Repository $repository;

private AggregateRootId $id;

public function setUp(): void
{
if (file_exists(self::DB_PATH)) {
unlink(self::DB_PATH);
}

$connection = DriverManager::getConnection([
'driverClass' => Driver::class,
'path' => self::DB_PATH,
]);
$connection = DbalManager::createConnection();

$this->bus = DefaultEventBus::create();

Expand Down Expand Up @@ -94,14 +80,14 @@ public function provideData(): void
$this->repository->save($profile);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
#[Bench\BeforeMethods('provideData')]
public function benchLoad10000Events(): void
{
$this->repository->load($this->id);
}

#[Bench\Revs(20)]
#[Bench\Revs(10)]
public function benchSave10000Events(): void
{
$profile = Profile::create(ProfileId::v7(), 'Peter');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Tests\Integration;
namespace Patchlevel\EventSourcing\Tests;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\AbstractSQLiteDriver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\BankAccountSplitStream\Aggregate\BankAccount;
use Patchlevel\EventSourcing\Tests\Integration\BankAccountSplitStream\Events\BalanceAdded;
use Patchlevel\EventSourcing\Tests\Integration\BankAccountSplitStream\Events\BankAccountCreated;
use Patchlevel\EventSourcing\Tests\Integration\BankAccountSplitStream\Events\MonthPassed;
use Patchlevel\EventSourcing\Tests\Integration\BankAccountSplitStream\Projection\BankAccountProjector;
use Patchlevel\EventSourcing\Tests\Integration\DbalManager;
use PHPUnit\Framework\TestCase;

use function count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
use Patchlevel\EventSourcing\Snapshot\Adapter\InMemorySnapshotAdapter;
use Patchlevel\EventSourcing\Snapshot\DefaultSnapshotStore;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\MessageDecorator\FooMessageDecorator;
use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Processor\SendEmailProcessor;
use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Projection\ProfileProjector;
use Patchlevel\EventSourcing\Tests\Integration\DbalManager;
use PHPUnit\Framework\TestCase;

/** @coversNothing */
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Outbox/OutboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Tests\Integration\DbalManager;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\Outbox\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Integration\Outbox\Events\ProfileCreated;
use Patchlevel\EventSourcing\Tests\Integration\Outbox\Processor\SendEmailProcessor;
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Pipeline/PipelineChangeStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Tests\Integration\DbalManager;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\Pipeline\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Integration\Pipeline\Events\NewVisited;
use Patchlevel\EventSourcing\Tests\Integration\Pipeline\Events\OldVisited;
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Projectionist/ProjectionistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Tests\Integration\DbalManager;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Projection\ErrorProducerProjector;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Projection\ProfileProjector;
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Store/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Tests\Integration\DbalManager;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\Store\Events\ProfileCreated;
use PHPUnit\Framework\TestCase;

Expand Down

0 comments on commit f10a683

Please sign in to comment.