测试环境:
引用
REDHAT6.0 x86_64
Ruby Enterprise Edition version 1.8.7-2010.02
memcached 1.4.4
redis-2.4.6
Gems:
memcached(1.3.5)
hiredis (0.4.4)
Ruby Enterprise Edition version 1.8.7-2010.02
memcached 1.4.4
redis-2.4.6
Gems:
memcached(1.3.5)
hiredis (0.4.4)
相关配置:
memcached:-m 1024 -c 1024 -t 8
内存:1G,并发连接:1024,线程数:8
redis:默认配置,其中持久化数据部分关闭
loglevel warning
#save 900 1
#save 300 10
#save 60 10000
rdbcompression yes
测试方式:随即生成1000byte内的字符串,写入10万次。
memcached代码:
require 'rubygems' require 'memcached' @cache = Memcached.new('localhost:11211') 100000.times do |i| @cache.set "Test/#{i}", '0'*rand(1000) end
redis测试代码:
require 'rubygems' require 'hiredis' @cache = Hiredis::Connection.new @cache.connect("127.0.0.1", 6379) 100000.times do |i| @cache.write ['SET', "Test/#{i}", '0'*rand(1000)] @cache.read end
测试结果:
real user sys memcached 1x SET pipeline 10000 times 0.937s 0.305s 0.376s redis 1x SET pipeline 10000 times 1.218s 0.517s 0.318s memcached 10x SET pipeline 10000 times 1.954s 3.311s 1.794s redis 10x SET pipeline 10000 times 3.578s 5.610s 2.229s memcached 20x SET pipeline 10000 times 3.724s 6.789s 3.547s redis 20x SET pipeline 10000 times 7.024s 11.409s 4.259s memcached 1x SET pipeline 100000 times 8.434s 2.849s 3.165s redis 1x SET pipeline 100000 times 10.088s 3.315s 2.979s memcached 10x SET pipeline 100000 times 15.823s 21.094s 14.900s redis 10x SET pipeline 100000 times 26.971s 20.364s 14.673s memcached 20x SET pipeline 100000 times 28.992s 42.706s 29.173s redis 20x SET pipeline 100000 times 50.189s 40.969s 27.939s memcached 1x SET pipeline 1000000 times 1m16.988s 26.652s 27.189s redis 1x SET pipeline 1000000 times 1m39.096s 25.127s 28.373s memcached 10x SET pipeline 1000000 times 2m30.850s 3m22.393s 2m26.716s redis 10x SET pipeline 1000000 times 4m19.509s 2m46.179s 2m18.871s memcached 20x SET pipeline 1000000 times 6m22.883s 9m2.995s 6m5.845s redis 20x SET pipeline 1000000 times 12m55.556s 9m6.064s 6m56.633s
结论:
1、memcached的写入性能还是明显要高于redis,特别是多并发的时候,优势更明显!
2、redis server的占用一般在50%左右,memcached server的CPU占用150%左右
3、从总体CPU占用率上来说,redis的优势很明显,4核CPU的使用率没有超过20%,而memcached的CPU一直在50%左右。