-
Notifications
You must be signed in to change notification settings - Fork 266
Add server description to the benchmark report #1163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eef00cb
Add server description to the report
GromNaN bf12951
Move warmup to each benchmark
GromNaN cc95d4e
Remove BaseBench for specialized static classes
GromNaN 4c8ce4c
Update benchmark/Extension/EnvironmentProvider.php
GromNaN 2eb5cc9
Merge branch 'master' into phpbench-env
GromNaN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace MongoDB\Benchmark\Extension; | ||
|
||
use MongoDB\Benchmark\Utils; | ||
use MongoDB\Driver\Command; | ||
use MongoDB\Driver\Manager; | ||
use MongoDB\Driver\ReadPreference; | ||
use MongoDB\Driver\Server; | ||
use PhpBench\Environment\Information; | ||
use PhpBench\Environment\ProviderInterface; | ||
|
||
use function array_merge; | ||
use function implode; | ||
use function parse_url; | ||
use function str_replace; | ||
|
||
use const PHP_URL_PASS; | ||
|
||
class EnvironmentProvider implements ProviderInterface | ||
{ | ||
public function isApplicable(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function getInformation(): Information | ||
{ | ||
$client = Utils::getClient(); | ||
$client->getManager()->selectServer(); | ||
|
||
return new Information('mongodb', array_merge( | ||
$this->getUri(), | ||
$this->getServerInfo($client->getManager()), | ||
$this->getBuildInfo($client->getManager()), | ||
)); | ||
} | ||
|
||
private function getUri(): array | ||
{ | ||
$uri = Utils::getUri(); | ||
// Obfuscate the password in the URI | ||
$uri = str_replace(':' . parse_url($uri, PHP_URL_PASS) . '@', ':***@', $uri); | ||
|
||
return ['uri' => $uri]; | ||
} | ||
|
||
private function getServerInfo(Manager $manager): array | ||
{ | ||
$topology = match ($manager->selectServer()->getType()) { | ||
Server::TYPE_STANDALONE => 'standalone', | ||
Server::TYPE_LOAD_BALANCER => 'load-balanced', | ||
Server::TYPE_RS_PRIMARY => 'replica-set', | ||
Server::TYPE_MONGOS => 'shared', | ||
default => 'unknown', | ||
}; | ||
|
||
return ['topology' => $topology]; | ||
} | ||
|
||
private function getBuildInfo(Manager $manager): array | ||
{ | ||
$buildInfo = $manager->executeCommand( | ||
Utils::getDatabase(), | ||
new Command(['buildInfo' => 1]), | ||
new ReadPreference(ReadPreference::PRIMARY), | ||
)->toArray()[0]; | ||
|
||
return [ | ||
'version' => $buildInfo->version ?? 'unknown server version', | ||
'modules' => implode(', ', $buildInfo->modules ?? []), | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace MongoDB\Benchmark\Extension; | ||
|
||
use PhpBench\DependencyInjection\Container; | ||
use PhpBench\DependencyInjection\ExtensionInterface; | ||
use PhpBench\Extension\RunnerExtension; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class MongoDBExtension implements ExtensionInterface | ||
{ | ||
public function load(Container $container): void | ||
{ | ||
$container->register( | ||
EnvironmentProvider::class, | ||
fn (Container $container) => new EnvironmentProvider(), | ||
[RunnerExtension::TAG_ENV_PROVIDER => ['name' => 'mongodb']], | ||
); | ||
} | ||
|
||
public function configure(OptionsResolver $resolver): void | ||
{ | ||
// No config | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace MongoDB\Benchmark\Fixtures; | ||
|
||
use function file_get_contents; | ||
use function json_decode; | ||
|
||
use const JSON_THROW_ON_ERROR; | ||
|
||
final class Data | ||
{ | ||
public const LARGE_FILE_PATH = __DIR__ . '/data/large_doc.json'; | ||
public const SMALL_FILE_PATH = __DIR__ . '/data/small_doc.json'; | ||
public const TWEET_FILE_PATH = __DIR__ . '/data/tweet.json'; | ||
|
||
public static function readJsonFile(string $path): array | ||
{ | ||
return json_decode(file_get_contents($path), true, 512, JSON_THROW_ON_ERROR); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"oggaoR4O":"miNVpaKW","Vxri7mmI":"CS5VwrwN","IQ8K4ZMG":"Oq5Csk1w","WzI8s1W0":"ZPm57dhu","E5Aj2zB3":"gxUpzIjg","3MXe8Wi7":"Smo9whci","PHPSSV51":"TW34kfzq","CxSCo4jD":55336395,"5C8GSDC5":41992681,"fC63DsLR":72188733,"l6e0U4bR":46660880,"TLRpkltp":3527055,"Ph9CZN5L":74094448} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.