redis memcache 性能比较
来源:互联网 发布:python开发实战1200例 编辑:程序博客网 时间:2024/06/06 03:36
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的测试文件
- <?php
- function get_data (){
- mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
- mysql_select_db("ugc");
- $result = mysql_query("SELECT task_id FROM ugc_tasks");
- $return = array();
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $return[] = $row;
- }
- mysql_free_result($result);
- return $return;
- }
- $redis = new redis();
- $redis->connect('127.0.0.1', 6379);
- if ($redis->exists('test')) {
- $value = $redis->get("test");
- }else{
- $value = get_data();
- $redis->set('test',json_encode($value));
- }
- print_r(json_decode($value));
- ?>
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测试文件
- <?php
- function get_data (){
- mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
- mysql_select_db("ugc");
- $result = mysql_query("SELECT task_id FROM ugc_tasks");
- $return = array();
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $return[] = $row;
- }
- mysql_free_result($result);
- return $return;
- }
- $mem = new Memcache;
- $mem->connect("127.0.0.1",11211) or die ("Could not connect");
- $value = $mem->get('test1');
- if (emptyempty($value)) {
- $value = json_encode(get_data());
- $mem->set('test1',$value,0, 600);
- }
- print_r(json_decode($value));
- ?>
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。关于使用哪一种,看个人喜好而定了。
- redis memcache 性能比较
- memcache,redis,mongodb 比较
- Redis Memcache比较
- Memcache与Redis比较
- memcache redis 比较
- redis、mongodb、memcache比较
- Redis 与 Memcache比较
- Redis Memcache SSDB比较
- Redis Memcache SSDB比较
- redis、mongdb、memcache比较
- Redis与memcache比较
- redis和memcache比较
- Redis和Memcache比较
- ehcache memcache redis 比较
- redis和memcache比较
- redis memcache 性能测试
- memcache、apc性能比较
- Redis和Memcache的比较
- swift 快速奔跑的兔几 本节的内容是:iOS上基于文档的应用程序
- Android合并文件的三种方式
- Ansj添加停用词表
- Boost.program_options简述
- 你了解 Assembly.Load 吗?
- redis memcache 性能比较
- C++设计模式[十八]观察者模式
- easyui-tooltip 提示框
- C++primer plus第六版课后编程练习答案6.1
- 旧智能手机各种妙用
- Leetcode171: Implement Trie (Prefix Tree)
- recover和restore的区别
- 【转载】浅谈MySql的存储引擎(表类型)
- CentOS7下Firewall常用命令