php redis client 稳定性测试
一直有个想法,做一个只有redis作数据库的系统,一直对redis的功能比较赞赏,但不知道redis的单线程稳定性如何,之前测试过100万Key的写入锁,今天又测试了一下正常读写下redis cli的get稳定性。
结果看起来还可以,2万次左右的单次读取锁0.001秒,如果每次展示需要读取300次cache,整体来说,在redis上的时间损失也不超过0.1秒,跟mysql动则0.1秒的查询效率来看,还是快得多了。
但还不会做redis db集群和数据恢复,学习ing。
官方网站 http://redis.io/
Redis命令 http://redis.io/commands
Redis协议 http://redis.io/topics/protocol
NoSQLFan Redis资料汇总专题 http://blog.nosqlfan.com/html/3537.html
Ubuntu 12.04 Aspire,10G
[shell]
shuhai@Aspire:/wwwroot/php/redis$ cat /proc/meminfo
MemTotal: 10092540 kB
MemFree: 4093172 kB
Buffers: 629836 kB
Cached: 2685732 kB
[/shell]
redis版本
[shell]
shuhai@Aspire:/wwwroot/php/redis$ redis-cli -v
redis-cli 2.2.12
[/shell]
[shell]
shuhai@Aspire:/wwwroot/php/redis$ redis-server -v
Redis server version 2.2.12 (00000000:0)
[/shell]
测试一,读取锁时间
[shell]
shuhai@Aspire:/wwwroot/php/redis$ php locktest.php
60910 => 0.0011389255523682
10954 => 0.0012128353118896
6543 => 0.0011680126190186
599 => 0.0013341903686523
89891 => 0.0011501312255859
20667 => 0.001054048538208
94608 => 0.0011560916900635
127 => 0.0016088485717773
380 => 0.0011329650878906
6977 => 0.0019309520721436
21108 => 0.0011842250823975
31646 => 0.0012660026550293
143386 => 0.0012049674987793
[/shell]
[php]
<?php
$redis = new redis;
$redis->connect("tcp://127.0.0.1:6379");
$count = 0;
while(true)
{
$s = microtime(true);
$redis->get(‘shuhai’);
$e = microtime(true);
$t = $e-$s;
$count ++;
if($t > 0.001)
{
echo "$count => $t\n";
$count = 0;
}
}
[/php]
测试二,平均锁读取数量
[shell]
shuhai@Aspire:/wwwroot/php/redis$ php locktest.php
23260
18449.5
40499
30982
32170.6
32801.666666667
33552.428571429
31086.875
27664.333333333
28921.5
27306.545454545
25048.25
23313.923076923
22005.285714286
24101.866666667
26472.0625
25839.764705882
24858.722222222
26115.210526316
25114.75
24149.714285714
29368.954545455
[/shell]
[php]
shuhai@Aspire:/wwwroot/php/redis$ cat locktest.php
<?php
$redis = new redis;
$redis->connect("tcp://127.0.0.1:6379");
$count = 0;
while(true)
{
$s = microtime(true);
$redis->get(‘shuhai’);
$e = microtime(true);
$t = $e-$s;
$count ++;
if($t > 0.001)
{
$array[] = $count;
echo array_sum( $array ) / count( $array ) . "\n";
$count = 0;
}
}
[/php]