Skip to content

Commit

Permalink
add php benchmarks (#131)
Browse files Browse the repository at this point in the history
* add php benchmarks

* fixes

* fixes

* fixes

* fixes

* fixes
  • Loading branch information
dgafka authored May 30, 2023
1 parent 9c67107 commit ea1482c
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/split-testing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Ecotone Framework'
name: 'Tests'

on:
pull_request:
Expand All @@ -10,7 +10,7 @@ on:

jobs:
get_packages:
name: Package testing
name: Get packages
runs-on: ubuntu-latest

steps:
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/test-monorepo.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Ecotone Framework'
name: 'Tests'

on:
pull_request:
Expand All @@ -10,7 +10,7 @@ on:

jobs:
run:
name: "Testing Monorepo"
name: "Monorepo"
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
Expand Down Expand Up @@ -118,3 +118,11 @@ jobs:
APP_DB_HOST: 127.0.0.1
APP_DB_PORT: 3306
APP_DB_DRIVER: pdo_mysql

- name: Benchmarks
run: composer tests:phpbench
env:
DATABASE_DSN: pgsql://ecotone:secret@127.0.0.1:5432/ecotone
APP_DB_HOST: 127.0.0.1
APP_DB_PORT: 5432
APP_DB_DRIVER: pdo_pgsql
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
"aws/aws-sdk-php": "<=3.269.5",
"symfony/messenger": "^5.4|^6.0",
"symfony/doctrine-messenger": "^5.4|^6.0",
"doctrine/doctrine-bundle": "^2.9"
"doctrine/doctrine-bundle": "^2.9",
"phpbench/phpbench": "^1.2"
},
"extra": {
"laravel": {
Expand Down Expand Up @@ -174,6 +175,11 @@
"@tests:phpstan",
"@tests:phpunit",
"@tests:behat"
],
"tests:phpbench": [
"(cd packages/Ecotone && composer update --prefer-stable --prefer-dist --no-interaction && composer tests:phpbench)",
"(cd packages/Laravel && composer update --prefer-stable --prefer-dist --no-interaction && composer tests:phpbench)",
"(cd packages/Symfony && composer update --prefer-stable --prefer-dist --no-interaction && composer tests:phpbench)"
]
},
"config": {
Expand Down
6 changes: 5 additions & 1 deletion packages/Ecotone/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"phpunit/phpunit": "^9.5",
"behat/behat": "^3.10",
"phpstan/phpstan": "^1.8",
"symfony/expression-language": "^6.0"
"symfony/expression-language": "^6.0",
"phpbench/phpbench": "^1.2"
},
"scripts": {
"tests:phpstan": "vendor/bin/phpstan",
Expand All @@ -54,6 +55,9 @@
"tests:behat": [
"vendor/bin/behat -vvv"
],
"tests:phpbench": [
"vendor/bin/phpbench run tests/Benchmark --bootstrap=./vendor/autoload.php"
],
"tests:ci": [
"@tests:phpstan",
"@tests:phpunit",
Expand Down
82 changes: 82 additions & 0 deletions packages/Ecotone/tests/Benchmark/EcotoneBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Test\Ecotone\Benchmark;

use Ecotone\Lite\EcotoneLite;
use Ecotone\Messaging\Config\ModulePackageList;
use Ecotone\Messaging\Config\ServiceConfiguration;
use PHPUnit\Framework\TestCase;
use Test\Ecotone\Modelling\Fixture\CommandEventFlow\CreateMerchant;
use Test\Ecotone\Modelling\Fixture\CommandEventFlow\Merchant;
use Test\Ecotone\Modelling\Fixture\CommandEventFlow\MerchantSubscriber;
use Test\Ecotone\Modelling\Fixture\CommandEventFlow\User;
use Test\Ecotone\Modelling\Fixture\CommandHandler\Aggregate\InMemoryStandardRepository;

class EcotoneBenchmark extends TestCase
{
/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_running_ecotone_lite()
{
$this->execute(
ServiceConfiguration::createWithDefaults()
->withFailFast(false)
->withSkippedModulePackageNames(ModulePackageList::allPackages()),
false
);
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_running_ecotone_lite_with_fail_fast()
{
$this->execute(
ServiceConfiguration::createWithDefaults()
->withFailFast(true)
->withSkippedModulePackageNames(ModulePackageList::allPackages()),
false
);
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_running_ecotone_lite_with_cache()
{
$this->execute(
ServiceConfiguration::createWithDefaults()
->withFailFast(false)
->withCacheDirectoryPath(sys_get_temp_dir())
->withSkippedModulePackageNames(ModulePackageList::allPackages()),
true
);
}

private function execute(ServiceConfiguration $serviceConfiguration, bool $useCachedVersion): void
{
$ecotoneApplication = EcotoneLite::bootstrap(
[Merchant::class, User::class, MerchantSubscriber::class, InMemoryStandardRepository::class],
[
new MerchantSubscriber(), InMemoryStandardRepository::createEmpty()
],
$serviceConfiguration,
useCachedVersion: $useCachedVersion,
allowGatewaysToBeRegisteredInContainer: true
);

$merchantId = '123';
$ecotoneApplication->getCommandBus()->send(new CreateMerchant($merchantId));

$this->assertTrue(
$ecotoneApplication->getQueryBus()->sendWithRouting('user.get', metadata: ['aggregate.id' => $merchantId])
);
}
}
6 changes: 5 additions & 1 deletion packages/Laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"phpstan/phpstan": "^1.8",
"orchestra/testbench": "^7.6",
"wikimedia/composer-merge-plugin": "^2.0",
"symfony/expression-language": "^6.0"
"symfony/expression-language": "^6.0",
"phpbench/phpbench": "^1.2"
},
"extra": {
"laravel": {
Expand All @@ -68,6 +69,9 @@
"tests:phpunit": [
"vendor/bin/phpunit"
],
"tests:phpbench": [
"vendor/bin/phpbench run tests/Application/Benchmark --bootstrap=./vendor/autoload.php"
],
"tests:ci": [
"@tests:phpstan",
"@tests:phpunit"
Expand Down
2 changes: 1 addition & 1 deletion packages/Laravel/src/EcotoneProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function register()

$environment = App::environment();
$rootCatalog = App::basePath();
$isCachingConfiguration = $environment === 'prod' ? true : Config::get('ecotone.cacheConfiguration');
$isCachingConfiguration = in_array($environment, ['prod', 'production']) ? true : Config::get('ecotone.cacheConfiguration');
$cacheDirectory = App::storagePath() . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'ecotone';

if (! is_dir($cacheDirectory)) {
Expand Down
67 changes: 67 additions & 0 deletions packages/Laravel/tests/Application/Benchmark/EcotoneBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Test\Ecotone\Laravel\Application\Benchmark;

use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Http\Kernel;
use PHPUnit\Framework\TestCase;

class
EcotoneBenchmark extends TestCase
{
/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_kernel_boot_on_prod()
{
putenv("APP_ENV=production");
$this->createApplication();
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_kernel_boot_on_dev()
{
putenv('APP_ENV=development');
$this->createApplication();
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_messaging_boot_on_prod()
{
putenv('APP_ENV=production');
$app = $this->createApplication();
$app->make(ConfiguredMessagingSystem::class);
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_messaging_boot_on_dev()
{
putenv('APP_ENV=development');
$app = $this->createApplication();
$app->make(ConfiguredMessagingSystem::class);
}

public function createApplication(): Application
{
$app = require __DIR__ . '/../bootstrap/app.php';

$app->make(Kernel::class)->bootstrap();

return $app;
}
}
55 changes: 55 additions & 0 deletions packages/Symfony/tests/Benchmark/EcotoneBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Benchmark;

use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use Ecotone\SymfonyBundle\App\Kernel;

class EcotoneBenchmark
{
/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_kernel_boot_on_prod()
{
$kernel = new Kernel('prod', false);
$kernel->boot();
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_kernel_boot_on_dev()
{
$kernel = new Kernel('dev', false);
$kernel->boot();
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_messaging_boot_on_prod()
{
$kernel = new Kernel('prod', false);
$kernel->boot();
$kernel->getContainer()->get(ConfiguredMessagingSystem::class);
}

/**
* @Revs(10)
* @Iterations(5)
* @Warmup(1)
*/
public function bench_messaging_boot_on_dev()
{
$kernel = new Kernel('dev', false);
$kernel->boot();
$kernel->getContainer()->get(ConfiguredMessagingSystem::class);
}
}
32 changes: 0 additions & 32 deletions packages/Symfony/tests/Benchmark/KernelBootBench.php

This file was deleted.

0 comments on commit ea1482c

Please sign in to comment.