什么时候应该使用Memcache而不是Memcached?

时间:2021-02-08 16:05:48

It seems that PHP has two memcached libraries named memcache and memcached. What is the difference and how do you know which one to use? Is one outdated? It seems that memcached offers more methods so I would assume that means it has had the most development - but it also seems to require external C/C++ libraries so I'm not sure if I can install it.

PHP似乎有两个memcached库,分别是memcache和memcached。有什么区别,你怎么知道用哪一个?是一个过时的?memcached似乎提供了更多的方法,因此我认为这意味着它拥有了最多的开发——但它似乎也需要外部的C/ c++库,所以我不确定是否可以安装它。

It seems that memcache has been around longer, does not require additional libraries, and has pre-compiled binaries for even windows! I would think that it would be the better choice for now. However, being new to memcached (server) I'm not sure if there is some super important features in memcached (php) that make it worth the extra trouble.

似乎memcache已经存在很长时间了,不需要额外的库,甚至在windows中也有预编译的二进制文件!我认为现在是更好的选择。然而,作为memcached(服务器)的新手,我不确定memcached (php)中是否有一些非常重要的特性值得为其增加麻烦。

4 个解决方案

#1


241  

Memcached client library was just recently released as stable. It is being used by digg ( was developed for digg by Andrei Zmievski, now no longer with digg) and implements much more of the memcached protocol than the older memcache client. The most important features that memcached has are:

Memcached客户端库刚刚以稳定的方式发布。digg使用它(由Andrei Zmievski为digg开发,现在不再使用digg)并实现比旧的memcached客户端更多的memcached协议。memcached最重要的特性是:

  1. Cas tokens. This made my life much easier and is an easy preventive system for stale data. Whenever you pull something from the cache, you can receive with it a cas token (a double number). You can than use that token to save your updated object. If no one else updated the value while your thread was running, the swap will succeed. Otherwise a newer cas token was created and you are forced to reload the data and save it again with the new token.
  2. 中科院令牌。这使我的生活更加轻松,并且是一个针对陈旧数据的简单预防系统。无论何时从缓存中提取什么,您都可以用它接收一个cas令牌(一个双数)。您可以使用该令牌来保存更新后的对象。如果在线程运行时没有其他人更新该值,则交换将成功。否则,将创建一个新的cas令牌,您将*重新加载数据并使用新的令牌再次保存它。
  3. Read through callbacks are the best thing since sliced bread. It has simplified much of my code.
  4. 读过回调是有史以来最好的事情。它简化了我的大部分代码。
  5. getDelayed() is a nice feature that can reduce the time your script has to wait for the results to come back from the server.
  6. getdelay()是一个很好的特性,它可以减少脚本等待结果从服务器返回的时间。
  7. While the memcached server is supposed to be very stable, it is not the fastest. You can use binary protocol instead of ASCII with the newer client.
  8. 虽然memcached服务器应该非常稳定,但它不是最快的。对于较新的客户端,可以使用二进制协议代替ASCII。
  9. Whenever you save complex data into memcached the client used to always do serialization of the value (which is slow), but now with memcached client you have the option of using igbinary. So far I haven't had the chance to test how much of a performance gain this can be.
  10. 每当您将复杂数据保存到memcached时,客户端通常都会执行值的序列化(这是缓慢的),但是现在有了memcached客户端,您就可以选择使用igbinary了。到目前为止,我还没有机会去测试它能带来多少性能收益。

All of this points were enough for me to switch to the newest client, and can tell you that it works like a charm. There is that external dependency on the libmemcached library, but have managed to install it nonetheless on Ubuntu and Mac OSX, so no problems there so far.

所有这些都足以让我切换到最新的客户端,并可以告诉你,它就像一种魅力。libmemcached库有一个外部依赖项,但仍然设法将它安装到Ubuntu和Mac OSX上,因此到目前为止没有问题。

