选择合适的缓存机制

发布于 2024-08-24 01:29:50 字数 730 浏览 10 评论 0原文

我的设置:

  • 4 个网络服务器
  • 静态内容服务器(NFS 安装)
  • 2 个数据库服务器
  • 2 个“魔术”服务器
  • 另外 8 台指定为多用途的机器。

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

文件系统

处理我们生成并静态提供的内容。 RSS 提要、旧报告数据、用户特定页面等...这些都缓存到静态服务器。

Memcached

PHP 会话数据、MySQL 查询结果,通常需要在我们的系统中可用。我们有 8 台机器可以包含在服务器池中。

APC

我不知道。这两个“神奇”服务器不属于任何分布式系统,因此它们似乎可以在 APC 中缓存查询结果并从那里工作。过去了,我什么也想不起来了。

查询缓存

鉴于 SQL 使用的性质,查询缓存会降低性能。我已经禁用了这个。

一般来说,什么类型的数据应该存储在哪里?这个设置还有意义吗?

APC数据缓存在分布式系统中是否有任何用处(我想不出)?

我是否缺少一些可以让事情变得更容易或更高效的东西?

编辑:我终于明白了帕斯卡在说什么。我一直在想,我只会将我的配置/任何内容的一部分移动到 APC,并且仍然从磁盘加载文件的其余部分。还有其他建议吗?

My setup:

  • 4 webservers
  • Static content server (NFS mount)
  • 2 db servers
  • 2 "do magic" servers
  • An additional 8 machines designated multi-purpose.

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).

File System

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.

Memcached

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.

Query Caching

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?

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?

Edit: 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角卖回忆 2024-08-31 01:29:50

我在某些项目中使用相同类型的缓存机制;我们使用 APC + memcached 作为缓存系统。

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

  • APC 访问速度稍快一点(如果我没记错的话,大约比 memcached 快 5 倍),因为它只是本地——即不涉及网络。
  • 使用APC,您的缓存会在每台服务器上复制;使用memcached,跨服务器不存在重复
    • 这意味着memcached确保所有服务器具有相同版本的数据;而APC中存储的数据在每台服务器上可能不同

我们通常使用:

  • APC 用于必须经常访问、快速生成的数据,并且:
    • 不经常修改
    • 或者即使所有服务器上的内容不相同也没关系
  • ,要么在所有内存缓存服务器上对于需要更多时间生成和/或较少使用的数据来说 。
    • 或者对于修改必须立即可见的数据(即,当写入数据库时​​,缓存的条目也会重新生成)

例如,我们可以:

  • 使用 APC 来存储配置变量:
    • 不要经常改变
    • 经常访问
    • 很小
  • 使用 memcached 存储文章内容(例如,对于 CMS 应用程序)
    • 不是那么小,而且数量很多,这意味着它可能需要比我们单独在一台服务器上拥有的内存更多的内存
    • 生成起来相当困难/繁重

一些旁注:

  • 如果多个服务器尝试写入通过 NFS 共享的同一个文件,可能会出现问题,因为 NFS 上没有锁定机制(据我记得)
  • APC 可以用于缓存数据,是的 - 但使用它的最重要原因是它的操作码缓存功能(可以在 PHP 服务器上节省大量 CPU)
  • memcached 中的条目大小有限:您无法存储大于 1M 的条目(我有时会遇到这个问题 - 很少,但发生时就不好了 ^^ )

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

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

  • 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 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
  • memcached for data that takes more time to generate, and/or is less used.
    • Or for data for which modifications must be visible immediatly (i.e. when there is a write to the DB, the cached entry is regenerated too)

For instance, we could :

  • Use APC to store configuration variables :
    • Don't change often
    • Are accessed very often
    • Are small
  • Use memcached for content of articles (for a CMS application, for example) :
    • Not that small, and there are a lot of them, which means it might need more memory than we have on one server alone
    • Pretty hard/heavy to generate

A couple of sidenotes :

  • 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 ^^ )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文