From cae2b850a7114e0f24da029a28f2c9d7b6f0d70f Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Mon, 14 Jul 2014 10:02:40 +0200 Subject: [PATCH] tweaked things so that we are back to just one base config file --- README.md | 9 ++--- cli-config.php.dist | 50 ++++++++++++++++++++++++---- cli-config.php.mongo-dist | 69 -------------------------------------- index.php | 70 +++++++++++++++++++++------------------ 4 files changed, 85 insertions(+), 113 deletions(-) delete mode 100644 cli-config.php.mongo-dist diff --git a/README.md b/README.md index 0f412e6..4c8da5b 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ composer require jackalope/jackalope-jackrabbit:~1.0 Also you can use MongoDB (not available at the moment): ``` -composer require jackalope/jackalope-mongodb:* +composer require jackalope/jackalope-mongodb:dev-master ``` -Copy the ``cli-config.php.dist`` or ``cli-config.php.mongo-dist`` for **MongoDB** to ``cli-config.php`` and adjust as needed. +Copy the ``cli-config.php.dist`` to ``cli-config.php`` and adjust as needed. Finally run ``php index.php`` or ``php index.php benchmark``. It is possible to also configure the number of nodes to add per batch via ``--count`` and the number of @@ -31,9 +31,10 @@ Once the command has been run once, it can optionally be run one more time with to add one more "section" on top of the existing data to see how the performance is without having lots of previous inserts/gets before. This can of course be combined with the other parameters. -Furthermore you can force a table optimization before the test run via ``--optimize``. +Furthermore you can force a table optimization (for Doctrine DBAL) before the test run via ``--optimize`` and +disable query execution via ``--disable-query``. -Finally it is possible to run some standard jackalope commands via ``./vendor/bin/jackalope``. +Finally it is possible to run some standard Jackalope commands via ``./vendor/bin/jackalope``. ## TODO diff --git a/cli-config.php.dist b/cli-config.php.dist index 2299e03..64cca5b 100644 --- a/cli-config.php.dist +++ b/cli-config.php.dist @@ -4,6 +4,7 @@ $db_user = 'root'; $db_pass = ''; $driver = 'pdo_sqlite'; $host = 'localhost'; +$port = null; $database = 'phpcr_benchmark'; $path = 'benchmark.sqlite'; $uri = 'http://localhost:8080/server'; @@ -11,7 +12,7 @@ $workspace = 'benchmark'; $phpcr_user = 'admin'; $phpcr_pass = 'admin'; -// either 'doctrine-dbal' or 'jackrabbit' +// either 'doctrine-dbal', 'jackrabbit' or 'mongodb' $transport = 'some-transport'; switch ($transport) { @@ -55,6 +56,33 @@ switch ($transport) { 'jackalope.logger' => new \Jackalope\Transport\Logging\Psr3Logger(new \Psr\Log\NullLogger()), ); break; + + case 'mongodb': + $mongoOptions = array('db' => $database); + if ($db_user) { + $mongoOptions['username'] = $db_user; + } + if ($db_pass) { + $mongoOptions['password'] = $db_pass; + } + + $port = $port ?: 27017; + $mongoClient = new \MongoClient(sprintf('mongodb://%s:%s', $host, $port), $mongoOptions); + + $doctrineMongoDB = new \Doctrine\MongoDB\Database( + new \Doctrine\MongoDB\Connection($mongoClient), + new \MongoDB($mongoClient, $database), + new \Doctrine\Common\EventManager() + ); + + $parameters = array( + 'jackalope.mongodb_database' => $doctrineMongoDB + ); + + $factory = new \Jackalope\RepositoryFactoryMongoDB(); + + break; + default: die('Pick a transport layer'); } @@ -85,6 +113,7 @@ if (isset($argv[1]) } $append = in_array('--append', $argv); +$disableQuery = in_array('--disable-query', $argv); $count = 100; $key = array_search('--count', $argv); @@ -97,10 +126,17 @@ if ($key && isset($argv[$key+1]) && is_numeric($argv[$key+1])) { $sections = $argv[$key+1]; } -if (!$append && $factory instanceof \Jackalope\RepositoryFactoryDoctrineDBAL) { - // recreate database schema - $options = array('disable_fks' => $dbConn->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform); - $repositorySchema = new \Jackalope\Transport\DoctrineDBAL\RepositorySchema($options, $dbConn); - $repositorySchema->reset(); - $workspaceInstance->createWorkspace($workspace); +if (!$append) { + if ($factory instanceof \Jackalope\RepositoryFactoryDoctrineDBAL) { + // recreate database schema + $options = array('disable_fks' => $dbConn->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform); + $repositorySchema = new \Jackalope\Transport\DoctrineDBAL\RepositorySchema($options, $dbConn); + $repositorySchema->reset(); + $workspaceInstance->createWorkspace($workspace); + } elseif ($factory instanceof \Jackalope\RepositoryFactoryMongoDB) { + // recreate database collections + $doctrineMongoDB->drop(); + $workspaceInstance->createWorkspace('default'); + $workspaceInstance->createWorkspace($workspace); + } } diff --git a/cli-config.php.mongo-dist b/cli-config.php.mongo-dist deleted file mode 100644 index 7596ee4..0000000 --- a/cli-config.php.mongo-dist +++ /dev/null @@ -1,69 +0,0 @@ - $database); -if ($db_user) $mongoOptions['username'] = $db_user; -if ($db_pass) $mongoOptions['password'] = $db_pass; -$mongoClient = new \MongoClient(sprintf('mongodb://%s:%s', $server, $port), $mongoOptions); - -$doctrineMongoDB = new \Doctrine\MongoDB\Database( - new \Doctrine\MongoDB\Connection($mongoClient), - new \MongoDB($mongoClient, $database), - new \Doctrine\Common\EventManager() -); - -$parameters = array('jackalope.mongodb_database' => $doctrineMongoDB); -$factory = new \Jackalope\RepositoryFactoryMongoDB(); -$credentials = new \PHPCR\SimpleCredentials($phpcr_user, $phpcr_pass); -$repository = $factory->getRepository($parameters); -$adminSession = $repository->login($credentials, 'default'); - -$workspaceInstance = $adminSession->getWorkspace(); -if (!in_array($workspace, $workspaceInstance->getAccessibleWorkspaceNames())) { - $workspaceInstance->createWorkspace($workspace); -} - -if (isset($argv[1]) - && $argv[1] != 'benchmark' - && $argv[1] != 'list' - && $argv[1] != 'help' -) { - $repository = $factory->getRepository($parameters); - - $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( - 'dialog' => new \Symfony\Component\Console\Helper\DialogHelper(), - 'phpcr' => new \PHPCR\Util\Console\Helper\PhpcrHelper($repository->login($credentials, $workspace)), - 'phpcr_console_dumper' => new \PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper(), - )); - - return; -} - -$append = in_array('--append', $argv); - -$count = 100; -$key = array_search('--count', $argv); -if ($key && isset($argv[$key+1]) && is_numeric($argv[$key+1])) { - $count = $argv[$key+1]; -} -$sections = 10; -$key = array_search('--sections', $argv); -if ($key && isset($argv[$key+1]) && is_numeric($argv[$key+1])) { - $sections = $argv[$key+1]; -} - -if (!$append && $factory instanceof \Jackalope\RepositoryFactoryMongoDB) { - // recreate database collections - $doctrineMongoDB->drop(); - $workspaceInstance->createWorkspace('default'); - $workspaceInstance->createWorkspace($workspace); -} diff --git a/index.php b/index.php index b4f84c6..76b821c 100644 --- a/index.php +++ b/index.php @@ -42,15 +42,17 @@ $path = $rootPath.'/1/'.$nodeName; $stopWatch = new \Symfony\Component\Stopwatch\Stopwatch(); -$qm = $session->getWorkspace()->getQueryManager(); -$sql = "SELECT * FROM [nt:unstructured] WHERE count = '$nodeName'"; -$query = $qm->createQuery($sql, \PHPCR\Query\QueryInterface::JCR_SQL2); -$sql2 = "SELECT * FROM [nt:unstructured] WHERE count = '$nodeName' AND ISDESCENDANTNODE('$rootPath/1')"; -$query2 = $qm->createQuery($sql2, \PHPCR\Query\QueryInterface::JCR_SQL2); -$sql = "SELECT * FROM [nt:unstructured] WHERE CONTAINS([nt:unstructured].md5, '".md5($nodeName)."')"; -$query3 = $qm->createQuery($sql, \PHPCR\Query\QueryInterface::JCR_SQL2); -$sql2 = "SELECT * FROM [nt:unstructured] WHERE CONTAINS([nt:unstructured].md5, '".md5($nodeName)."') AND ISDESCENDANTNODE('$rootPath/1')"; -$query4 = $qm->createQuery($sql2, \PHPCR\Query\QueryInterface::JCR_SQL2); +if (empty($disableQuery)) { + $qm = $session->getWorkspace()->getQueryManager(); + $sql = "SELECT * FROM [nt:unstructured] WHERE count = '$nodeName'"; + $query = $qm->createQuery($sql, \PHPCR\Query\QueryInterface::JCR_SQL2); + $sql2 = "SELECT * FROM [nt:unstructured] WHERE count = '$nodeName' AND ISDESCENDANTNODE('$rootPath/1')"; + $query2 = $qm->createQuery($sql2, \PHPCR\Query\QueryInterface::JCR_SQL2); + $sql = "SELECT * FROM [nt:unstructured] WHERE CONTAINS([nt:unstructured].md5, '".md5($nodeName)."')"; + $query3 = $qm->createQuery($sql, \PHPCR\Query\QueryInterface::JCR_SQL2); + $sql2 = "SELECT * FROM [nt:unstructured] WHERE CONTAINS([nt:unstructured].md5, '".md5($nodeName)."') AND ISDESCENDANTNODE('$rootPath/1')"; + $query4 = $qm->createQuery($sql2, \PHPCR\Query\QueryInterface::JCR_SQL2); +} gc_enable(); @@ -78,37 +80,39 @@ print_r("Getting a node by path took '" . $event->getDuration(). "' ms.\n"); validateNode($node, $path); - $stopWatch->start("search a node"); - $result = $query->execute(); - $event = $stopWatch->stop("search a node"); - print_r("Searching a node by property took '" . $event->getDuration(). "' ms.\n"); + if (empty($disableQuery)) { + $stopWatch->start("search a node"); + $result = $query->execute(); + $event = $stopWatch->stop("search a node"); + print_r("Searching a node by property took '" . $event->getDuration(). "' ms.\n"); - $node = $result->getNodes()->current(); - validateNode($node, $path); + $node = $result->getNodes()->current(); + validateNode($node, $path); - $stopWatch->start("search a node in a subpath"); - $result = $query2->execute(); - $event = $stopWatch->stop("search a node in a subpath"); - print_r("Searching a node by property in a subpath took '" . $event->getDuration(). "' ms.\n"); + $stopWatch->start("search a node in a subpath"); + $result = $query2->execute(); + $event = $stopWatch->stop("search a node in a subpath"); + print_r("Searching a node by property in a subpath took '" . $event->getDuration(). "' ms.\n"); - $node = $result->getNodes()->current(); - validateNode($node, $path); + $node = $result->getNodes()->current(); + validateNode($node, $path); - $stopWatch->start("search a node via contains"); - $result = $query3->execute(); - $event = $stopWatch->stop("search a node via contains"); - print_r("Searching a node via contains took '" . $event->getDuration(). "' ms.\n"); + $stopWatch->start("search a node via contains"); + $result = $query3->execute(); + $event = $stopWatch->stop("search a node via contains"); + print_r("Searching a node via contains took '" . $event->getDuration(). "' ms.\n"); - $node = $result->getNodes()->current(); - validateNode($node, $path); + $node = $result->getNodes()->current(); + validateNode($node, $path); - $stopWatch->start("search a node via contains in a subpath"); - $result = $query4->execute(); - $event = $stopWatch->stop("search a node via contains in a subpath"); - print_r("Searching a node via contains in a subpath took '" . $event->getDuration(). "' ms.\n"); + $stopWatch->start("search a node via contains in a subpath"); + $result = $query4->execute(); + $event = $stopWatch->stop("search a node via contains in a subpath"); + print_r("Searching a node via contains in a subpath took '" . $event->getDuration(). "' ms.\n"); - $node = $result->getNodes()->current(); - validateNode($node, $path); + $node = $result->getNodes()->current(); + validateNode($node, $path); + } } print_r("Current memory use is '".memory_get_usage()."' bytes \n");