redismemcache非常像的,都是key,value的方式,将数据存放内存中。最近在学习redis,在网上看了一些这方面的资料,有三种观点:

  1. redis读写内存比memcache
  2. memcache读写内存比redis
  3. memcache读写内存比redis快,但是redis整体性能优于memcache

    所以我做了一下测试.

redis的测试结果

第一次

root@ubuntu:/home/yamatamain/download/webbench-1.5# webbench -c 10000 -t 30 http://localhost/php-redis/test_redis.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost/php-redis/test_redis.php
10000 clients, running 30 sec.
Speed=48324 pages/min, 40318471 bytes/sec.
Requests: 22599 susceed, 1563 failed.
telnet 127.0.0.1 6379

telnet登录一下,把test对应的值清除掉,保重测试的公平性

del test

第二次

root@ubuntu:/home/yamatamain/download/webbench-1.5# webbench -c 10000 -t 30 http://localhost/php-redis/test_redis.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost/php-redis/test_redis.php
10000 clients, running 30 sec.
Speed=53570 pages/min, 41217689 bytes/sec.
Requests: 23106 susceed, 3679 failed.
telnet 127.0.0.1 6379
del test

第三次

root@ubuntu:/home/yamatamain/download/webbench-1.5# webbench -c 10000 -t 30 http://localhost/php-redis/test_redis.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost/php-redis/test_redis.php
10000 clients, running 30 sec.
Speed=49450 pages/min, 39694073 bytes/sec.
Requests: 22301 susceed, 2424 failed.
telnet 127.0.0.1 6379
del test

memcache测试结果

第一次
root@ubuntu:/home/yamatamain/download/webbench-1.5# webbench -c 10000 -t 30 http://localhost/php-redis/test_memcache.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost/php-redis/test_memcache.php
10000 clients, running 30 sec.
Speed=61632 pages/min, 52228667 bytes/sec.
Requests: 29205 susceed, 1611 failed.
telnet 127.0.0.1 11211

telnet登录一下,把test1对应的值清除掉,保重测试的公平性

delete test1

第二次

root@ubuntu:/home/yamatamain/download/webbench-1.5# webbench -c 10000 -t 30 http://localhost/php-redis/test_memcache.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost/php-redis/test_memcache.php
10000 clients, running 30 sec.
Speed=64160 pages/min, 52601449 bytes/sec.
Requests: 29426 susceed, 2654 failed.
telnet 127.0.0.1 11211
delete test1

第三次

root@ubuntu:/home/yamatamain/download/webbench-1.5# webbench -c 10000 -t 30 http://localhost/php-redis/test_memcache.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://localhost/php-redis/test_memcache.php
10000 clients, running 30 sec.
Speed=65190 pages/min, 52506614 bytes/sec.
Requests: 29348 susceed, 3247 failed.
telnet 127.0.0.1 11211
delete test1

从上面比较结果,可以看出,memcacheredis快的。rediskey,value的管理,更灵活。有很多人把redis归于nosql的范围,细细想,还真是那么一回事。redis还可以把内在中的数据,放到磁盘中,这一点上,redis更像memcachedb。那么问题来了,到底是用redis还是memcached呢?

查到下面对应的资料,是来自redis作者的说法(stackoverflow上面)。

You should not care too much about performances. Redis is faster per corewith 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. 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.

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.

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).

翻译如下[1]:

  • 没有必要过多的关注性能。由于Redis只使用单核,而Memcached可以使用多核,所以在比较上,平均每一个核上Redis在存储小数据时比Memcached性能更高。而在100k以上的数据中,Memcached性能要高于Redis,虽然Redis最近也在存储大数据的性能上进行优化,但是比起Memcached,还是稍有逊色。说了这么多,结论是,无论你使用哪一个,每秒处理请求的次数都不会成为瓶颈。

  • 你需要关注内存使用率。对于key-value这样简单的数据储存,memcache的内存使用率更高。如果采用hash结构,redis的内存使用率会更高。当然,这些都依赖于具体的应用场景。

  • 你需要关注关注数据持久化和主从复制时,只有redis拥有这两个特性。如果你的目标是构建一个缓存在升级或者重启后之前的数据不会丢失的话,那也只能选择redis

  • 你应该关心你需要的操作。redis支持很多复杂的操作,甚至只考虑内存的使用情况,在一个单一操作里你常常可以做很多,而不需要将数据读取到客户端中(这样会需要很多的IO操作)。这些复杂的操作基本上和纯GETPOST操作一样快,所以你不只是需要GET/SET而是更多的操作时,redis会起很大的作用。

对于两者的选择还是要看具体的应用场景,如果需要缓存的数据只是key-value这样简单的结构时,我在项目里还是采用memcache,它也足够的稳定可靠。如果涉及到存储,排序等一系列复杂的操作时,毫无疑问选择redis

redismemecache的不同在于:

  • 存储方式
  • memecache 把数据全部存在内存之中,断电后会挂掉,数据不能超过内存大小
  • redis有部份存在硬盘上,这样能保证数据的持久性,支持数据的持久化(笔者注:有DUMPAOF日志两种持久化方式,在实际应用的时候,要特别注意配置文件快照参数,要不就很有可能服务器频繁满载做dump)。
  • 数据支持类型:
    • redis在数据支持上要比memecache多的多。
  • 使用底层模型不同:
    • 新版本的redis直接自己构建了VM 机制 ,因为一般的系统调用系统函数的话,会浪费一定的时间去移动和请求。
  • 运行环境不同:

    redis目前官方只支持LINUX,从而省去了对于其它系统的支持,这样的话可以更好的把精力用于本系统环境上的优化,虽然后来微软有一个小组为其写了补丁。但是没有放到主干上

