选择适当的缓存机制 [英] Selecting an appropriate cache mechanism

查看:81
本文介绍了选择适当的缓存机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设置:

  • 4个网络服务器
  • 静态内容服务器(已挂载NFS)
  • 2个数据库服务器
  • 2个神奇"服务器
  • 另外8台被指定为多功能的机器.

我正在为三种缓存机制编写包装器,以便可以某种标准化的方式使用它们:文件系统,Memcached和APC.我正在尝试提出使用示例(以及每个缓存中实际放置的内容).

I'm writing a wrapper for three caching mechanisms so that they can be used in a somewhat normalized manner: Filesystem, Memcached and APC. I'm trying to come up with examples for use (and what to actually put in each cache).

处理我们生成的内容,然后以静态方式投放. RSS提要,旧的报告数据,用户特定的页面等...所有这些都缓存到静态服务器中.

Handles content that we generate and then statically serve. RSS feeds, old report data, user specific pages, etc... This is all cached to the static server.

PHP会话数据,MySQL查询结果,通常是在我们的系统中必须可用的内容.服务器池中可以包含8台计算机.

PHP session data, MySQL query results, generally things that need to be available across our systems. We have 8 machines that can be included in the server pool.

我不知道.这两个做魔术"服务器不是任何分布式系统的一部分,因此它们似乎可以将查询结果缓存在APC中并从那里工作.除此之外,我什么都没想到.

I have no idea. The two "do magic" servers are not part of any distributed system, so it seems likely that they could cache query results in APC and work from there. Past that, I can't think of anything.

鉴于我们使用SQL的本质,查询缓存会降低性能.我已禁用此功能.

Given the nature of our SQL use, query caching reduces performance. I've disabled this.

通常,什么类型的数据应存储在哪里?这种设置是否有意义?

In general, what types of data should be stored where? Does this setup even make sense?

分布式系统中的APC数据缓存有什么用(我想不到)?

Is there any use for an APC data cache in a distributed system (I can't think of one)?

有什么我想念的东西会让事情变得更轻松或更有效吗?

Is there something that I'm missing that would make things easier or more efficient?

我终于弄清了Pascal在说什么.我的想法是,我只会将config/的任何部分移动到APC,并且仍然从磁盘加载其余文件.还有其他建议吗?

I've figured out what Pascal was saying, finally. I had it stuck in my head that I would only be moving a portion of my config / whatever to APC, and still loading the rest of the file from disk. Any other suggestions?

推荐答案

在某些项目中,我正在使用相同的缓存机制;并且我们正在使用APC + memcached作为缓存系统.

I'm using the same kind of caching mecanism for some projects ; and we are using APC + memcached as caching systems.

在缓存数据时,APC和memcached之间有两个/三个主要区别:

There are two/three main differences between APC and memcached, when it comes to caching data :

  • APC访问要快一些(如果我没记错的话,访问速度比memcached快5倍),因为它只是本地的-即不涉及网络.
  • 使用APC,您的缓存将在每台服务器上重复;使用memcached,服务器之间没有重复
    • whic表示memcached确保所有服务器具有相同版本的数据;而每台服务器上存储在APC中的数据可能会有所不同
    • APC access is a bit faster (something like 5 times faster than memcached, if I remember correctly), as it's only local -- i.e. no network involved.
    • Using APC, your cache is duplicated on each server ; using memcached, there is no duplication accross servers
      • whic means that memcached ensures that all servers have the same version of the data ; while data stored in APC can be different on each server


      我们通常使用:


      We generally use :

      • 用于经常访问的数据的APC,生成速度很快,并且:
        • 两者都不经常修改
        • 或者在所有服务器上是否相同都没关系
        • APC for data that has to be accessed very often, is quick to generate, and :
          • either is not modified often
          • or it doesn't matter if it's not identical on all servers
          • 或者对于必须立即可见修改的数据(即,当对数据库进行写操作时,也会重新生成缓存的条目)

          例如,我们可以:

          • 使用APC存储配置变量:
            • 不要经常更改
            • 经常访问
            • 很小
            • Use APC to store configuration variables :
              • Don't change often
              • Are accessed very often
              • Are small
              • 并不小,并且有很多,这意味着它可能需要比仅在一台服务器上更多的内存
              • 很难/繁重地生成


              几个旁注:


              A couple of sidenotes :

              • 如果多个服务器尝试写入通过NFS共享的同一文件,则可能会出现问题,因为NFS上没有锁定机制(据我所记得)
              • 可以使用APC缓存数据,但是-使用它的最重要的原因是它的操作码缓存功能(可以在PHP服务器上节省大量CPU)
              • memcached中的条目大小有限:您不能存储大于1M的条目(我有时会遇到这个问题-很少,但是发生时不好^^)
              • If several servers try to write to the same file that's shared via NFS, there can be problems, as there is no locking mecanism on NFS (as far as I remember)
              • APC can be used to cache data, yes -- but the most important reason to use it is it's opcode caching feature (can save a large amount of CPU on the PHP servers)
              • Entries in memcached are limited in size : you cannot store an entry that's bigger than 1M (I've sometimes run into that problem -- rarely, but it's not good when it happens ^^ )

              这篇关于选择适当的缓存机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