Skip to content

Commit

Permalink
Fullapp benchmark (#144)
Browse files Browse the repository at this point in the history
* ci: fix phpbench baseline on main

* add example app to run benchmarks on for Lite/Symfony/Laravel

* ci: remove cached files between benchmarks

* refactor benchmarks

* add PlaceOrderWithoutEcotoneBenchmark

* clean ExampleApp

* ci: remove opcache benchmark

* skip without ecotone benchmark

---------

Co-authored-by: jlabedo <jean@needelp.com>
  • Loading branch information
jlabedo and jlabedo authored Jun 9, 2023
1 parent 35280d2 commit 39ceb03
Show file tree
Hide file tree
Showing 73 changed files with 2,080 additions and 181 deletions.
34 changes: 15 additions & 19 deletions .github/workflows/benchmark-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,28 @@ jobs:
id: baseline
continue-on-error: true
run: |
vendor/bin/phpbench --profile=opcache_enabled --retry-threshold=5 --tag=main.opcache_enabled
vendor/bin/phpbench --profile=opcache_disabled --retry-threshold=5 --tag=main.opcache_disabled
vendor/bin/phpbench run --retry-threshold=5 --tag=main --report=github-report
- uses: actions/checkout@v3
with:
clean: false

- name: Remove cached files
working-directory:
run: |
rm -rf Monorepo/ExampleApp/Lite/var/cache
rm -rf Monorepo/ExampleApp/Symfony/var/cache
rm -rf Monorepo/ExampleApp/Laravel/framework/cache
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Benchmark PR with opcache enabled
id: opcache_enabled
env:
PHPBENCH_REF_OPTION: "${{ steps.baseline.outcome == 'success' && '--ref=main.opcache_enabled' || '' }}"
run: |
vendor/bin/phpbench run --profile=opcache_enabled --retry-threshold=5 --report=github-report $PHPBENCH_REF_OPTION | bin/phpbench-to-md.sh > opcache_enabled.md
cat opcache_enabled.md
echo '## Opcache enabled' >> "$GITHUB_STEP_SUMMARY"
cat opcache_enabled.md >> "$GITHUB_STEP_SUMMARY"
- name: Benchmark PR with opcache disabled
id: opcache_disabled
- name: Benchmark PR
env:
PHPBENCH_REF_OPTION: "${{ steps.baseline.outcome == 'success' && '--ref=main.opcache_disabled' || '' }}"
PHPBENCH_REF_OPTION: "${{ steps.baseline.outcome == 'success' && '--ref=main' || '' }}"
run: |
vendor/bin/phpbench run --profile=opcache_disabled --retry-threshold=5 --report=github-report $PHPBENCH_REF_OPTION | bin/phpbench-to-md.sh > opcache_disabled.md
cat opcache_disabled.md
echo '## Opcache disabled' >> "$GITHUB_STEP_SUMMARY"
cat opcache_disabled.md >> "$GITHUB_STEP_SUMMARY"
echo "Baseline: $PHPBENCH_REF_OPTION"
vendor/bin/phpbench run --retry-threshold=5 --report=github-report $PHPBENCH_REF_OPTION | bin/phpbench-to-md.sh > benchmark.md
cat benchmark.md
echo '## Benchmark' >> "$GITHUB_STEP_SUMMARY"
cat benchmark.md >> "$GITHUB_STEP_SUMMARY"
72 changes: 0 additions & 72 deletions Monorepo/Benchmark/EcotoneBenchmark.php

This file was deleted.

72 changes: 72 additions & 0 deletions Monorepo/Benchmark/FullAppBenchmarkCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Monorepo\Benchmark;

use Monorepo\ExampleApp\Symfony\Kernel;
use Psr\Container\ContainerInterface;

abstract class FullAppBenchmarkCase
{
public function bench_symfony_prod()
{
\putenv('APP_ENV=prod');
$kernel = new Kernel('prod', false);
$kernel->boot();
$container = $kernel->getContainer();

$this->execute($container);

$kernel->shutdown();
}

public function bench_symfony_dev()
{
\putenv('APP_ENV=dev');
$kernel = new Kernel('dev', true);
$kernel->boot();
$container = $kernel->getContainer();

$this->execute($container);

$kernel->shutdown();
}

public function bench_laravel_prod(): void
{
\putenv('APP_ENV=production');
$app = $this->createLaravelApplication();
$this->execute($app);
}

public function bench_laravel_dev(): void
{
\putenv('APP_ENV=development');
$app = $this->createLaravelApplication();
$this->execute($app);
}

public function bench_lite_prod()
{
$bootstrap = require __DIR__ . "/../ExampleApp/Lite/app.php";
$messagingSystem = $bootstrap(true);
$this->execute(new LiteContainerAccessor($messagingSystem));
}

public function bench_lite_dev()
{
$bootstrap = require __DIR__ . "/../ExampleApp/Lite/app.php";
$messagingSystem = $bootstrap(false);
$this->execute(new LiteContainerAccessor($messagingSystem));
}

private function createLaravelApplication()
{
$app = require __DIR__ . '/../ExampleApp/Laravel/bootstrap/app.php';

$app->make(\Illuminate\Foundation\Http\Kernel::class)->bootstrap();

return $app;
}

protected abstract function execute(ContainerInterface $container): void;
}
17 changes: 17 additions & 0 deletions Monorepo/Benchmark/KernelBootBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Monorepo\Benchmark;

use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;
use PhpBench\Attributes\Warmup;
use Psr\Container\ContainerInterface;

#[Warmup(1), Revs(10), Iterations(5)]
class KernelBootBenchmark extends FullAppBenchmarkCase
{
protected function execute(ContainerInterface $container): void
{
// do nothing
}
}
50 changes: 0 additions & 50 deletions Monorepo/Benchmark/LaravelBenchmark.php

This file was deleted.

23 changes: 23 additions & 0 deletions Monorepo/Benchmark/LiteContainerAccessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Monorepo\Benchmark;

use Ecotone\Messaging\Config\MessagingSystem;
use Psr\Container\ContainerInterface;

class LiteContainerAccessor implements ContainerInterface
{
public function __construct(private MessagingSystem $messagingSystem)
{
}

public function get(string $id)
{
return $this->messagingSystem->getServiceFromContainer($id);
}

public function has(string $id): bool
{
throw new \Exception("Not implemented");
}
}
18 changes: 18 additions & 0 deletions Monorepo/Benchmark/MessagingBootBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Monorepo\Benchmark;

use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;
use PhpBench\Attributes\Warmup;
use Psr\Container\ContainerInterface;

#[Warmup(1), Revs(10), Iterations(5)]
class MessagingBootBenchmark extends FullAppBenchmarkCase
{
protected function execute(ContainerInterface $container): void
{
$container->get(ConfiguredMessagingSystem::class);
}
}
33 changes: 33 additions & 0 deletions Monorepo/Benchmark/PlaceOrderBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Monorepo\Benchmark;

use Monorepo\ExampleApp\Common\Infrastructure\Configuration;
use Monorepo\ExampleApp\Common\UI\OrderController;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;
use PhpBench\Attributes\Warmup;
use Psr\Container\ContainerInterface;
use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpFoundation\Request;

#[Warmup(1), Revs(10), Iterations(5)]
class PlaceOrderBenchmark extends FullAppBenchmarkCase
{
protected function execute(ContainerInterface $container): void
{
$orderController = $container->get(OrderController::class);
$configuration = $container->get(Configuration::class);

$orderController->placeOrder(new Request(content: json_encode([
'orderId' => Uuid::uuid4()->toString(),
'address' => [
'street' => 'Washington',
'houseNumber' => '15',
'postCode' => '81-221',
'country' => 'Netherlands'
],
'productId' => $configuration->productId(),
])));
}
}
34 changes: 34 additions & 0 deletions Monorepo/Benchmark/PlaceOrderWithoutEcotoneBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Monorepo\Benchmark;

use Monorepo\ExampleApp\Common\Infrastructure\Configuration;
use Monorepo\ExampleApp\Common\UI\OrderControllerWithoutMessaging;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;
use PhpBench\Attributes\Skip;
use PhpBench\Attributes\Warmup;
use Psr\Container\ContainerInterface;
use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpFoundation\Request;

#[Skip, Warmup(1), Revs(10), Iterations(5)]
class PlaceOrderWithoutEcotoneBenchmark extends FullAppBenchmarkCase
{
protected function execute(ContainerInterface $container): void
{
$orderController = $container->get(OrderControllerWithoutMessaging::class);
$configuration = $container->get(Configuration::class);

$orderController->placeOrder(new Request(content: json_encode([
'orderId' => Uuid::uuid4()->toString(),
'address' => [
'street' => 'Washington',
'houseNumber' => '15',
'postCode' => '81-221',
'country' => 'Netherlands'
],
'productId' => $configuration->productId(),
])));
}
}
Loading

0 comments on commit 39ceb03

Please sign in to comment.