Skip to content

Commit

Permalink
tweaked things so that we are back to just one base config file
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Jul 14, 2014
1 parent c1a44a2 commit cae2b85
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 113 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -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
Expand All @@ -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

Expand Down
50 changes: 43 additions & 7 deletions cli-config.php.dist
Expand Up @@ -4,14 +4,15 @@ $db_user = 'root';
$db_pass = '';
$driver = 'pdo_sqlite';
$host = 'localhost';
$port = null;
$database = 'phpcr_benchmark';
$path = 'benchmark.sqlite';
$uri = 'http://localhost:8080/server';
$workspace = 'benchmark';
$phpcr_user = 'admin';
$phpcr_pass = 'admin';

// either 'doctrine-dbal' or 'jackrabbit'
// either 'doctrine-dbal', 'jackrabbit' or 'mongodb'
$transport = 'some-transport';

switch ($transport) {
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
69 changes: 0 additions & 69 deletions cli-config.php.mongo-dist

This file was deleted.

70 changes: 37 additions & 33 deletions index.php
Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit cae2b85

Please sign in to comment.