技术库 > 存储系统

php中memcache与memcached的区别

技术库:tec.5lulu.com

from:tec.5lulu.com

       说法一:

       两个不同版本的php的memcached的客户端

new memcache是pecl扩展库版本

new memcached是libmemcached版本

       功能差不多

       说法二:

       Memcache是什么?

       Memcache是一个自由和开放源代码、高性能、分配的内存对象缓存系统。用于加速动态web应用程序,减轻数据库负载。

       它可以应对任意多个连接,使用非阻塞的网络IO。由于它的工作机制是在内存中开辟一块空间,然后建立一个HashTable,Memcached自管理这些HashTable

       Memcached是简单而强大的。它简单的设计促进迅速部署,易于发展所面临的问题,解决了很多大型数据缓存。它的API可供最流行的语言。

       Memcache的知名用户有:LiveJournal、Wikipedia、Flickr、Bebo、Twitter、Typepad、Yellowbot、Youtube 等。

       Memcache官方网站:http://memcached.org/

       Memcached又是什么?

       Memcache是该系统的项目名称,Memcached是该系统的主程序文件,以守护程序方式运行于一个或多个服务器中,随时接受客户端的连接操作,使用共享内存存取数据。

       PHP中的Memcache是什么?

       php中的所讲的memcache是用于连接Memecached的客户端组件。

       简单的说一句话:Memcached 是一个服务(运行在服务器上的程序,监听某个端口),Memcache 是 一套访问Memcached的api

       两者缺一不可,不然无法正常运行。Memcache能在多台服务器上发挥很好的作用,同台服务器上用APCXcache效率是很可观的。

       同台服务器APC的效率是Memcached的7倍,APC效率比Memcached高是肯定的

1 Memcached 16% faster than Memcache?

       Nobody seemed to benchmark the two clients to see which one is faster and that is why I did just that. I tested both clients on the same machine with default settings in Ubuntu 12.04 for both the clients and the server. This is the benchmark script I used:

addServer('localhost', 11211);
$start = microtime(true);
foreach ($values as $k => $v) $m->set($k, $v, 3600);
$time = microtime(true)-$start;
echo "memcached set: $timen";
$start = microtime(true);
foreach ($values as $k => $v) $m->get($k);
$time = microtime(true)-$start;
echo "memcached get: $timen";
// Memcache
$m = new Memcache();
$m->addServer('localhost', 11211);
$start = microtime(true);
foreach ($values as $k => $v) $m->set($k, $v, 0, 3600);
$time = microtime(true)-$start;
echo "memcache set: $timen";
$start = microtime(true);
foreach ($values as $k => $v) $m->get($k);
$time = microtime(true)-$start;
echo "memcache get: $timen";

       And this is the output:


maurits@maurits-Aspire-X3960:~$ php memcache.php
memcache vs memcached: 10000 keys
memcached set: 0.91661500930786
memcached get: 0.86234307289124
memcache set: 1.0546097755432
memcache get: 1.0519700050354


       We clearly see that memcached is faster than memcache, but to find out how much faster we have to use xdebug profiling (install with “sudo apt-get install php5-xdebug”). We enabled xdebug profiling by setting “xdebug.profiler_enable = 1″ in “/etc/php5/conf.d/xdebug.ini”. After running the php script a “cachegrind.out” file is created in the “/tmp” directory. KCachegrind (install with “sudo apt-get install kcachegrind”) can analyze that file and make pretty graphs:

memcache_vs_memcached_3
picture 1: KCachegrind call graph

memcache_vs_memcached_2
       picture 2: KCachegrind callee map

memcache_vs_memcached
       picture 3: KCachegrind flat profile

Conclusion

       The difference is really small, so there are probably better reasons to choose the memcached client over the memcache client

phpmemcache与memcached的区别


标签: memcache memcached本文链接 http://tec.5lulu.com/detail/109kpn14mknh88r08.html

我来评分 :6.1
0

转载注明:转自5lulu技术库

本站遵循:署名-非商业性使用-禁止演绎 3.0 共享协议

www.5lulu.com