Redis 性能比 memcached redis好吗?有哪些网站采用 Redis

对redis与memcached性能比较的三个试验 - 阿文 - ITeye技术网站
博客分类:
试验场景一:要对同一个list实时添加元素,且放入缓存中。代码如下:
public void testMemCacheAndRedis() {
this.testInsert(1000);
public void testInsert(int size) {
MemCached memCached = (MemCached) ctx.getBean("configMemCache");
memCached.flushAll();
long before = System.currentTimeMillis();
List&Integer& list = new ArrayList&Integer&();
for (int i = 0; i & i++) {
list.add(i);
memCached.put("test", list);
long end = System.currentTimeMillis();
RedisTemplate&String, Object& redisTemplate = (RedisTemplate&String, Object&) ctx.getBean("bubbleRedisTemplate");
redisTemplate.delete("test123");
long before2 = System.currentTimeMillis();
for (int i = 0; i & i++) {
redisTemplate.boundListOps("test123").leftPush(i);
long end2 = System.currentTimeMillis();
System.out.println("memcached use time is " + (end - before));
System.out.println("redis use time is " + (end2 - before2));
当n=1000时的任意3次打印结果:
=============================================
memcached use time is 6282
redis use time is 1156
memcached use time is 6547
redis use time is 1172
memcached use time is 6234
redis use time is 1375
当n=2000时的任意3次打印结果:
=============================================
memcached use time is 22313
redis use time is 2328
memcached use time is 22969
redis use time is 2907
memcached use time is 22938
redis use time is 2234
当n=3000时的任意3次打印结果:
=============================================
memcached use time is 48859
redis use time is 3297
memcached use time is 48156
redis use time is 4547
memcached use time is 47765
redis use time is 3375
试验一结论(只对本次试验负责):当n在20条以内时,两者差异不大,但当n大于20时,redis在性能上的优势就会逐渐体现出来。
试验场景二:对程序做些稍许的改动,即将memCached.put("xwq", list);这一行移到for循环外面执行,代码如下:
public void testMemCacheAndRedis() {
this.testBatchInsert(3000);
public void testBatchInsert(int size) {
MemCached memCached = (MemCached) ctx.getBean("configMemCache");
memCached.flushAll();
long before = System.currentTimeMillis();
List&Integer& list = new ArrayList&Integer&();
for (int i = 0; i & i++) {
list.add(i);
memCached.put("test", list);
long end = System.currentTimeMillis();
RedisTemplate&String, Object& redisTemplate = (RedisTemplate&String, Object&) ctx.getBean("bubbleRedisTemplate");
redisTemplate.delete("test123");
long before2 = System.currentTimeMillis();
for (int i = 0; i & i++) {
redisTemplate.boundListOps("test123").leftPush(i);
long end2 = System.currentTimeMillis();
System.out.println("memcached use time is " + (end - before));
System.out.println("redis use time is " + (end2 - before2));
我们再做下试验:
当n=1000时的任意3次打印结果:
===================================================
memcached use time is 15
redis use time is 1188
memcached use time is 32
redis use time is 1188
memcached use time is 31
redis use time is 1234
当n=2000时的任意3次打印结果:
===================================================
memcached use time is 47
redis use time is 2437
memcached use time is 31
redis use time is 2344
memcached use time is 47
redis use time is 2265
但n=3000时的任意3次打印结果:
===================================================
memcached use time is 62
redis use time is 3406
memcached use time is 47
redis use time is 3391
memcached use time is 47
redis use time is 3688
试验二结论(只对本次试验负责):由此可以看出,memcached一次性将list放入到缓存中,比redis每次更新性能是要高很多的。
试验场景三:对同样大小的两个list,同时进行相同次数的读操作,代码如下:
& @Test
& public void testMemCacheAndRedis() {
&&& // this.testInsert(3000);
&&& // this.testBatchInsert(3000);
&&& this.testRead(200);
& }
& public void testRead(int size) {
&&& MemCached memCached = (MemCached) ctx.getBean("configMemCache");
&&& memCached.flushAll();
&&& List&Integer& list = new ArrayList&Integer&();
&&& for (int i = 0; i & 1000; i++) {
&&&&& list.add(i);
&&& }
&&& memCached.put("test", list);
&&& long before = System.currentTimeMillis();
&&& for (int i = 0; i & i++) {
&&&&& memCached.get("test");
&&& }
&&& long end = System.currentTimeMillis();
&&& RedisTemplate&String, Object& redisTemplate = (RedisTemplate&String, Object&) ctx.getBean("bubbleRedisTemplate");
&&& redisTemplate.delete("test123");
&&& for (int i = 0; i & 1000; i++) {
&&&&& redisTemplate.boundListOps("test123").leftPush(i);
&&& }
&&& long before2 = System.currentTimeMillis();
&&& for (int i = 0; i & i++) {
&&&&& redisTemplate.boundListOps("xwq123").range(0, -1);
&&& }
&&& long end2 = System.currentTimeMillis();
&&& System.out.println("memcached use time is " + (end - before));
&&& System.out.println("redis use time is " + (end2 - before2));
& }
当n=100时的任意3次打印结果:
============================================
memcached use time is 6765
redis use time is 281
memcached use time is 2187
redis use time is 297
memcached use time is 9547
redis use time is 313
当n=200时的任意3次打印结果:
============================================
memcached use time is 34250
redis use time is 546
memcached use time is 12171
redis use time is 547
memcached use time is 8297
redis use time is 516
当n=500时的任意3次打印结果:
============================================
memcached use time is 69437
redis use time is 1297
memcached use time is 43781
redis use time is 1516
memcached use time is 37750
redis use time is 1281
试验三结论(只对本次试验负责):同样是从缓存中读取数据,redis的性能是要远远高于memcached。
综上所述结论(只对本次次试验负责):通过上述三次试验,redis在读操作和写操作上是全面领先memcached的。但有一点,memcached可以一次性将集合的数据放入自己的缓存中,而redis却不行(有还是木有?),所以memcached并不是一无是处的,在很多场景下,二者是需要交叉使用的,要根据实际场景进行取舍。
wenqiang06ky
浏览: 34110 次
来自: 杭州
下面这个文章讲述了 ehcache,redis,memcach ...
针对list的测试,你是把每个元素挨个放到redis,把lis ...
yw123456 写道table_name 后面的表名必须全部 ...
也可以用oracle中动态SQL语句啊。
table_name 后面的表名必须全部要大写表名。否则查不到 ...Redis 性能比 Memcached 好吗?有哪些网站采用 Redis_百度知道
Redis 性能比 Memcached 好吗?有哪些网站采用 Redis
新浪用redis能说Redis功能比 Memcached更加强供使用场合更
知道智能回答机器人
我是知道站内的人工智能,可高效智能地为您解答问题。很高兴为您服务。
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Redis 性能比 Memcached 好吗?有哪些网站采用 Redis_百度知道
Redis 性能比 Memcached 好吗?有哪些网站采用 Redis
新浪用redis能说Redis功能比 Memcached更加强供使用场合更
知道智能回答机器人
我是知道站内的人工智能,可高效智能地为您解答问题。很高兴为您服务。
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁您的位置: >
Memcached真的过时了吗?Redis与Memcached的比较
[导读]这两年Redis火得可以,Redis也常常被当作Memcached的挑战者被提到桌面上来。关于Redis与Memcached的比较更是比比皆是。然而,Redis真的在功能、性能以及内存使用效率上都超越了Memcached吗? 下面内容来自Redis作者在...
这两年Redis火得可以,Redis也常常被当作Memcached的挑战者被提到桌面上来。关于Redis与Memcached的比较更是比比皆是。然而,Redis真的在功能、性能以及内存使用效率上都超越了Memcached吗?
下面内容来自Redis作者在stackoverflow上的一个回答,对应的问题是《》(相比Redis,Memcached真的过时了吗?)
You should not care too much about performances. Redis is faster per core with small values, but memcached is able to use multiple cores with a single executable and TCP port without help from the client. Also memcached is faster with big values in the order of 100k. Redis recently improved a lot about big values (unstable branch) but still memcached is faster in this use case. The point here is: nor one or the other will likely going to be your bottleneck for the query-per-second they can deliver.
没有必要过多的关心性能,因为二者的性能都已经足够高了。由于Redis只使用单核,而Memcached可以使用多核,所以在比较上,平均每一个核上Redis在存储小数据时比Memcached性能更高。而在100k以上的数据中,Memcached性能要高于Redis,虽然Redis最近也在存储大数据的性能上进行优化,但是比起Memcached,还是稍有逊色。说了这么多,结论是,无论你使用哪一个,每秒处理请求的次数都不会成为瓶颈。(比如瓶颈可能会在网卡)
You should care about memory usage. For simple key-value pairs memcached is more memory efficient. If you use Redis hashes, Redis is more memory efficient. Depends on the use case.
如果要说内存使用效率,使用简单的key-value存储的话,Memcached的内存利用率更高,而如果Redis采用hash结构来做key-value存储,由于其组合式的压缩,其内存利用率会高于Memcached。当然,这和你的应用场景和数据特性有关。
You should care about persistence and replication, two features only available in Redis. Even if your goal is to build a cache it helps that after an upgrade or a reboot your data are still there.
如果你对数据持久化和数据同步有所要求,那么推荐你选择Redis,因为这两个特性Memcached都不具备。即使你只是希望在升级或者重启系统后缓存数据不会丢失,选择Redis也是明智的。
You should care about the kind of operations you need. In Redis there are a lot of complex operations, even just considering the caching use case, you often can do a lot more in a single operation, without requiring data to be processed client side (a lot of I/O is sometimes needed). This operations are often as fast as plain GET and SET. So if you don&t need just GEt/SET but more complex things Redis can help a lot (think at timeline caching).
当然,最后还得说到你的具体应用需求。Redis相比Memcached来说,拥有更多的数据结构和并支持更丰富的数据操作,通常在Memcached里,你需要将数据拿到客户端来进行类似的修改再set回去。这大大增加了网络IO的次数和数据体积。在Redis中,这些复杂的操作通常和一般的GET/SET一样高效。所以,如果你需要缓存能够支持更复杂的结构和操作,那么Redis会是不错的选择。
来源:(其他人的回答同样值得一看)
转载请注明来源:
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系我们,我们会尽快予以更正。
上一篇:下一篇:
了解这些字:
··········
··········
··········
··········}

我要回帖

更多关于 memcached vs redis 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信