Skip to content

Instantly share code, notes, and snippets.

@misterion
Created December 4, 2015 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterion/78793fe1f536332dc0e0 to your computer and use it in GitHub Desktop.
Save misterion/78793fe1f536332dc0e0 to your computer and use it in GitHub Desktop.
<?php
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('max_execution_time', 0);
ini_set('memory_limit', '3072M');
$hashWrite = /** @lang Lua */ <<<LUA
for i = 0, ARGV[1], 1 do
redis.call('hset', 'test', i, i);
end
LUA;
$hashRead = /** @lang Lua */ <<<LUA
for i = 0, ARGV[1], 1 do
redis.call('hget', 'test', i);
end
return redis.call('hlen', 'test');
LUA;
$hashWriteStr = /** @lang Lua */ <<<LUA
local longString = string.rep('x', 17000);
for i = 0, ARGV[1], 1 do
redis.call('hset', 'test', i, longString .. i);
end
LUA;
$hashSuite = [
['write', $hashWrite],
['read', $hashRead]
];
$redis = new \Redis();
$redis->connect('192.168.1.133', 6379);
$redis->config('SET', 'hash-max-ziplist-entries', 1);
$redis->config('SET', 'hash-max-ziplist-value', 1000000);
testSuite($redis, 'hashmap', $hashSuite);
$redis->config('SET', 'hash-max-ziplist-entries', 100000);
$redis->config('SET', 'hash-max-ziplist-value', 1000000);
testSuite($redis, 'ziplist', $hashSuite);
function testSuite(Redis $redis, $prefix, array $suites) {
$redis->flushAll();
foreach ($suites as $entry) {
$ret = [];
list($name, $script) = $entry;
for ($i = 0; $i < 30000; $i += 500) {
runTest($redis, $ret, $i, $script);
}
file_put_contents($prefix . $name . '.csv', formatedData($ret));
}
}
function formatedData(array $data) {
$out = '';
foreach($data as $size => $results) {
$out .= $size . ';' . $results[0] . ';' . $results[1] . PHP_EOL;
}
return $out;
}
function runTest(Redis $redis, array &$ret, $size, $script) {
echo "Running pass $size\n";
$memoryBefore = $redis->info('memory');
$before = microtime(true);
$redis->eval($script, [$size]);
$duration = microtime(true) - $before;
$usedMemory = $redis->info('memory')['used_memory'] - $memoryBefore['used_memory'];
$ret[$size] = [$duration, $usedMemory];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment