简体   繁体   English

频繁使用的网站的缓存策略

[英]Caching strategy for heavily used web-site

We're in process of designing caching strategy for a heavily used web-site. 我们正在为一个经常使用的网站设计缓存策略。 The site consists of a mix of dynamic and static content. 该站点包含动态和静态内容。 The front-end is PHP, middle tier is Tomcat and mysql on the back. 前端是PHP,中间层是Tomcat,后面是mysql。

Only user login screen is done over HTTPS to secure the credentials. 仅用户登录屏幕通过HTTPS完成,以保护凭据。 After that, all content is served over plain HTTP. 之后,所有内容都通过纯HTTP提供。 Some of the screens are specific to the customer (let's say his last orders), while other screens are common to everybody (most popular products, promotions, rules, etc). 一些屏幕是特定于客户的(例如,他的最后订单),而其他屏幕是每个人都通用的(最受欢迎的产品,促销,规则等)。

Given the expected traffic volume it's clear that we need a comprehensive caching strategy. 给定预期的流量,很明显,我们需要一个全面的缓存策略。 So we're considering following options: 因此,我们正在考虑以下选项:

  1. Put Squid or Varnish in front of PHP and configure it to cache all public content and even order submission form of a customer . 将Squid或Varnish放在PHP的前面并配置它以缓存所有公开内容甚至客户的订单提交表格
  2. Use memcached by PHP to cache page fragments (such as most popular products) 使用PHP的memcached来缓存页面片段(例如最受欢迎的产品)
  3. Implement caching in the middle tier/tomcats (ie before returning content to web-servers, try to fetch it from local cache such as ehcache) 在中间层/ tomcats中实现缓存(即,在将内容返回到Web服务器之前,尝试从本地缓存(例如ehcache)中获取内容)
  4. Use PHP-level cache like Zend Cache and store there fragments of the pages. 使用Zend Cache之类的PHP级缓存,并在其中存储页面的片段。 This is close to the second option that i mentioned but it's built into the Zend framework. 这接近于我提到的第二个选项,但它内置在Zend框架中。

It's possible that we will use a combination of those strategies. 我们可能会结合使用这些策略。

So the question is whether it's worthwhile to add front cache like Varnish, or just use Zend Cache inside? 所以问题是,是否值得添加像Varnish这样的前端缓存,还是仅在内部使用Zend Cache?


The other option that i forgot to mention is to use PHP-level cache like Zend Cache and store there fragments of the pages. 我忘了提到的另一个选项是使用Zend Cache之类的PHP级别的缓存并在那里存储页面的片段。 This is close to the second option that i mentioned but it's built into the Zend framework. 这接近于我提到的第二个选项,但它内置在Zend框架中。

So the question is whether it's worthwhile to add front cache like Varnish, or just use Zend Cache inside? 所以问题是,是否值得添加像Varnish这样的前端缓存,还是仅在内部使用Zend Cache?

Thanks again, Philopator. 再次感谢Philopator。

I've done quite a few projects like this and found that: 我已经完成了很多这样的项目,发现:

  • creating a (complete) custom solution is hard and expensive. 创建(完整的)自定义解决方案既困难又昂贵。 Luckily you found Squid/Varnish, memcache and ehcache 幸运的是,您发现了Squid / Varnish,memcache和ehcache
  • The dynamic behaviour of sites differ a lot and you know your site best, so it makes sense to devise a specific caching strategy 网站的动态行为差异很大,您对网站的了解最深,因此设计一种特定的缓存策略很有意义。
  • it makes sense to deploy multiple layers of cache. 部署多层缓存很有意义。 However, this will complicate the behavior of your site, so you should tell everybody involved with the site (eg business) something about it and tell your engineers a lot about it. 但是,这会使您的网站的行为复杂化,因此您应该告诉与网站有关的每个人(例如,业务)有关此事的信息,并告诉您的工程师很多有关它的信息。
  • Think of how you're going to debug problems. 想想如何调试问题。 eg add headers that indicate the freshness of the data served, allow certain people to purge or avoid the cache 例如,添加标头以指示所提供数据的新鲜度,允许某些人清除或避免缓存
  • Regularly check how the different cache layers perform (eg use nagios plugins for your varnish machines). 定期检查不同的缓存层的性能(例如,将nagios插件用于清漆机器)。
  • Measure where your performance problems are before you build any caches :) 在构建任何缓存之前,请先评估性能问题所在的位置:)
  • caching certain objects for just a short while can already be a very significant improvement 短时间缓存某些对象已经是非常重要的改进

These days I like Varnish a lot: it's a separate layer that doesn't clutter the Java/PHP code, it's fast and very flexible. 如今,我非常喜欢Varnish:它是一个独立的层,不会使Java / PHP代码混乱,它既快速又非常灵活。 Downside is that the configuration in vcl is a bit too complex. 缺点是vcl中的配置太复杂了。

I typically use ehcache + in memory storage to avoid latency (eg database queries or service requests) with small data sets, and memcached when there's a lot of data and the cache needs to shared by multiple nodes. 我通常在内存存储中使用ehcache +来避免小数据集的延迟(例如,数据库查询或服务请求),并在有大量数据且需要由多个节点共享缓存的情况下使用memcached。

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

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