个人总结一下,有持久化需求或者对数据结构和处理有高级要求的应用,选择redis,其他简单的key/value存储,选择memcache。

redis & memcache 性能比较的更多相关文章

  1. Redis 的性能幻想与残酷现实

    2011 年,当初选择 Redis 作为主要的内存数据存储,主要吸引我的是它提供多样的基础数据结构可以很方便的实现业务需求.另一方面又比较担心它的性能是否足以支撑,毕竟当时 Redis 还属于比较新的 ...

  2. Redis 的性能幻想与残酷现实(转)

    2011 年,当初选择 Redis 作为主要的内存数据存储,主要吸引我的是它提供多样的基础数据结构可以很方便的实现业务需求.另一方面又比较担心它的性能是否足以支撑,毕竟当时 Redis 还属于比较新的 ...

  3. Redis 的性能

    Redis 的性能幻想与残酷现实 2011 年,当初选择 Redis 作为主要的内存数据存储,主要吸引我的是它提供多样的基础数据结构可以很方便的实现业务需求.另一方面又比较担心它的性能是否足以支撑,毕 ...

  4. redis,memcache二者的区别是?(优缺点)

    Memcache和Redis区别: Redis中,并不是所有的数据都一直存储在内存中的,这是和Memcache相比一个最大的区别. Redis在很多方面具备数据库的特征,或者说就是一个数据库系统,而M ...

  5. 微擎开启redis memcache

    微擎开启redis memcache 2018年01月20日 14:39:54 luogan129 阅读数:2161更多 个人分类: 微信开发   版权声明:本文为博主原创文章,未经博主允许不得转载. ...

  6. redis memcache rabbitMQ

    Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动 ...

  7. Redis.Memcache和MongoDB区别?

    Memcached的优势: Memcached可以利用多核优势,单吞吐量极高,可以达到几十万QPS(取决于Key.value的字节大小以及服务器硬件性能,日常环境中QPS高峰大约在4-6w左右.)适用 ...

  8. Redis大幅性能提升之Batch批量读写

    Redis大幅性能提升之Batch批量读写 提示:本文针对的是StackExchange.Redis 一.问题呈现 前段时间在开发的时候,遇到了redis批量读的问题,由于在StackExchange ...

  9. 微擎开启redis memcache文档2

    微擎开启redis memcache 2018年01月20日 14:39:54 luogan129 阅读数:2161更多 个人分类: 微信开发   版权声明:本文为博主原创文章,未经博主允许不得转载. ...

随机推荐

  1. 从零开始学spring cloud(十) -------- hystrix简单代码示例

    一.官网文档阅读 较低级别的服务中的服务故障可能导致级联故障一直到用户. 当对特定服务的调用超过circuitBreaker.requestVolumeThreshold(默认值:20个请求)且失败百 ...

  2. 项目中的Launch_getSecurityEntitle_postlaunch

    研究透彻这个launch和postlaunch的执行过程才能改进他: //AppVTTicket.js ,launch:function(){ Ticketing.inciTick={}; this. ...

  3. JavaSE基础知识(5)—面向对象(方法的重写与重载)

    一.重写 1.说明 子类对继承过来的父类的方法进行改造,这种现象称为方法的重写或覆盖或覆写(Override) 2.要求 方法签名完全一致,jdk5.0之后,允许返回类型可以是子类类型,权限修饰符可以 ...

  4. 将python文件打包成exe可运行文件

    https://blog.csdn.net/douzhenwen/article/details/78886244

  5. error: command 'gcc' failed with exit status 1

    MacOS下想安装MySQL-Python,执行语句: sudo pip install MySQL-Python 遇到了如下错误信息: /Users/kaitlyn/anaconda3/envs/e ...

  6. centos中病毒

    嗯 很开中了病毒,,,而且这是第二次了.... 然后大佬说让我  crontab -l  一下 然后试了下 然后出来这个东东 执行下  crontab -r  这个  然后就crontab -l  就 ...

  7. redis---安装和开启和关闭

    转redis---安装和开启和关闭 http://blog.csdn.net/xing_____/article/details/38457463 系统:centos6.4 redis下载:http: ...

  8. eclipse Maven Dependencies 黑色背景说明

    记录工作点点滴滴,大到系统设计,源码分析,小到IDE设置. 这里要说的是eclipse中Maven Dependencies 为什么有些jar用黑色背景,如下图所示: 网上很多人说jar包在本地仓库不 ...

  9. 用turtle库实现汉诺塔问题~~~~~

    汉诺塔问题 问题描述和背景: 汉诺塔是学习"递归"的经典入门案例,该案例来源于真实故事.‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬ ...

  10. python3 第三十一章 - 模块

    1.什么是模块 如果从Python解释器退出并再次输入,您所做的定义(函数和变量)将丢失.因此,如果要编写一个稍长的程序,最好使用文本编辑器为解释器准备输入,并以该文件作为输入运行它.这称为创建脚本. ...