forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1.3.x: Add build stages for MongoDB 3.0+ Extract coverage to separate build Fix wrong version number in MongoDB 4.0 build stage Move toolchain installation to install step Add performance stage to travis-ci Add basic benchmark tests Rework MongoDB installation to correctly install server versions Add note about ini settings for legacy drivers Add test stage for replica sets Only run sharding tests on sharded clusters
- Loading branch information
Showing
11 changed files
with
485 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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,11 @@ | ||
#!/bin/bash | ||
|
||
if nc -z localhost 27017 | ||
then | ||
sudo service mongod stop | ||
fi | ||
|
||
export SERVER_FILENAME=mongodb-linux-x86_64-${SERVER_DISTRO}-${SERVER_VERSION} | ||
wget -qO- http://fastdl.mongodb.org/linux/${SERVER_FILENAME}.tgz | tar xz | ||
export PATH=${PWD}/${SERVER_FILENAME}/bin:${PATH} | ||
mongod --version |
This file contains 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,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ODM\MongoDB\Benchmark; | ||
|
||
use Doctrine\Common\Cache\ArrayCache; | ||
use Doctrine\ODM\MongoDB\Configuration; | ||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; | ||
use MongoDB\Client; | ||
use MongoDB\Model\DatabaseInfo; | ||
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; | ||
use function array_map; | ||
use function getenv; | ||
use function in_array; | ||
use function iterator_to_array; | ||
|
||
/** | ||
* @BeforeMethods({"initDocumentManager", "clearDatabase"}) | ||
*/ | ||
abstract class BaseBench | ||
{ | ||
public const DATABASE_NAME = 'doctrine_odm_performance'; | ||
private const DEFAULT_MONGODB_SERVER = 'mongodb://localhost:27017'; | ||
|
||
/** @var DocumentManager */ | ||
protected static $documentManager; | ||
|
||
/** | ||
* @return DocumentManager | ||
*/ | ||
protected function getDocumentManager() | ||
{ | ||
return self::$documentManager; | ||
} | ||
|
||
public function initDocumentManager() | ||
{ | ||
$config = new Configuration(); | ||
|
||
$config->setProxyDir(__DIR__ . '/../../tests/Proxies'); | ||
$config->setProxyNamespace('Proxies'); | ||
$config->setHydratorDir(__DIR__ . '/../../tests/Hydrators'); | ||
$config->setHydratorNamespace('Hydrators'); | ||
$config->setPersistentCollectionDir(__DIR__ . '/../../tests/PersistentCollections'); | ||
$config->setPersistentCollectionNamespace('PersistentCollections'); | ||
$config->setDefaultDB(self::DATABASE_NAME); | ||
$config->setMetadataDriverImpl(self::createMetadataDriverImpl()); | ||
$config->setMetadataCacheImpl(new ArrayCache()); | ||
|
||
$client = new Client( | ||
getenv('DOCTRINE_MONGODB_SERVER') ?: self::DEFAULT_MONGODB_SERVER, | ||
[], | ||
['typeMap' => ['root' => 'array', 'document' => 'array']] | ||
); | ||
|
||
self::$documentManager = DocumentManager::create($client, $config); | ||
} | ||
|
||
public function clearDatabase() | ||
{ | ||
// Check if the database exists. Calling listCollections on a non-existing | ||
// database in a sharded setup will cause an invalid command cursor to be | ||
// returned | ||
$client = self::$documentManager->getClient(); | ||
$databases = iterator_to_array($client->listDatabases()); | ||
$databaseNames = array_map(static function (DatabaseInfo $database) { | ||
return $database->getName(); | ||
}, $databases); | ||
if (! in_array(self::DATABASE_NAME, $databaseNames)) { | ||
return; | ||
} | ||
|
||
$collections = $client->selectDatabase(self::DATABASE_NAME)->listCollections(); | ||
|
||
foreach ($collections as $collection) { | ||
// See https://jira.mongodb.org/browse/SERVER-16541 | ||
if ($collection->getName() === 'system.indexes') { | ||
continue; | ||
} | ||
|
||
$client->selectCollection(self::DATABASE_NAME, $collection->getName())->drop(); | ||
} | ||
} | ||
|
||
protected static function createMetadataDriverImpl() | ||
{ | ||
return AnnotationDriver::create(__DIR__ . '/../tests/Documents'); | ||
} | ||
} |
This file contains 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,122 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ODM\MongoDB\Benchmark\Document; | ||
|
||
use Doctrine\ODM\MongoDB\Benchmark\BaseBench; | ||
use Doctrine\ODM\MongoDB\Hydrator\HydratorInterface; | ||
use Documents\User; | ||
use MongoDB\BSON\ObjectId; | ||
use MongoDB\BSON\UTCDateTime; | ||
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
|
||
/** | ||
* @BeforeMethods({"init"}, extend=true) | ||
*/ | ||
final class HydrateDocumentBench extends BaseBench | ||
{ | ||
/** @var array */ | ||
private static $data; | ||
|
||
/** @var array */ | ||
private static $embedOneData; | ||
|
||
/** @var array */ | ||
private static $embedManyData; | ||
|
||
/** @var array */ | ||
private static $referenceOneData; | ||
|
||
/** @var array */ | ||
private static $referenceManyData; | ||
|
||
/** @var HydratorInterface */ | ||
private static $hydrator; | ||
|
||
public function init() | ||
{ | ||
self::$data = [ | ||
'_id' => new ObjectId(), | ||
'username' => 'alcaeus', | ||
'createdAt' => new UTCDateTime(), | ||
]; | ||
|
||
self::$embedOneData = [ | ||
'address' => ['city' => 'Munich'], | ||
]; | ||
|
||
self::$embedManyData = [ | ||
'phonenumbers' => [ | ||
['phonenumber' => '12345678'], | ||
['phonenumber' => '12345678'], | ||
], | ||
]; | ||
|
||
self::$referenceOneData = [ | ||
'account' => [ | ||
'$ref' => 'Account', | ||
'$id' => new ObjectId(), | ||
], | ||
]; | ||
|
||
self::$referenceManyData = [ | ||
'groups' => [ | ||
[ | ||
'$ref' => 'Group', | ||
'$id' => new ObjectId(), | ||
], | ||
[ | ||
'$ref' => 'Group', | ||
'$id' => new ObjectId(), | ||
], | ||
], | ||
]; | ||
|
||
self::$hydrator = $this | ||
->getDocumentManager() | ||
->getHydratorFactory() | ||
->getHydratorFor(User::class); | ||
} | ||
|
||
/** | ||
* @Warmup(2) | ||
*/ | ||
public function benchHydrateDocument() | ||
{ | ||
self::$hydrator->hydrate(new User(), self::$data); | ||
} | ||
|
||
/** | ||
* @Warmup(2) | ||
*/ | ||
public function benchHydrateDocumentWithEmbedOne() | ||
{ | ||
self::$hydrator->hydrate(new User(), self::$data + self::$embedOneData); | ||
} | ||
|
||
/** | ||
* @Warmup(2) | ||
*/ | ||
public function benchHydrateDocumentWithEmbedMany() | ||
{ | ||
self::$hydrator->hydrate(new User(), self::$data + self::$embedManyData); | ||
} | ||
|
||
/** | ||
* @Warmup(2) | ||
*/ | ||
public function benchHydrateDocumentWithReferenceOne() | ||
{ | ||
self::$hydrator->hydrate(new User(), self::$data + self::$referenceOneData); | ||
} | ||
|
||
/** | ||
* @Warmup(2) | ||
*/ | ||
public function benchHydrateDocumentWithReferenceMany() | ||
{ | ||
self::$hydrator->hydrate(new User(), self::$data + self::$referenceManyData); | ||
} | ||
} |
Oops, something went wrong.