Memcache(d) 与 Varnish 加速 3 层 Web 架构
我正在尝试加快我的基准测试(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 inget
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个适用于 stackoverflow.com 的示例:添加此注释会使页面缓存失效,因此必须从 Varnish 中清除此页面(还有我的个人资料页面,这可能不值得一开始就进行缓存。记住使所有内容无效)受影响的页面可能有点问题)。然而,所有评论仍然在 Memcache 中,因此数据库只需写入这条评论。数据库不需要执行任何其他操作来生成页面。所有评论都由 Memcache 提取,并且页面会被重新缓存,直到有人再次影响它(也许通过投票我的答案)。同样,数据库写入投票,所有其他数据都从 Memcache 中提取,生活很快。
Memcache 可以让您的数据库免于进行大量的读取工作,Varnish 通过减少生成页面的频率来节省动态 Web 服务器的 CPU 负载(如果没有 Memcache,也可以减轻数据库负载)。
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).
我的经验来自于将 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.