Skip to content
Closed
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
4 changes: 2 additions & 2 deletions phpbench.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"runner.php_env": {
"PGSQL_DATABASE_URL": "pgsql://postgres:[email protected]:5432/postgres?serverVersion=11&charset=utf8"
},
"runner.iterations": 2,
"runner.retry_threshold": 10,
"runner.iterations": 10,
"runner.retry_threshold": 5,
"storage.xml_storage_path": "var/phpbench"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
{
$this->context = flow_context(config());
$this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_csv_loader_bench') . '.csv';
$this->rows = (new FakeStaticOrdersExtractor(10_000))->toRows();
$this->rows = (new FakeStaticOrdersExtractor(1_000))->toRows();
}

public function __destruct()
Expand All @@ -34,7 +34,7 @@ public function __destruct()
\unlink($this->outputPath);
}

public function bench_load_10k() : void
public function bench_load_1k() : void
{
to_csv($this->outputPath)->load($this->rows, $this->context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@

use function Flow\ETL\Adapter\Doctrine\{from_dbal_key_set_qb, from_dbal_limit_offset_qb, pagination_key_asc, pagination_key_set, to_dbal_schema_table, to_dbal_table_insert};
use function Flow\ETL\DSL\{config, df, flow_context};
use Doctrine\DBAL\{DriverManager, ParameterType};
use Doctrine\DBAL\{Connection, DriverManager, ParameterType};
use Doctrine\DBAL\Tools\DsnParser;
use Flow\ETL\Tests\Double\FakeStaticOrdersExtractor;
use PhpBench\Attributes\Groups;

#[Groups(['extractor'])]
final class DbalExtractorBench
{
private const TABLE_NAME = 'benchmark_orders_extractor';
private const string TABLE_NAME = 'benchmark_orders_extractor';

private \Doctrine\DBAL\Connection $connection;
private Connection $connection;

public function __construct()
{
$dsn = \getenv('PGSQL_DATABASE_URL');

if (!$dsn) {
throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');
}
$dsn = \getenv('PGSQL_DATABASE_URL') ?: throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');

$params = (new DsnParser(['postgresql' => 'pdo_pgsql']))->parse($dsn);

Expand All @@ -44,7 +40,7 @@ public function __destruct()
$this->connection->close();
}

public function bench_extract_10k_keyset() : void
public function bench_extract_1k_keyset() : void
{
$context = flow_context(config());

Expand All @@ -60,7 +56,7 @@ public function bench_extract_10k_keyset() : void
}
}

public function bench_extract_10k_limit_offset() : void
public function bench_extract_1k_limit_offset() : void
{
$context = flow_context(config());

Expand All @@ -72,7 +68,6 @@ public function bench_extract_10k_limit_offset() : void
foreach (from_dbal_limit_offset_qb(
$this->connection,
$queryBuilder,
page_size: 1000
)->extract($context) as $rows) {
}
}
Expand All @@ -89,7 +84,7 @@ private function setupDatabase() : void
$table->setPrimaryKey(['index']);
$schemaManager->createTable($table);

$extractor = new FakeStaticOrdersExtractor(10_000);
$extractor = new FakeStaticOrdersExtractor(1_000);

df()
->read($extractor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#[Groups(['loader'])]
final class DbalLoaderBench
{
private const TABLE_NAME = 'benchmark_orders_loader';
private const string TABLE_NAME = 'benchmark_orders_loader';

private Connection $connection;

Expand All @@ -25,16 +25,12 @@ final class DbalLoaderBench

public function __construct()
{
$dsn = \getenv('PGSQL_DATABASE_URL');

if (!$dsn) {
throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');
}
$dsn = \getenv('PGSQL_DATABASE_URL') ?: throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');

$params = (new DsnParser(['postgresql' => 'pdo_pgsql']))->parse($dsn);

$this->connection = DriverManager::getConnection($params);
$this->rows = (new FakeStaticOrdersExtractor(10_000))->toRows();
$this->rows = (new FakeStaticOrdersExtractor(1_000))->toRows();
$this->context = flow_context();
}

Expand Down Expand Up @@ -63,9 +59,9 @@ public function setUp() : void
}

#[BeforeMethods('setUp')]
public function bench_load_10k() : void
public function bench_load_1k() : void
{
foreach ($this->rows->chunks(1_000) as $chunk) {
foreach ($this->rows->chunks(100) as $chunk) {
to_dbal_table_insert($this->connection, self::TABLE_NAME)->load($chunk, $this->context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
{
$this->context = flow_context(config());
$this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_json_loader_bench') . '.json';
$this->rows = (new FakeStaticOrdersExtractor(10_000))->toRows();
$this->rows = (new FakeStaticOrdersExtractor(1_000))->toRows();
}

public function __destruct()
Expand All @@ -34,7 +34,7 @@ public function __destruct()
\unlink($this->outputPath);
}

public function bench_load_10k() : void
public function bench_load_1k() : void
{
to_json($this->outputPath)->load($this->rows, $this->context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
{
$this->context = flow_context(config());
$this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_parquet_loader_bench') . '.parquet';
$this->rows = (new FakeStaticOrdersExtractor(10_000))->toRows();
$this->rows = (new FakeStaticOrdersExtractor(1_000))->toRows();
}

public function __destruct()
Expand All @@ -34,7 +34,7 @@ public function __destruct()
\unlink($this->outputPath);
}

public function bench_load_10k() : void
public function bench_load_1k() : void
{
to_parquet($this->outputPath)->load($this->rows, $this->context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
#[Groups(['extractor'])]
final class PostgreSqlExtractorBench
{
private const TABLE_NAME = 'benchmark_orders_extractor';
private const string TABLE_NAME = 'benchmark_orders_extractor';

private Client $client;

public function __construct()
{
$dsn = \getenv('PGSQL_DATABASE_URL');

if (!$dsn) {
throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');
}
$dsn = \getenv('PGSQL_DATABASE_URL') ?: throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');

if (!\extension_loaded('pgsql')) {
throw new \RuntimeException('ext-pgsql is not available');
Expand All @@ -50,37 +46,37 @@ public function __destruct()
$this->client->close();
}

public function bench_extract_10k_cursor() : void
public function bench_extract_1k_cursor() : void
{
$context = flow_context(config());

foreach (from_pgsql_cursor(
$this->client,
select(star())->from(table(self::TABLE_NAME)),
)->withFetchSize(1000)->extract($context) as $rows) {
)->withFetchSize(100)->extract($context) as $rows) {
}
}

public function bench_extract_10k_keyset() : void
public function bench_extract_1k_keyset() : void
{
$context = flow_context(config());

foreach (from_pgsql_key_set(
$this->client,
select(star())->from(table(self::TABLE_NAME)),
pgsql_pagination_key_set(pgsql_pagination_key_asc('index')),
)->withPageSize(1000)->extract($context) as $rows) {
)->withPageSize(100)->extract($context) as $rows) {
}
}

public function bench_extract_10k_limit_offset() : void
public function bench_extract_1k_limit_offset() : void
{
$context = flow_context(config());

foreach (from_pgsql_limit_offset(
$this->client,
select(star())->from(table(self::TABLE_NAME))->orderBy(asc(col('index'))),
)->withPageSize(1000)->extract($context) as $rows) {
)->withPageSize(100)->extract($context) as $rows) {
}
}

Expand All @@ -104,11 +100,8 @@ private function setupDatabase() : void
->column(column('items', data_type_jsonb()))
);

$extractor = new FakeStaticOrdersExtractor(10_000);
$context = flow_context(config());

df()
->read($extractor)
->read(new FakeStaticOrdersExtractor(1_000))
->write(to_pgsql_table($this->client, self::TABLE_NAME))
->run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#[Groups(['loader'])]
final class PostgreSqlLoaderBench
{
private const TABLE_NAME = 'benchmark_orders_loader';
private const string TABLE_NAME = 'benchmark_orders_loader';

private Client $client;

Expand All @@ -25,11 +25,7 @@ final class PostgreSqlLoaderBench

public function __construct()
{
$dsn = \getenv('PGSQL_DATABASE_URL');

if (!$dsn) {
throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');
}
$dsn = \getenv('PGSQL_DATABASE_URL') ?: throw new \RuntimeException('PGSQL_DATABASE_URL environment variable is not set');

if (!\extension_loaded('pgsql')) {
throw new \RuntimeException('ext-pgsql is not available');
Expand All @@ -43,7 +39,7 @@ public function __construct()
pgsql_connection_dsn($dsn),
mapper: pgsql_mapper(),
);
$this->rows = (new FakeStaticOrdersExtractor(10_000))->toRows();
$this->rows = (new FakeStaticOrdersExtractor(1_000))->toRows();
$this->context = flow_context();
}

Expand Down Expand Up @@ -77,9 +73,9 @@ public function setUp() : void
}

#[BeforeMethods('setUp')]
public function bench_load_10k() : void
public function bench_load_1k() : void
{
foreach ($this->rows->chunks(1_000) as $chunk) {
foreach ($this->rows->chunks(100) as $chunk) {
to_pgsql_table($this->client, self::TABLE_NAME)->load($chunk, $this->context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Flow\ETL\Adapter\Text\Tests\Benchmark;

use function Flow\ETL\Adapter\Text\to_text;
use function Flow\ETL\DSL\{config, flow_context};
use function Flow\ETL\DSL\{config, flow_context, row};
use Flow\ETL\{FlowContext, Row, Rows, Tests\Double\FakeStaticOrdersExtractor};
use PhpBench\Attributes\Groups;

Expand All @@ -22,8 +22,8 @@ public function __construct()
{
$this->context = flow_context(config());
$this->outputPath = \tempnam(\sys_get_temp_dir(), 'etl_txt_loader_bench') . '.txt';
$this->rows = (new FakeStaticOrdersExtractor(10_000))->toRows()->map(
fn (Row $r) => \Flow\ETL\DSL\row($r->get('order_id'))
$this->rows = (new FakeStaticOrdersExtractor(1_000))->toRows()->map(
fn (Row $r): Row => row($r->get('order_id'))
);
}

Expand All @@ -36,7 +36,7 @@ public function __destruct()
\unlink($this->outputPath);
}

public function bench_load_10k() : void
public function bench_load_1k() : void
{
to_text($this->outputPath)->load($this->rows, $this->context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public function provideRows() : \Generator
'notes' => "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
];

yield '10k' => ['rows' => \array_map($callback, \range(1, 10_000))];

yield '5k' => ['rows' => \array_map($callback, \range(1, 5000))];

yield '1k' => ['rows' => \array_map($callback, \range(1, 1000))];
}
}
12 changes: 1 addition & 11 deletions src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,16 @@
#[Groups(['building_blocks'])]
final class RowsBench
{
private Rows $rows;

private Rows $rows100;

private Rows $rows1k;

public function setUp() : void
{
$this->rows = (new FakeStaticOrdersExtractor(10_000))->toRows();
$this->rows1k = (new FakeStaticOrdersExtractor(1_000))->toRows();
$this->rows100 = (new FakeStaticOrdersExtractor(100))->toRows();
}

public function bench_chunk_1_000_on_10k() : void
{
foreach ($this->rows->chunks(1_000) as $chunk) {

}
}

public function bench_diff_left_100_on_1k() : void
{
$this->rows1k->diffLeft($this->rows100);
Expand Down Expand Up @@ -91,7 +81,7 @@ public function bench_partition_by_on_1k() : void

public function bench_schema_on_1k_identical_rows() : void
{
$this->rows->schema();
$this->rows1k->schema();
}

public function bench_sort_asc_on_1k() : void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setUp() : void
$this->context = flow_context(config());
}

public function bench_transform_10k_rows() : void
public function bench_transform_1k_rows() : void
{
(new RenameEachEntryTransformer(rename_style(StringStyles::KEBAB)))->transform($this->rows, $this->context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function setUp() : void
['id' => 3, 'random' => false, 'text' => null, 'from' => 666],
['id' => 4, 'random' => true, 'text' => null, 'from' => 666],
['id' => 5, 'random' => false, 'text' => null, 'from' => 666],
], \range(0, 10_000))),
], \range(0, 1_000))),
flow_context(config())->entryFactory(),
);
$this->context = flow_context(config());
}

public function bench_transform_10k_rows() : void
public function bench_transform_1k_rows() : void
{
(new RenameEntryTransformer('from', 'to'))->transform($this->rows, $this->context);
}
Expand Down
Loading
Loading