频繁使用网站的缓存策略

发布于 2024-10-17 01:29:45 字数 750 浏览 0 评论 0原文

我们正在为一个频繁使用的网站设计缓存策略。 该网站由动态和静态内容混合组成。前端是PHP,中间层是Tomcat,后端是mysql。

仅通过 HTTPS 完成用户登录屏幕以保护凭据。之后,所有内容都通过纯 HTTP 提供。有些屏幕是特定于客户的(比如说他的最后订单),而其他屏幕则是每个人都通用的(最受欢迎的产品、促销、规则等)。

考虑到预期的流量,很明显我们需要一个全面的缓存策略。因此,我们正在考虑以下选项:

  1. 将 Squid 或 Varnish 放在 PHP 前面,并将其配置为缓存所有公共内容以及甚至客户的订单提交表单
  2. 通过 PHP 使用 memcached 来缓存页面片段(例如最流行的产品)
  3. 在中间层/tomcat 中实现缓存(即在将内容返回到 Web 服务器之前,尝试从本地缓存(例如 ehcache)获取它)
  4. 使用 PHP 级缓存,例如Zend 缓存并存储页面片段。这与我提到的第二个选项很接近,但它内置于 Zend 框架中。

我们可能会结合使用这些策略。

那么问题是是否值得像Varnish一样添加前端缓存,或者只是在内部使用Zend Cache?


我忘记提及的另一个选项是使用 PHP 级缓存(如 Zend Cache)并存储页面片段。这与我提到的第二个选项很接近,但它内置于 Zend 框架中。

那么问题是是否值得像Varnish一样添加前端缓存,或者只是在内部使用Zend Cache?

再次感谢, 菲洛帕托.

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.

Only user login screen is done over HTTPS to secure the credentials. After that, all content is served over plain 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.
  2. Use memcached by PHP to cache page fragments (such as most popular products)
  3. Implement caching in the middle tier/tomcats (i.e. before returning content to web-servers, try to fetch it from local cache such as ehcache)
  4. Use PHP-level cache like Zend Cache and store there fragments of the pages. This is close to the second option that i mentioned but it's built into the Zend framework.

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?


The other option that i forgot to mention is to use PHP-level cache like Zend Cache and store there fragments of the pages. This is close to the second option that i mentioned but it's built into the Zend framework.

So the question is whether it's worthwhile to add front cache like Varnish, or just use Zend Cache inside?

Thanks again,
Philopator.

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

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

发布评论

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

评论(1

就此别过 2024-10-24 01:29:45

我已经完成了很多这样的项目,并发现:

  • 创建(完整的)自定义解决方案既困难又昂贵。幸运的是,您发现 Squid/Varnish、memcache 和 ehcache
  • 站点的动态行为差异很大,并且您最了解您的站点,因此设计特定的缓存策略是有意义的
  • ,部署多层缓存是有意义的。然而,这将使您的网站的行为变得复杂,因此您应该告诉与该网站相关的每个人(例如业务人员)一些有关它的信息,并告诉您的工程师很多有关它的信息。
  • 想想你将如何调试问题。例如,添加指示所提供数据的新鲜度的标头、允许某些人清除或避免缓存
  • 定期检查不同缓存层的执行情况(例如,为您的 varnish 机器使用 nagios 插件)。
  • 在构建任何缓存之前测量性能问题出在哪里:)
  • 缓存某些对象一段时间就已经是一个非常显着的改进

这些天我非常喜欢 Varnish:它是一个独立的层,不会使 Java/PHP 代码变得混乱,它速度快且非常灵活。缺点是vcl中的配置有点太复杂了。

我通常在内存存储中使用ehcache +,以避免小数据集的延迟(例如数据库查询或服务请求),而当数据量很大并且缓存需要由多个节点共享时,我通常使用memcached。

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
  • 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 (e.g. business) something about it and tell your engineers a lot about it.
  • Think of how you're going to debug problems. e.g. 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 (e.g. use nagios plugins for your varnish machines).
  • 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. Downside is that the configuration in vcl is a bit too complex.

I typically use ehcache + in memory storage to avoid latency (e.g. 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.

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