redis memcache 性能比较

From: http://blog.51yip.com/cache/1318.html

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

1,redis读写内存比memcache快

2,memcache读写内存比redis快

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

所以我做了一下测试。关于redis和memcache的安装,请参考

linux redis 安装配置, 以及redis php扩展

linux memcache 安装

1,redis的测试文件

查看复制打印?
  1. <?php  
  2. function get_data (){  
  3.    mysql_connect("localhost""root"""or die("Could not connect: " . mysql_error());  
  4.    mysql_select_db("ugc");  
  5.   
  6.    $result = mysql_query("SELECT task_id FROM ugc_tasks");  
  7.    $return = array();  
  8.    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {  
  9.       $return[] = $row;  
  10.    }  
  11.   
  12.    mysql_free_result($result);  
  13.    return $return;  
  14. }  
  15.   
  16. $redis = new redis();  
  17. $redis->connect('127.0.0.1', 6379);  
  18.   
  19. if ($redis->exists('test')) {  
  20.    $value = $redis->get("test");  
  21. }else{  
  22.    $value = get_data();  
  23.    $redis->set('test',json_encode($value));  
  24. }  
  25.   
  26. print_r(json_decode($value));  
  27. ?>  

2,redis的测试结果

第一次
root@ubuntu:/home/zhangying/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/zhangying/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/zhangying/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

3,memcache测试文件

查看复制打印?
  1. <?php  
  2. function get_data (){  
  3.    mysql_connect("localhost""root"""or die("Could not connect: " . mysql_error());  
  4.    mysql_select_db("ugc");  
  5.   
  6.    $result = mysql_query("SELECT task_id FROM ugc_tasks");  
  7.    $return = array();  
  8.    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {  
  9.        $return[] = $row;  
  10.    }  
  11.   
  12.    mysql_free_result($result);  
  13.    return $return;  
  14. }  
  15.   
  16. $mem = new Memcache;  
  17. $mem->connect("127.0.0.1",11211) or die ("Could not connect");  
  18. $value = $mem->get('test1');  
  19. if (emptyempty($value)) {  
  20.    $value = json_encode(get_data());  
  21.    $mem->set('test1',$value,0, 600);  
  22. }  
  23.   
  24. print_r(json_decode($value));  
  25. ?>  

4,memcache测试结果

第一次

root@ubuntu:/home/zhangying/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/zhangying/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/zhangying/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

从上面比较结果,可以看出,memcache比redis快的。redis对key,value的管理,更灵活。有很多人把redis归于nosql的范围,细细想,还真是那么一回事。redis还可以把内在中的数据,放到磁盘中,这一点上,redis更像memcachedb。关于使用哪一种,看个人喜好而定了。


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/403192.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SQL性能优化案例分析

这段时间做一个SQL性能优化的案例分析&#xff0c; 整理了一下过往的案例&#xff0c;发现一个比较有意思的&#xff0c;拿出来给大家分享。 这个项目是我在项目开展2期的时候才加入的&#xff0c; 之前一期是个金融内部信息门户&#xff0c; 里面有个功能是收集各个上市公司的…

前端下载图片、pdf、excel、world文件;前端下载图片和pdf文件;前端a标签下载图片和pdf文件;下载文件名称不生效原因。

参考文章1 参考文章2 以下的下载是&#xff0c;拿到了后端给的下载图片的接口地址url > 方法1&#xff1a;将文本或者JS字符串通过 Blob 转换成二进制下载 优点&#xff1a;可以下载&#xff0c;也可以保存名称。 //文件流参数和图片名称 function downloadTxt(str, filenam…

JavaBean规范

&#xff08;1&#xff09;JavaBean 类必须是一个公共类&#xff0c;并将其访问属性设置为 public &#xff0c;如&#xff1a; public class user{......}&#xff08;2&#xff09;JavaBean 类必须有一个空的构造函数&#xff1a;类中必须有一个不带参数的公用构造器 &#…

USB 设备类代码表

USB Class Codes 官方地址&#xff1a;http://www.usb.org/developers/defined_classUSB defines class code information that is used to identify a device’s functionality and to nominally load a device driver based on that functionality. The information is conta…

Redis安装和使用指南

From: http://mwt198668.blog.163.com/blog/static/48803692201132141755962/ Redis安装指南 作者&#xff1a;Red_Ant 时间&#xff1a;2011-04-20 简 介 redis是一个key-value存储系统。和Memcached类似&#xff0c;它支持存储的value类型相对更多&#xff0c;包括string…

员工打卡课后小项目

public class Fm{//员工类public string Id { get; set; }public string Name { get; set; }public int Age { get; set; }public string Gender { get; set; }} public class SI{//打卡类public string Name { get; set; }public DateTime Begin { get; set; }public DateTime…

通过后端接口,预览文件流图片;预览和下载文件流

后端接口返回的是文件流 1.如果是pdf等文件&#xff0c;通过iframe结合文件流&#xff0c;做到文件的下载和预览 // 预览文件openPdf1 () {// 后端下载文件流的地址接口let url G_CGI_PHP.group.documentDownload ?id this.paymentImage1const newWindow window.open()ne…

SAP里删除trace文件的方法

1. stat.DAT&#xff1a;性能统计文件。 这个统计文件增长很快&#xff0c;不小心就涨到900MB以上。 对应的OS路径: D:\usr\sap\DEV\DVEBMGS00\data 处理方法: ST03N -> Expert mode -> Collector and Perfromance DB ->Statistics Records & File -> D…

HID设备类详解

HID设备类 Base Class 03h (HID – Human Interface Device) This base class is defined for devices that conform to the HID Device Class Specification found on the USB-IF website. That specification defines the usable set of SubClass and Protocol values. V…

DatePicker动态设置picker-options 中的disabledDate属性操作;

一、场景&#xff1a; 有两个时间选择器A和B。A的时间任意选&#xff0c;B的时间必须选择A之后的时间。此时就需要给B设置可选时间区间&#xff0c;而且是动态的值&#xff0c;既动态设置picker-options 中的disabledDate。 二、代码片段 html&#xff1a; <el-col :span&…

Linux使用笔记: 设置Samba服务器中新建文件/目录的权限

From: http://easwy.com/blog/archives/set-file-directory-attribute-for-linux-samba/ 通过Samba服务器实现windows和Linux之间的文件共享&#xff0c;相信是绝大多数人的选择。通常我们都会使用Samba的缺省配置&#xff0c;这样&#xff0c;每次通过Samba从Windows向Linux中…

[转]序列化悍将Protobuf-Net,入门动手实录

最近在研究web api 2&#xff0c;看了一篇文章&#xff0c;讲解如何提升性能的&#xff0c; 在序列化速度的跑分中&#xff0c;Protobuf一骑绝尘&#xff0c;序列化速度快&#xff0c;性能强&#xff0c;体积小&#xff0c;所以打算了解下这个利器 1&#xff1a;安装篇 谷歌官方…

单线程写多线程读安全的结构体

大型网络游戏服务器的逻辑大多采用单线程设计&#xff0c;典型的就是一个线程处理一个区域(地图),跨区域通过跳转实现&#xff0c;这样&#xff0c;不同区域的对象在逻辑上是不发生交互的。 这样在一台服务器上开启N个线程就可以处理N个区域。但一个线程处理一个区域毕竟有其瓶…

Linux 内核打印级别

printk的打印级别 #define KERN_EMERG "<0>" /* system is unusable */ #define KERN_ALERT "<1>" /* action must be taken immediately */ #define KERN_CRIT "<2>" /* critical conditions */ #define KERN_ERR "…

时间戳转日期;日期转时间戳;

一、 拓展:如何用js将日期转换成时间戳 new Date(2022-06-01).getTime() //1654041600000 //这个safari无法将时分秒转时间戳// 推荐用这个&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&…

swoole之代码热更新实现

From: http://www.th7.cn/Program/php/201405/211057.shtml 持续的思考: 本人参与的swoole项目有幸被很多朋友使用&#xff0c;我也大力向周边的一些朋友推荐&#xff0c;随着swoole的版本迭代更新&#xff0c;已经足够稳定了&#xff0c;在阿里&#xff0c;腾讯&#xff0c;yy…

题目1168:字符串的查找删除

题目1168&#xff1a;字符串的查找删除 时间限制&#xff1a;1 秒 内存限制&#xff1a;32 兆 特殊判题&#xff1a;否 提交&#xff1a;5092 解决&#xff1a;2097 题目描述&#xff1a;给定一个短字符串&#xff08;不含空格&#xff09;&#xff0c;再给定若干字符串&#x…

C# 文件操作详解(三)---------Directory类

前面两篇介绍了File类和FileInfo类&#xff0c;对于文件的操作基本够用&#xff0c;但是后面还会补充一下FileStream相关的操作&#xff0c;例如StreamReader和StreamWriter的内容。本文主要介绍Directory类的使用&#xff0c;让我们一起看一下Directory类为我们提供了哪些操作…

js实现复制并能保留原格式粘贴;vue中点击复制粘贴功能;vue复制功能(不需要插件);

使用场景&#xff1a;vue项目中遇到点击按钮&#xff0c;复制文本的功能。复制成功后可以黏贴。 <div click"copyDesc">复制</div>methods:{copyDesc () {let url 这是复制的内容&#xff0c;可以是data的变量值或传递的参数等换行文字1换行文字2 let…

Libusb开发教程一 安装

1. 从官网下载需要使用的离线资源包&#xff1a; 进入 libusb.info 的 Download 页 下载 libusb-1.0.9.tar.bz2 下载 libusb-compat-0.1.4.tar.bz2 2. 实验平台 OS: Ubuntu16.04 Kernel: 4.4.0 3. 安装过程 <1> 拷贝步骤一中的离线包到 Linux 系统目录&#xff0c;一般…