Memcache(d) 与 Varnish 加速 3 层 Web 架构

发布于 2024-10-08 07:28:40 字数 397 浏览 0 评论 0原文

我正在尝试加快我的基准测试(3 层 Web 架构),并且我有一些与 Memcache(d) 和 Varnish 相关的一般问题。

  • 有什么区别?
    在我看来,Varnish 位于网络服务器后面,缓存网页,不需要更改代码,只需配置即可。
    另一方面,Memcached 是通用缓存系统,主要用于缓存数据库结果,并且需要更改 get 方法(第一次缓存查找)。

  • 我可以同时使用两者吗?前端 Web 服务器中的 Varnish 和用于数据库缓存的 Memcached?

  • 什么是更好的选择?

    (场景 1 - 主要是写,
    场景 2 - 主要阅读,
    场景 3 - 读取和写入类似)

I'm trying to speed up my benchmark (3 tier web architecture), and I have some general questions related to Memcache(d) and Varnish.

  • What is the difference?
    It seems to me that Varnish is behind the web server, caching web pages and doesn't require change in code, just configuration.
    On the other side, Memcached is general purpose caching system and mostly used to cache result from database and does require change in get method (first cache lookup).

  • Can I use both? Varnish in front web server and Memcached for database caching?

  • What is a better option?

    (scenario 1 - mostly write,
    scenario 2 - mostly read,
    scenario 3 - read and write are similar)

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

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

发布评论

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

评论(2

猫性小仙女 2024-10-15 07:28:40
  • Varnish 位于网络服务器前面;它用作缓存的反向 http 代理。
  • 您可以同时使用两者。
  • 主要是写——Varnish 需要清除受影响的页面。这将导致开销并且对修改后的页面没有什么好处。
  • 主要阅读——Varnish 可能会涵盖其中的大部分内容。
  • 类似的阅读和write -- Varnish 将为您提供大量页面,Memcache 将为混合了已知数据和新数据的页面提供信息,使您能够更快地生成页面。

一个适用于 stackoverflow.com 的示例:添加此注释会使页面缓存失效,因此必须从 Varnish 中清除此页面(还有我的个人资料页面,这可能不值得一开始就进行缓存。记住使所有内容无效)受影响的页面可能有点问题)。然而,所有评论仍然在 Memcache 中,因此数据库只需写入这条评论。数据库不需要执行任何其他操作来生成页面。所有评论都由 Memcache 提取,并且页面会被重新缓存,直到有人再次影响它(也许通过投票我的答案)。同样,数据库写入投票,所有其他数据都从 Memcache 中提取,生活很快。

Memcache 可以让您的数据库免于进行大量的读取工作,Varnish 通过减少生成页面的频率来节省动态 Web 服务器的 CPU 负载(如果没有 Memcache,也可以减轻数据库负载)。

  • Varnish is in front of the webserver; it works as a reverse http proxy that caches.
  • You can use both.
  • Mostly write -- Varnish will need to have affected pages purged. This will result in an overhead and little benefit for modified pages.
  • Mostly read -- Varnish will probably cover most of it.
  • Similar read & write -- Varnish will serve a lot of the pages for you, Memcache will provide info for pages that have a mixture of known and new data allowing you to generate pages faster.

An example that could apply to stackoverflow.com: adding this comment invalidated the page cache, so this page would have to be cleared from Varnish (and also my profile page, which probably isn't worth caching to begin with. Remembering to invalidate all affected pages may be a bit of an issue). All the comments, however, are still in Memcache, so the database only has to write this comment. Nothing else needs to be done by the database to generate the page. All the comments are pulled by Memcache, and the page is recached until somebody affects it again (perhaps by voting my answer up). Again, the database writes the vote, all other data is pulled from Memcache, and life is fast.

Memcache saves your DB from doing a lot of read work, Varnish saves your dynamic web server from CPU load by making you generate pages less frequently (and lightens the db load a bit as well if not for Memcache).

孤者何惧 2024-10-15 07:28:40

我的经验来自于将 Varnish 与 Drupal 结合使用。用尽可能简单的术语来说,我的回答如下:

一般来说,Varnish 适用于未经身份验证(通过 cookie)的流量,而 memcached 将缓存经过身份验证的流量。

所以两者都用。

My experience comes from using Varnish with Drupal. In as simple terms as possible, here's how I'd answer:

In general, Varnish works for unauthenticated (via cookie) traffic and memcached will cache authenticated traffic.

So use both.

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