Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function testBenchmark()
- {
- $time = microtime(TRUE);
- $container = $this->createContainer('sharding');
- foreach ($container->getByType('Kdyby\Redis\ClientsPool') as $client) {
- $this->getClient($client); // flushdb
- }
- $containerFile = Nette\Reflection\ClassType::from($container)->getFileName();
- $containerClass = get_class($container);
- $statsFile = TEMP_DIR . '/stats.log';
- $this->threadStress(function () use ($containerFile, $containerClass, $statsFile) {
- require_once $containerFile;
- /** @var Nette\DI\Container|\SystemContainer $container */
- $container = new $containerClass();
- $container->initialize();
- Nette\Diagnostics\Debugger::enable(TRUE, TEMP_DIR);
- $cache = new \Nette\Caching\Cache($container->getByType('Kdyby\Redis\StorageRouter'));
- $stats = array('miss' => 0);
- // randomly read every 1000th key
- for ($i = 1; $i <= 10000; $i += 10) {
- $key = rand($i, $i + 10);
- $cache->load($key, function (&$dp) use ($key, $cache, &$stats) {
- $stats['miss'] += 1;
- $dp[$cache::TAGS] = array_unique(array(md5($key % 10000), md5($key % 1000), md5($key % 100), md5($key % 10)));
- return array_fill(0, 30, range('a', 'z'));
- });
- }
- /** @var \Kdyby\Redis\Diagnostics\Panel $panel */
- $panel = $container->getByType('Kdyby\Redis\Diagnostics\Panel');
- $stats['queries'] = $panel->getQueryCount();
- $stats['time'] = sprintf('%0.1f', $panel->getTotalTime()) . ' ms';
- file_put_contents($statsFile, json_encode($stats) . "\n", FILE_APPEND);
- }, 200, 5);
- var_dump(microtime(TRUE) - $time);
- }
Advertisement
Add Comment
Please, Sign In to add comment