From 0f9ce7c639c891f1a22e95150b01a00b96b558b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 20 Sep 2023 17:33:50 +0200 Subject: [PATCH] Use dedicated class for ParallelMultiFileImportBench --- ...h.php => ParallelMultiFileImportBench.php} | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) rename benchmark/src/DriverBench/{ParallelBench.php => ParallelMultiFileImportBench.php} (91%) diff --git a/benchmark/src/DriverBench/ParallelBench.php b/benchmark/src/DriverBench/ParallelMultiFileImportBench.php similarity index 91% rename from benchmark/src/DriverBench/ParallelBench.php rename to benchmark/src/DriverBench/ParallelMultiFileImportBench.php index d2fb05891..bd3accdb7 100644 --- a/benchmark/src/DriverBench/ParallelBench.php +++ b/benchmark/src/DriverBench/ParallelMultiFileImportBench.php @@ -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 { @@ -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) { @@ -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(); @@ -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 = []; @@ -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( @@ -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());