Skip to content

Commit

Permalink
Use dedicated class for ParallelMultiFileImportBench
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Sep 20, 2023
1 parent 59515b0 commit 0f9ce7c
Showing 1 changed file with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
/**
* For accurate results, run benchmarks on a standalone server.
*
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#parallel
* @see https://github.com/mongodb/specifications/blob/ddfc8b583d49aaf8c4c19fa01255afb66b36b92e/source/benchmarking/benchmarking.rst#ldjson-multi-file-import
*/
#[BeforeClassMethods('beforeClass')]
#[AfterClassMethods('afterClass')]
final class ParallelBench
#[BeforeMethods('beforeIteration')]
#[Revs(1)]
#[Iterations(1)]
final class ParallelMultiFileImportBench
{
public static function beforeClass(): void
{
Expand All @@ -60,13 +63,17 @@ public static function afterClass(): void
}
}

public function beforeIteration(): void
{
$database = Utils::getDatabase();
$database->drop();
$database->createCollection(Utils::getCollectionName());
}

/**
* Parallel: LDJSON multi-file import
* Using Driver's BulkWrite in a single thread
*/
#[BeforeMethods('beforeMultiFileImport')]
#[Revs(1)]
#[Iterations(1)]
public function benchMultiFileImportBulkWrite(): void
{
foreach (self::getFileNames() as $file) {
Expand All @@ -75,12 +82,8 @@ public function benchMultiFileImportBulkWrite(): void
}

/**
* Parallel: LDJSON multi-file import
* Using library's Collection::insertMany in a single thread
*/
#[BeforeMethods('beforeMultiFileImport')]
#[Revs(1)]
#[Iterations(1)]
public function benchMultiFileImportInsertMany(): void
{
$collection = Utils::getCollection();
Expand All @@ -102,15 +105,11 @@ public function benchMultiFileImportInsertMany(): void
}

/**
* Parallel: LDJSON multi-file import
* Using multiple forked threads
*
* @param array{processes:int, files:string[], batchSize:int} $params
*/
#[BeforeMethods('beforeMultiFileImport')]
#[ParamProviders(['provideProcessesParameter'])]
#[Revs(1)]
#[Iterations(1)]
public function benchMultiFileImportFork(array $params): void
{
$pids = [];
Expand Down Expand Up @@ -149,15 +148,11 @@ public function benchMultiFileImportFork(array $params): void
}

/**
* Parallel: LDJSON multi-file import
* Using amphp/parallel-functions with worker pool
*
* @param array{processes:int, files:string[], batchSize:int} $params
*/
#[BeforeMethods('beforeMultiFileImport')]
#[ParamProviders(['provideProcessesParameter'])]
#[Revs(1)]
#[Iterations(1)]
public function benchMultiFileImportAmp(array $params): void
{
wait(parallelMap(
Expand All @@ -180,13 +175,6 @@ public static function provideProcessesParameter(): Generator
yield '34 proc' => ['processes' => 34]; // 3 sequences
}

public function beforeMultiFileImport(): void
{
$database = Utils::getDatabase();
$database->drop();
$database->createCollection(Utils::getCollectionName());
}

public static function importFile(string $file): void
{
$namespace = sprintf('%s.%s', Utils::getDatabaseName(), Utils::getCollectionName());
Expand Down

0 comments on commit 0f9ce7c

Please sign in to comment.