If you decide to update to the newer library, I suggest you update to the latest server version as well as it has some nice features as well. You will need to install libevent for it to compile, but on Ubuntu it wasn't much trouble.

如果您决定更新到更新的库,我建议您更新到最新的服务器版本,它也有一些不错的特性。你需要安装libevent来编译它,但是在Ubuntu上,这并不是什么麻烦。

I haven't seen any frameworks pick up the new memcached client thus far (although I don't keep track of them), but I presume Zend will get on board shortly.

到目前为止,我还没有看到任何框架使用新的memcached客户机(尽管我没有跟踪它们),但我认为Zend很快就会加入进来。

UPDATE

Zend Framework 2 has an adapter for Memcached which can be found here

Zend Framework 2有一个用于Memcached的适配器,可以在这里找到

#2


11  

This is 2013. Forget about the 2009 comments. Likewise, if you are running serious traffic loads, do not even contemplate how to make-do with a windows based memcache. When dealing with a very large scale (500+ front end web servers) and 20+ back end database servers and replicants (mysql & mssql mix), a farm of memcached servers (12 servers in group) supports multiple high volume OLTP applications answering 25K ~ 40K mc->get calls per-second. These calls are those that do NOT have to reach a database.

这是2013。忘掉2009年的评论吧。同样地,如果你正在运行严重的交通负载,甚至不要考虑如何使用基于windows的memcache。当处理一个非常大的规模(500+前端web服务器)和20+后端数据库服务器和副本(mysql和mssql混合)时,memcached服务器群(组中有12个服务器)支持多个容量较大的OLTP应用程序,响应25K ~ 40K mc->每秒调用。这些调用是那些不需要到达数据库的调用。

IMHO, this use of memcached provided SERIOUS $$$,$$$savings on CAPEX for new DB servers & licences as well as on support contracts for large commercial designs.

IMHO, memcached的使用为新的DB服务器和许可证以及大型商业设计的支持合同节省了大量的美元和美元的资本支出。

#3


10  

When using Windows, the comparison is cut short: memcache appears to be the only client available.

当使用Windows时,比较被缩短:memcache似乎是惟一可用的客户机。

#4


7  

Memcached is a newer API, it also provides memcached as a session provider which could be great if you have a farm of server.

Memcached是一种更新的API,它还提供了Memcached作为会话提供程序,如果您有大量的服务器,这将是非常棒的。

After the version is still really low 0.2 but I have used both and I didn't encounter major problem, so I would go to memcached since it's new.

版本仍然很低,但是我已经使用了这两种方法,而且我没有遇到什么大问题,所以我要去memcached,因为它是新的。

#1


241  

Memcached client library was just recently released as stable. It is being used by digg ( was developed for digg by Andrei Zmievski, now no longer with digg) and implements much more of the memcached protocol than the older memcache client. The most important features that memcached has are:

Memcached客户端库刚刚以稳定的方式发布。digg使用它(由Andrei Zmievski为digg开发,现在不再使用digg)并实现比旧的memcached客户端更多的memcached协议。memcached最重要的特性是:

  1. Cas tokens. This made my life much easier and is an easy preventive system for stale data. Whenever you pull something from the cache, you can receive with it a cas token (a double number). You can than use that token to save your updated object. If no one else updated the value while your thread was running, the swap will succeed. Otherwise a newer cas token was created and you are forced to reload the data and save it again with the new token.
  2. 中科院令牌。这使我的生活更加轻松,并且是一个针对陈旧数据的简单预防系统。无论何时从缓存中提取什么,您都可以用它接收一个cas令牌(一个双数)。您可以使用该令牌来保存更新后的对象。如果在线程运行时没有其他人更新该值,则交换将成功。否则,将创建一个新的cas令牌,您将*重新加载数据并使用新的令牌再次保存它。
  3. Read through callbacks are the best thing since sliced bread. It has simplified much of my code.
  4. 读过回调是有史以来最好的事情。它简化了我的大部分代码。
  5. getDelayed() is a nice feature that can reduce the time your script has to wait for the results to come back from the server.
  6. getdelay()是一个很好的特性,它可以减少脚本等待结果从服务器返回的时间。
  7. While the memcached server is supposed to be very stable, it is not the fastest. You can use binary protocol instead of ASCII with the newer client.
  8. 虽然memcached服务器应该非常稳定,但它不是最快的。对于较新的客户端,可以使用二进制协议代替ASCII。
  9. Whenever you save complex data into memcached the client used to always do serialization of the value (which is slow), but now with memcached client you have the option of using igbinary. So far I haven't had the chance to test how much of a performance gain this can be.
  10. 每当您将复杂数据保存到memcached时,客户端通常都会执行值的序列化(这是缓慢的),但是现在有了memcached客户端,您就可以选择使用igbinary了。到目前为止,我还没有机会去测试它能带来多少性能收益。

