Skip to content

Commit 5e0d448

Browse files
committed
Added traversal bench
1 parent 0b98960 commit 5e0d448

File tree

9 files changed

+195
-280
lines changed

9 files changed

+195
-280
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

README.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Benchmarking suite for PHPCR which uses the same bootstrapping process as the
77
Usage
88
-----
99

10-
Ensure that the PHPCR-API tests are working.
10+
The benchmarking suite uses the existing `phpunit.xml` configuration. Ensure that the PHPCR-API tests are working.
1111

1212
Include as a dev requirement:
1313

@@ -18,23 +18,7 @@ $ composer require "phpcr/phpcr-benchmarks"
1818
Run:
1919

2020
````bash
21-
$ ./vendor/bin/phpbench ./vendor/phpcr/phpcr-benchmarks/benchmarks
21+
$ ./vendor/bin/phpbench run --config=vendor/phpcr/phpcr-benchmarks/config/phpbench
2222
````
2323

24-
With detailed report:
25-
26-
````bash
27-
$ ./vendor/bin/phpbench ./vendor/phpcr/phpcr-benchmarks/benchmarks \
28-
--report={"name": "console_table", "memory": true}
29-
````
30-
31-
With a filter:
32-
33-
````bash
34-
$ ./vendor/bin/phpbench ./vendor/phpcr/phpcr-benchmarks/benchmarks \
35-
--report=console_table
36-
--filter=benchInsert
37-
````
38-
39-
For more information see the documentation for [PHPBench](https://github.com/dantleech/phpbench).
40-
24+
For more information see the documentation for [PHPBench](https://github.com/phpbench/phpbench).

benchmarks/BaseBench.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,14 @@ protected function getWorkspace()
7171
return $this->getSession()->getWorkspace();
7272
}
7373

74-
protected function createNodes(NodeInterface $parentNode, $number, $properties = array(), $sections = 1, $offset = 0)
74+
protected function createNodes(NodeInterface $parentNode, $number, $properties = array(), $offset = 0)
7575
{
7676
$number = $number + $offset;
77-
for ($section = 0; $section < $sections; $section++) {
78-
if (!$parentNode->hasNode('section-' . $section)) {
79-
$sectionNode = $parentNode->addNode('section-' . $section);
80-
} else {
81-
$sectionNode = $parentNode->getNode('section-' . $section);
82-
}
83-
for ($i = $offset; $i < $number; $i++) {
84-
$node = $sectionNode->addNode('node-' . $i);
85-
foreach ($properties as $property => $value) {
86-
$node->setProperty($property, $value);
87-
}
77+
78+
for ($i = $offset; $i < $number; $i++) {
79+
$node = $parentNode->addNode('node-' . $i);
80+
foreach ($properties as $property => $value) {
81+
$node->setProperty($property, $value);
8882
}
8983
}
9084
}

benchmarks/InsertBench.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
use PhpBench\Benchmark\Iteration;
77
use PHPCR\Benchmark\BaseBench;
88

9+
/**
10+
* @group insert
11+
* @processIsolation iteration
12+
*/
913
class InsertBench extends BaseBench
1014
{
1115
/**
@@ -21,7 +25,7 @@ public function benchInsertNodes(Iteration $iteration)
2125
'number' => 10,
2226
'hello' => 'goodbye',
2327
'goodbye' => 'hello',
24-
), $iteration->getParameter('sections'), 0);
28+
), 0);
2529

2630
$this->getSession()->save();
2731
}
@@ -36,19 +40,15 @@ public function provideNbNodes()
3640
return array(
3741
array(
3842
'nb_nodes' => 1,
39-
'sections' => 1,
4043
),
4144
array(
4245
'nb_nodes' => 10,
43-
'sections' => 1,
4446
),
4547
array(
4648
'nb_nodes' => 100,
47-
'sections' => 1,
4849
),
4950
array(
5051
'nb_nodes' => 1000,
51-
'sections' => 1,
5252
),
5353
);
5454
}

benchmarks/QueryBench.php

Lines changed: 44 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,38 @@
55
use PhpBench\Benchmark\Iteration;
66
use PHPCR\Benchmark\BaseBench;
77

8+
/**
9+
* @group query
10+
* @processIsolation iteration
11+
*/
812
class QueryBench extends BaseBench
913
{
10-
/**
11-
* @description Run a select query
12-
* @paramProvider provideQueryVariableProperties
13-
* @paramProvider provideNbNodes
14-
* @beforeMethod beforeCreateNodes
15-
* @iterations 1
16-
*/
17-
public function benchQuery(Iteration $iteration)
14+
public function setUp()
1815
{
19-
$query = $this->getQueryManager()->createQuery($iteration->getParameter('query'), 'JCR-SQL2');
20-
$query->execute();
16+
$this->loadDump('large_website.xml');
2117
}
2218

2319
/**
24-
* @description Run a select query and iterate
25-
* @paramProvider provideQueryVariableProperties
26-
* @paramProvider provideNbNodes
27-
* @beforeMethod beforeCreateNodes
28-
* @iterations 1
20+
* @description No iterations
21+
* @paramProvider provideQueries
22+
* @iterations 5
23+
* @group query_single_prop
2924
*/
30-
public function benchQueryAndIterate(Iteration $iteration)
25+
public function benchQuery(Iteration $iteration)
3126
{
3227
$query = $this->getQueryManager()->createQuery($iteration->getParameter('query'), 'JCR-SQL2');
33-
$result = $query->execute();
34-
35-
foreach ($result->getRows() as $row) {
36-
$row->getPath();
37-
}
28+
$query->execute();
3829
}
3930

4031
/**
41-
* @description Run a select query and get node for each result
42-
* @paramProvider provideQueryVariableProperties
43-
* @paramProvider provideNbNodes
44-
* @beforeMethod beforeCreateNodes
45-
* @iterations 2
32+
* @description Retrive nodes for each row
33+
* @paramProvider provideQueries
34+
* @iterations 5
35+
* @group query_single_prop
4636
*/
47-
public function benchQueryAndIterateWithNode(Iteration $iteration)
37+
public function benchQueryWithNodes(Iteration $iteration)
4838
{
4939
$query = $this->getQueryManager()->createQuery($iteration->getParameter('query'), 'JCR-SQL2');
50-
$result = $query->execute();
51-
52-
foreach ($result->getRows() as $row) {
53-
$row->getNode()->getPath();
54-
}
55-
}
56-
57-
/**
58-
* @description Search by property
59-
* @paramProvider provideNbNodesWithSections
60-
* @beforeMethod beforeCreateNodes
61-
* @beforeMethod beforeAppendNode
62-
* @iterations 2
63-
*/
64-
public function benchSearchByProperty()
65-
{
66-
$query = $this->getQueryManager()->createQuery(
67-
'SELECT * FROM [nt:unstructured] WHERE my_new_property = "foobar"'
68-
, 'JCR-SQL2');
6940
$results = $query->execute();
7041

7142
foreach ($results as $result) {
@@ -74,17 +45,14 @@ public function benchSearchByProperty()
7445
}
7546

7647
/**
77-
* @description Search by property in a subpath
78-
* @paramProvider provideNbNodesWithSections
79-
* @beforeMethod beforeCreateNodes
80-
* @beforeMethod beforeAppendNode
81-
* @iterations 2
48+
* @description Iterate over rows and retrieve properties
49+
* @paramProvider provideQueries
50+
* @iterations 5
51+
* @group query_single_prop
8252
*/
83-
public function benchSearchByPropertyInSubpath()
53+
public function benchQueryIterate(Iteration $iteration)
8454
{
85-
$query = $this->getQueryManager()->createQuery(
86-
'SELECT * FROM [nt:unstructured] WHERE my_new_property = "foobar" AND ISDESCENDANTNODE("/bench/section-0")'
87-
, 'JCR-SQL2');
55+
$query = $this->getQueryManager()->createQuery($iteration->getParameter('query'), 'JCR-SQL2');
8856
$results = $query->execute();
8957

9058
foreach ($results as $result) {
@@ -93,115 +61,50 @@ public function benchSearchByPropertyInSubpath()
9361
}
9462

9563
/**
96-
* @description Full text search within property
97-
* @paramProvider provideNbNodesWithSections
98-
* @beforeMethod beforeCreateNodes
99-
* @beforeMethod beforeAppendNode
100-
* @iterations 2
64+
* @description Run a select query with variable amount of properties
65+
* @paramProvider provideProperties
66+
* @iterations 5
67+
* @group query_variable_props
10168
*/
102-
public function benchSearchPropertyFullText()
69+
public function benchQueryIterateVariableProperties(Iteration $iteration)
10370
{
104-
$query = $this->getQueryManager()->createQuery(
105-
'SELECT * FROM [nt:unstructured] WHERE CONTAINS(my_new_property, "foobar")'
106-
, 'JCR-SQL2');
107-
$results = $query->execute();
108-
109-
foreach ($results as $result) {
110-
$result->getNode();
111-
}
112-
}
113-
114-
public function beforeCreateNodes(Iteration $iteration)
115-
{
116-
// do not recreate nodes in the same iteration set
117-
if ($iteration->getIndex() > 0) {
118-
$this->resetSession();
119-
return;
120-
}
71+
$props = $iteration->getParameter('props');
72+
$query = $this->getQueryManager()->createQuery(sprintf(
73+
'SELECT %s FROM [nt:unstructured] WHERE valves IS NOT NULL'
74+
, implode(', ', $props)), 'JCR-SQL2');
12175

122-
$this->resetWorkspace();
123-
124-
// warmup the connection
125-
$this->getQueryManager()->createQuery('SELECT * FROM [nt:unstructured]', 'JCR-SQL2')->execute();
126-
127-
$this->createNodes($this->getRootNode(), $iteration->getParameter('nb_nodes'), array(
128-
'string' => 'Hello',
129-
'number' => 10,
130-
'hello' => 'goodbye',
131-
'goodbye' => 'hello',
132-
), $iteration->getParameter('sections'), 0);
133-
134-
$this->getSession()->save();
135-
}
76+
$results = $query->execute();
13677

137-
public function beforeAppendNode(Iteration $iteration)
138-
{
139-
// do not recreate nodes in the same iteration set
140-
if ($iteration->getIndex() > 0) {
141-
return;
78+
foreach ($results as $row) {
79+
foreach ($props as $prop) {
80+
$row->getValue($prop);
81+
}
14282
}
143-
144-
$this->createNodes($this->getRootNode(), 1, array(
145-
'my_new_property' => 'foobar',
146-
), 1, 10000);
147-
148-
$this->getSession()->save();
14983
}
15084

151-
public function provideQueryVariableProperties()
85+
public function provideQueries()
15286
{
15387
return array(
15488
array(
155-
'query' => 'SELECT * FROM [nt:unstructured]',
156-
),
157-
array(
158-
'query' => 'SELECT string FROM [nt:unstructured]',
159-
),
160-
array(
161-
'query' => 'SELECT string, number FROM [nt:unstructured]',
162-
),
163-
array(
164-
'query' => 'SELECT string, number, hello, goodbye FROM [nt:unstructured]',
165-
),
166-
);
167-
}
168-
169-
public function provideNbNodes()
170-
{
171-
return array(
172-
array(
173-
'nb_nodes' => 1,
174-
'sections' => 1,
175-
),
176-
array(
177-
'nb_nodes' => 10,
178-
'sections' => 1,
179-
),
180-
array(
181-
'nb_nodes' => 100,
182-
'sections' => 1,
89+
'query' => 'SELECT valves FROM [nt:unstructured]',
18390
),
18491
);
18592
}
18693

187-
public function provideNbNodesWithSections()
94+
public function provideProperties()
18895
{
18996
return array(
19097
array(
191-
'nb_nodes' => 100,
192-
'sections' => 2,
98+
'props' => array('valves'),
19399
),
194100
array(
195-
'nb_nodes' => 1000,
196-
'sections' => 2,
101+
'props' => array('valves', 'thistles'),
197102
),
198103
array(
199-
'nb_nodes' => 100,
200-
'sections' => 4,
104+
'props' => array('valves', 'thistles', 'toppings', 'troikas'),
201105
),
202106
array(
203-
'nb_nodes' => 1000,
204-
'sections' => 4,
107+
'props' => array('valves', 'thistles', 'toppings', 'troikas', 'underrate', 'worksheets'),
205108
),
206109
);
207110
}

0 commit comments

Comments
 (0)