简体   繁体   English

使用PHP在高性能站点中使用Memcache

[英]Memcache in high performance sites with PHP

I have been working in trying to optimize a webservice that is required to return somewhat quickly (less than 1 second) and is required to maintain a high load of requests (greater than 1000/second). 我一直在努力优化需要快速返回(少于1秒)的Web服务,并且需要维持高负载的请求(大于1000 /秒)。 We are using memcached as a way to store objects "in memory". 我们使用memcached作为一种在内存中存储对象的方法。 It seems we are getting a large number of timeout errors from memcache. 看来我们从memcache中获得了大量的超时错误。

[Thu Jul 23 22:59:42 2009] [error] [client 123.456.789.10] PHP Warning: Memcache::connect() [memcache.connect]: Can't connect to 127.0.0.1:11211, Connection timed out (110) [2009年7月23日22:59:42] [错误] [客户端123.456.789.10] PHP警告:Memcache :: connect()[memcache.connect]:无法连接到127.0.0.1:11211,连接超时( 110)

So, on to the questions. 所以,关于问题。

  1. Is a good use of memcache to store objects in memory that are time consuming to create? 是否可以很好地利用memcache将对象存储在内存中,而这些对象的创建时间很长? Would APC be a better location for these objects? APC会成为这些物体的更好位置吗? The number of reads and 读数和

  2. Are there common pitfalls that I am overlooking in setting up memcache to work more efficiently? 在设置memcache以更有效地工作时,我是否会忽略常见的陷阱?

Thanks for any help, I am somewhat new to working with memcache, and I think there is something I am missing. 感谢您的帮助,我对使用memcache感到有些新意,我觉得我有些遗漏。

To answer your first point : 回答你的第一点:

  • The power of memcached is that it allows to create a cluster of cache servers : it is not meant to be used on a single server (event it you can use it that way) memcached的强大之处在于它允许创建一个缓存服务器集群:它不应该在单个服务器上使用(事件你可以这样使用它)
    • the theory is you have many servers, and each one has some free RAM you have no use for 理论上你有很多服务器,每个都有一些你没有用的免费RAM
    • to use this RAM, you install memcached on these servers, and configure it to use the amount of RAM that wasn't used 要使用此RAM,请在这些服务器上安装memcached,并将其配置为使用未使用的RAM量
    • and if one machine is down, it automatically stops using it, and put load balance the data on the others 如果一台机器关闭,它会自动停止使用它,并将数据的负载平衡置于其他机器上
    • the drawback of memcached (for some people) is that it's network based (even when you use it on only one machine) ; memcached(对某些人来说)的缺点是它是基于网络的(即使你只在一台机器上使用它); which means a bit slower that "local-only" 这意味着“只限本地”有点慢
  • APC works on only one machine : it is great (used as a caching mecanism) to store data you only need on one server, or if you only have one server ; APC只能在一台机器上运行:它很棒(用作缓存机制)来存储您在一台服务器上只需要的数据,或者只有一台服务器; and don't have more data that what you can store in RAM. 并且没有更多数据可以存储在RAM中。
    • main drawback would be that it absolutly does'nt scale : it's thought for one machine ; 主要的缺点是它绝对没有规模:它被认为是一台机器; if you have 10, you will have to have the same data 10 times, one time on each machine. 如果你有10个,你必须拥有10次相同的数据,每台机器一次。
    • APC is said to be about 5 times faster to get data, as it's local, and non-network-based. 据说APC获取数据的速度要快5倍,因为它是本地数据,而非基于网络。

One thing to about APC : if you use it for it's opcode cache ability (you should), make sure you configure it to have enough RAM for opcode+cache (so that it doesn't run out of memory for opcode cache, which would be bad) 关于APC的一件事:如果你使用它的操作码缓存能力(你应该),请确保你配置它有足够的RAM用于操作码+缓存(这样它就不会耗尽内存用于操作码缓存,这会坏)

If you need more (specific) help with memcached and don't get much help here, there is a mailing-list, which is sometimes quite active ; 如果您需要更多(特定)有关memcached的帮助,并且在这里没有得到太多帮助,那么有一个邮件列表,有时非常活跃; maybe trying there could be useful. 也许尝试可能有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM