Redis

edis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。
Redis 是一个高性能的key-value数据库。 redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部 分场合可以对关系数据库起到很好的补充作用。它提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erlang等客户端,使用很方便。[1] 
Redis支持主从同步。数据可以从主服务器向任意数量的从服务器上同步,从服务器可以是关联其他从服务器的主服务器。这使得Redis可执行单层树复制。存盘可以有意无意的对数据进行写操作。由于完全实现了发布/订阅机制,使得从数据库在任何地方同步树时,可订阅一个频道并接收主服务器完整的消息发布记录。同步对读取操作的可扩展性和数据冗余很有帮助。



Redis-benchmark是官方自带的Redis性能测试工具,可以有效的测试Redis服务的性能。


指令说明:

  1. Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]  
  2.   
  3. -h <hostname>      Server hostname (default 127.0.0.1)  
  4. -p <port>          Server port (default 6379)  
  5. -s <socket>        Server socket (overrides host and port)  
  6. -c <clients>       Number of parallel connections (default 50)  
  7. -n <requests>      Total number of requests (default 10000)  
  8. -d <size>          Data size of SET/GET value in bytes (default 2)  
  9. -k <boolean>       1=keep alive 0=reconnect (default 1)  
  10. -r <keyspacelen>   Use random keys for SET/GET/INCR, random values for SADD  
  11.   Using this option the benchmark will get/set keys  
  12.   in the form mykey_rand:000000012456 instead of constant  
  13.   keys, the <keyspacelen> argument determines the max  
  14.   number of values for the random number. For instance  
  15.   if set to 10 only rand:000000000000 - rand:000000000009  
  16.   range will be allowed.  
  17. -P <numreq>        Pipeline <numreq> requests. Default 1 (no pipeline).  
  18. -q                 Quiet. Just show query/sec values 只显示每秒钟能处理多少请求数结果  
  19. --csv              Output in CSV format  
  20. -l                 Loop. Run the tests forever 永久测试  
  21. -t <tests>         Only run the comma separated list of tests. The test  
  22.                     names are the same as the ones produced as output.  
  23. -I                 Idle mode. Just open N idle connections and wait.  

实例:

redis-benchmark -h 127.0.0.1 -p 6379 -q -d 100  
SET/GET 100 bytes 检测host为127.0.0.1 端口为6379的redis服务器性能


redis-benchmark -h 127.0.0.1 -p 6379 -c 5000 -n 100000 
5000个并发连接,100000个请求,检测host为127.0.0.1 端口为6379的redis服务器性能 




benchmark工具测试信息:
测试命令:
redis-benchmark -n 100000 -c 60
向redis服务器发送100000个请求,每个请求附带60个并发客户端
结果(部分):
====== SET ======
对集合写入测试
  100000 requests completed in 2.38 seconds
100000个请求在2.38秒内完成
  60 parallel clients
每次请求有60个并发客户端
  3 bytes payload
每次写入3个字节的数据
  keep alive: 1
保持一个连接,一台服务器来处理这些请求


93.06% <= 15 milliseconds
99.96% <= 31 milliseconds
99.98% <= 46 milliseconds
99.99% <= 62 milliseconds
100.00% <= 62 milliseconds
所有请求在62毫秒内完成
42105.26 requests per second
每秒处理42105.26次请求


  1. [root@localhost ~]# redis-benchmark -h 127.0.0.1 -p 6379 -c 5000 -n 100000  -d 100 -q  
  2. PING_INLINE: 34506.55 requests per second  
  3. PING_BULK: 34059.95 requests per second  
  4. SET: 31959.09 requests per second  
  5. GET: 31466.33 requests per second  
  6. INCR: 33311.12 requests per second  
  7. LPUSH: 29265.44 requests per second  
  8. LPOP: 36968.58 requests per second  
  9. SADD: 32030.75 requests per second  
  10. SPOP: 33344.45 requests per second  
  11. LPUSH (needed to benchmark LRANGE): 29735.36 requests per second  
  12. LRANGE_100 (first 100 elements): 16116.04 requests per second  
  13. LRANGE_300 (first 300 elements): 6659.56 requests per second  
  14. LRANGE_500 (first 450 elements): 4108.29 requests per second 

posted on 2016-06-01 10:55  王大王  阅读(126)  评论(0编辑  收藏  举报

导航