diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-08-16 08:22:05 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-08-16 08:22:05 +0200 |
commit | 1a365e77dfb8825136626202b1df462731b42060 (patch) | |
tree | 1dc4468eaabf070e051e790a9e67a9a9a2c63d99 /vendor/ruflin/elastica/test/benchmark | |
parent | a72fd280f7acb4d2a1ba579a0f1b2b2ae8958530 (diff) |
Update to MediaWiki 1.25.2
Diffstat (limited to 'vendor/ruflin/elastica/test/benchmark')
5 files changed, 378 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/benchmark/BulkMemoryUsageTest.php b/vendor/ruflin/elastica/test/benchmark/BulkMemoryUsageTest.php new file mode 100644 index 00000000..23e6521f --- /dev/null +++ b/vendor/ruflin/elastica/test/benchmark/BulkMemoryUsageTest.php @@ -0,0 +1,46 @@ +<?php + +use Elastica\Client; +use Elastica\Document; + +class BulkMemoryUsageTest extends \PHPUnit_Framework_TestCase +{ + + /** + * Some memory usage stats + * + * Really simple and quite stupid ... + */ + public function testServersArray() + { + $client = new Client(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $data = array( + 'text1' => 'Very long text for a string', + 'text2' => 'But this is not very long', + 'text3' => 'random or not random?', + ); + + $startMemory = memory_get_usage(); + + for ($n = 1; $n < 10; $n++) { + $docs = array(); + + for ($i = 1; $i <= 3000; $i++) { + $docs[] = new Document(uniqid(), $data); + } + + $type->addDocuments($docs); + $docs = array(); + } + + unset($docs); + + $endMemory = memory_get_usage(); + + $this->assertLessThan(1.2, $endMemory/$startMemory); + } +} diff --git a/vendor/ruflin/elastica/test/benchmark/ClientTest.php b/vendor/ruflin/elastica/test/benchmark/ClientTest.php new file mode 100644 index 00000000..e7a040f7 --- /dev/null +++ b/vendor/ruflin/elastica/test/benchmark/ClientTest.php @@ -0,0 +1,31 @@ +<?php + +use Elastica\Client; +use Elastica\Document; + +class ClientTest extends \PHPUnit_Framework_TestCase +{ + + public function testServersArray() + { + $client = new Client(); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('test'); + + $start = microtime(true); + + for ($i = 1; $i <= 10000; $i++) { + $doc = new Document($i, array('test' => 1)); + $type->addDocument($doc); + } + + // Refresh index + $index->refresh(); + + $end = microtime(true); + + //echo $end - $start; + + } +} diff --git a/vendor/ruflin/elastica/test/benchmark/TransportTest.php b/vendor/ruflin/elastica/test/benchmark/TransportTest.php new file mode 100644 index 00000000..42d6ac0c --- /dev/null +++ b/vendor/ruflin/elastica/test/benchmark/TransportTest.php @@ -0,0 +1,252 @@ +<?php + +use Elastica\Client; +use Elastica\Request; +use Elastica\Document; +use Elastica\Query; +use Elastica\Type\Mapping; +use Elastica\Query\MatchAll as MatchAllQuery; +use Elastica\Filter\Term as TermFilter; + +class TransportTest extends \PHPUnit_Framework_TestCase +{ + protected $_max = 1000; + + protected $_maxData = 20; + + static protected $_results = array(); + + public static function setUpBeforeClass() + { + if (!defined('DEBUG')) { + define('DEBUG', true); + } else if (false == DEBUG) { + self::markTestIncomplete('DEBUG const is set to false, it prevents query time measuring.'); + } + } + + public static function tearDownAfterClass() + { + self::printResults(); + } + + /** + * @param array $config + * @return \Elastica\Type + */ + protected function getType(array $config) + { + $client = new Client($config); + $index = $client->getIndex('test'); + return $index->getType('test'); + } + + /** + * @dataProvider providerTransport + */ + public function testAddDocument(array $config, $transport) + { + $type = $this->getType($config); + $index = $type->getIndex(); + $index->create(array(), true); + + $times = array(); + for ($i = 0; $i < $this->_max; $i++) { + $data = $this->getData($i); + $doc = new Document($i, $data); + $result = $type->addDocument($doc); + $times[] = $result->getQueryTime(); + $this->assertTrue($result->isOk()); + } + + $index->refresh(); + + self::logResults('insert', $transport, $times); + } + + /** + * @depends testAddDocument + * @dataProvider providerTransport + */ + public function testRandomRead(array $config, $transport) + { + $type = $this->getType($config); + + $type->search('test'); + + $times = array(); + for ($i = 0; $i < $this->_max; $i++) { + $test = rand(1, $this->_max); + $query = new Query(); + $query->setQuery(new MatchAllQuery()); + $query->setFilter(new TermFilter(array('test' => $test))); + $result = $type->search($query); + $times[] = $result->getResponse()->getQueryTime(); + } + + self::logResults('random read', $transport, $times); + } + + /** + * @depends testAddDocument + * @dataProvider providerTransport + */ + public function testBulk(array $config, $transport) + { + $type = $this->getType($config); + + $times = array(); + for ($i = 0; $i < $this->_max; $i++) { + $docs = array(); + for ($j = 0; $j < 10; $j++) { + $data = $this->getData($i . $j); + $docs[] = new Document($i, $data); + } + + $result = $type->addDocuments($docs); + $times[] = $result->getQueryTime(); + } + + self::logResults('bulk', $transport, $times); + } + + /** + * @dataProvider providerTransport + */ + public function testGetMapping(array $config, $transport) + { + $client = new Client($config); + $index = $client->getIndex('test'); + $index->create(array(), true); + $type = $index->getType('mappingTest'); + + // Define mapping + $mapping = new Mapping(); + $mapping->setParam('_boost', array('name' => '_boost', 'null_value' => 1.0)); + $mapping->setProperties(array( + 'id' => array('type' => 'integer', 'include_in_all' => FALSE), + 'user' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array('type' => 'string', 'include_in_all' => TRUE), + 'fullName' => array('type' => 'string', 'include_in_all' => TRUE) + ), + ), + 'msg' => array('type' => 'string', 'include_in_all' => TRUE), + 'tstamp' => array('type' => 'date', 'include_in_all' => FALSE), + 'location'=> array('type' => 'geo_point', 'include_in_all' => FALSE), + '_boost' => array('type' => 'float', 'include_in_all' => FALSE) + )); + + $type->setMapping($mapping); + $index->refresh(); + + $times = array(); + for ($i = 0; $i < $this->_max; $i++) { + $response = $type->request('_mapping', Request::GET); + $times[] = $response->getQueryTime(); + } + self::logResults('get mapping', $transport, $times); + } + + public function providerTransport() + { + return array( + array( + array( + 'transport' => 'Http', + 'host' => 'localhost', + 'port' => 9200, + 'persistent' => false, + ), + 'Http:NotPersistent' + ), + array( + array( + 'transport' => 'Http', + 'host' => 'localhost', + 'port' => 9200, + 'persistent' => true, + ), + 'Http:Persistent' + ), + array( + array( + 'transport' => 'Thrift', + 'host' => 'localhost', + 'port' => 9500, + 'config' => array( + 'framedTransport' => false, + ), + ), + 'Thrift:Buffered' + ), + ); + } + + /** + * @param string $test + * @return array + */ + protected function getData($test) + { + $data = array( + 'test' => $test, + 'name' => array(), + ); + for ($i = 0; $i < $this->_maxData; $i++) { + $data['name'][] = uniqid(); + } + return $data; + } + + /** + * @param $name + * @param $transport + * @param array $times + */ + protected static function logResults($name, $transport, array $times) + { + self::$_results[$name][$transport] = array( + 'count' => count($times), + 'max' => max($times) * 1000, + 'min' => min($times) * 1000, + 'mean' => (array_sum($times) / count($times)) * 1000, + ); + } + + protected static function printResults() + { + echo sprintf( + "\n%-12s | %-20s | %-12s | %-12s | %-12s | %-12s\n\n", + 'NAME', + 'TRANSPORT', + 'COUNT', + 'MAX', + 'MIN', + 'MEAN', + '%' + ); + foreach (self::$_results as $name => $values) { + $means = array(); + foreach ($values as $times) { + $means[] = $times['mean']; + } + $minMean = min($means); + foreach ($values as $transport => $times) { + $perc = (($times['mean'] - $minMean) / $minMean) * 100; + echo sprintf( + "%-12s | %-20s | %-12d | %-12.2f | %-12.2f | %-12.2f | %+03.2f\n", + $name, + $transport, + $times['count'], + $times['max'], + $times['min'], + $times['mean'], + $perc + ); + } + echo "\n"; + } + } +} diff --git a/vendor/ruflin/elastica/test/benchmark/phpunit.benchmark.xml b/vendor/ruflin/elastica/test/benchmark/phpunit.benchmark.xml new file mode 100644 index 00000000..a530de35 --- /dev/null +++ b/vendor/ruflin/elastica/test/benchmark/phpunit.benchmark.xml @@ -0,0 +1,10 @@ +<phpunit backupGlobals="false" + backupStaticAttributes="false" + bootstrap="../bootstrap.php" + colors="true"> + <testsuites> + <testsuite name="Transport"> + <file>TransportTest.php</file> + </testsuite> + </testsuites> +</phpunit>
\ No newline at end of file diff --git a/vendor/ruflin/elastica/test/benchmark/phpunit.xhprof.xml b/vendor/ruflin/elastica/test/benchmark/phpunit.xhprof.xml new file mode 100644 index 00000000..2293155a --- /dev/null +++ b/vendor/ruflin/elastica/test/benchmark/phpunit.xhprof.xml @@ -0,0 +1,39 @@ +<phpunit backupGlobals="false" + backupStaticAttributes="true" + bootstrap="../bootstrap.php" + colors="true"> + <testsuites> + <testsuite name="Transport"> + <file>TransportTest.php</file> + </testsuite> + </testsuites> + <listeners> + <listener class="PHPUnit_Util_Log_XHProf" file="/home/munkie/Projects/phpunit-testlistener-xhprof/PHPUnit/Util/Log/XHProf.php"> + <arguments> + <array> + <element key="xhprofLibFile"> + <string>/var/www/xhprof/xhprof_lib/utils/xhprof_lib.php</string> + </element> + <element key="xhprofRunsFile"> + <string>/var/www/xhprof/xhprof_lib/utils/xhprof_runs.php</string> + </element> + <element key="xhprofWeb"> + <string>http://xhprof.local/</string> + </element> + <element key="appNamespace"> + <string>Elastica</string> + </element> + <element key="xhprofFlags"> + <string>XHPROF_FLAGS_CPU,XHPROF_FLAGS_MEMORY</string> + </element> + <element key="xhprofConfigFile"> + <string>/var/www/xhprof/xhprof_lib/config.php</string> + </element> + <element key="xhprofIgnore"> + <string>call_user_func,call_user_func_array</string> + </element> + </array> + </arguments> + </listener> + </listeners> +</phpunit>
\ No newline at end of file |