All of this points were enough for me to switch to the newest client, and can tell you that it works like a charm. There is that external dependency on the libmemcached library, but have managed to install it nonetheless on Ubuntu and Mac OSX, so no problems there so far.

所有这些都足以让我切换到最新的客户端,并可以告诉你,它就像一种魅力。libmemcached库有一个外部依赖项,但仍然设法将它安装到Ubuntu和Mac OSX上,因此到目前为止没有问题。

If you decide to update to the newer library, I suggest you update to the latest server version as well as it has some nice features as well. You will need to install libevent for it to compile, but on Ubuntu it wasn't much trouble.

如果您决定更新到更新的库,我建议您更新到最新的服务器版本,它也有一些不错的特性。你需要安装libevent来编译它,但是在Ubuntu上,这并不是什么麻烦。

I haven't seen any frameworks pick up the new memcached client thus far (although I don't keep track of them), but I presume Zend will get on board shortly.

到目前为止,我还没有看到任何框架使用新的memcached客户机(尽管我没有跟踪它们),但我认为Zend很快就会加入进来。

UPDATE

Zend Framework 2 has an adapter for Memcached which can be found here

Zend Framework 2有一个用于Memcached的适配器,可以在这里找到

#2


11  

This is 2013. Forget about the 2009 comments. Likewise, if you are running serious traffic loads, do not even contemplate how to make-do with a windows based memcache. When dealing with a very large scale (500+ front end web servers) and 20+ back end database servers and replicants (mysql & mssql mix), a farm of memcached servers (12 servers in group) supports multiple high volume OLTP applications answering 25K ~ 40K mc->get calls per-second. These calls are those that do NOT have to reach a database.

这是2013。忘掉2009年的评论吧。同样地,如果你正在运行严重的交通负载,甚至不要考虑如何使用基于windows的memcache。当处理一个非常大的规模(500+前端web服务器)和20+后端数据库服务器和副本(mysql和mssql混合)时,memcached服务器群(组中有12个服务器)支持多个容量较大的OLTP应用程序,响应25K ~ 40K mc->每秒调用。这些调用是那些不需要到达数据库的调用。

IMHO, this use of memcached provided SERIOUS $$$,$$$savings on CAPEX for new DB servers & licences as well as on support contracts for large commercial designs.

IMHO, memcached的使用为新的DB服务器和许可证以及大型商业设计的支持合同节省了大量的美元和美元的资本支出。

#3


10  

When using Windows, the comparison is cut short: memcache appears to be the only client available.

当使用Windows时,比较被缩短:memcache似乎是惟一可用的客户机。

#4


7  

Memcached is a newer API, it also provides memcached as a session provider which could be great if you have a farm of server.

Memcached是一种更新的API,它还提供了Memcached作为会话提供程序,如果您有大量的服务器,这将是非常棒的。

After the version is still really low 0.2 but I have used both and I didn't encounter major problem, so I would go to memcached since it's new.

版本仍然很低,但是我已经使用了这两种方法,而且我没有遇到什么大问题,所以我要去memcached,因为它是新的。