Magento Block Cache Queue For High Traffic Sites

简介:

This is the initial release. It has been tested in a few production environments, but as always use with caution and keep checking the Github repo

Requirements

What does this fix?

If you have a high traffic magento site this modification will ensure that a non-cached block is only being called once, so it can be properly cached and served to all users requesting said block.

Example Scenario:

> Single core machine. 
> Magento Nav Bar with 150 categories which takes about 0.5 seconds to generate for 1 user.

Lets assume that your Magento Block cache has recently been cleared by either Admin or Updates to your catalog (IE. Deleting Categories, Updating Products, etc). Immediately 5 users visit your homepage at the same time.Apache/Magento gets the requests and starts to render your Homepage block by block for all users simultaneously. For arguments sake lets say that the Navigation Block is the heaviest item to load because your navigation bar contains a category drop down with 150 Parent/Child elements. Normally this means that all 5 users will request from the database and then loop through the collection to generate the HTML.

Completing the nav bar block takes about 0.5 seconds for 1 user. But since we have 5 concurrent users it decreases the total CPU power available and now it takes roughly 5 times as long to generate each request.

User 1 <-- Queries the database and generates HTML (20% CPU Load) - 2.5 seconds 
User 2 <-- Queries the database and generates HTML (20% CPU Load) - 2.5 seconds 
User 3 <-- Queries the database and generates HTML (20% CPU Load) - 2.5 seconds 
User 4 <-- Queries the database and generates HTML (20% CPU Load) - 2.5 seconds 
User 5 <-- Queries the database and generates HTML (20% CPU Load) - 2.5 seconds 
Total time: 2.5 seconds

Solution

With this modification the request takes slightly longer for 1 user but the benefits come in when you have concurrent users.

User 1 <-- Queries the database and generates HTML (100% CPU Load) - 0.6 seconds 
User 2 <-- (Wait) Retrieve HTML from User 1 (0% CPU Load) - 0.7 seconds 
User 3 <-- (Wait) Retrieve HTML from User 1 (0% CPU Load) - 0.7 seconds 
User 4 <-- (Wait) Retrieve HTML from User 1 (0% CPU Load) - 0.7 seconds 
User 5 <-- (Wait) Retrieve HTML from User 1 (0% CPU Load) - 0.7 seconds 
Total time: 0.7 seconds

Since user 1 has 100% of the CPU available it is able to complete the request faster and serve it out to the other users in Queue. There is a very small lag between the User 1 and when the rest of users get the data.

Benchmark

Coming Soon…

TODO

  • This is the initial release. I would like to package this up in a proper plugin later this month.
  • Some code clean up would also help.
  • Get some benchmarks.

Download

https://github.com/asalce/Magento-Block-Cache-Queue

原文:Magento Block Cache Queue For High Traffic Sites

PS:转这篇文章并不是来推荐作者写的这个扩展,作者自己也说这个不是一个完善的版本,我也对作者应对这个问题的处理方式持保留态度。重点是这里针对Magento的缓存机制,在高并发的情况下所会遇到的问题进行了阐述,至于如何应对和处理这个问题,我觉得方式可能有很多种,留给大家去思考



目录
相关文章
|
存储 索引 Python
Matplotlib使用自定义颜色绘制统计图
matplotlib 提供的所有绘图都带有默认样式,但有时可能需要自定义绘图的颜色和样式,以对绘制更加精美、符合审美要求的图像。
1807 0
Matplotlib使用自定义颜色绘制统计图
|
算法 C#
算法题丨3Sum Closest
描述 Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target.
1347 0
慧算账V2.0版发布,互联网记账再升级
本文讲的是慧算账V2.0版发布,互联网记账再升级,日前,慧算账迎来了一次版本的更新升级,V2.0版正式震撼上线。据悉,新推出的版本除了继续提升产品功能和完善用户体验外,其在智能化方面的表现也相当惹眼,下面就赶快随小编一睹为快吧! 一、银行日记账一键导入 以前,会计月末痛苦的事情是什么?不错,就是银行对账!几百条银行流水耗时几小时辛辛苦苦录入,换来的是跟实际1分钱的差额,而且遗憾的是久久核对不出差错在哪儿。
1935 0
|
.NET 数据格式
asp.net zip 压缩传输
原文:asp.net zip 压缩传输 在实际生产中,比如使用xml json 等传输大量数据的时候,有时候会出现等待时间过长,这里分享一个压缩传输的方法 首先到网上去下载一个 ICSharpCode.
1014 0
|
7天前
|
存储 关系型数据库 分布式数据库
PostgreSQL 18 发布,快来 PolarDB 尝鲜!
PostgreSQL 18 发布,PolarDB for PostgreSQL 全面兼容。新版本支持异步I/O、UUIDv7、虚拟生成列、逻辑复制增强及OAuth认证,显著提升性能与安全。PolarDB-PG 18 支持存算分离架构,融合海量弹性存储与极致计算性能,搭配丰富插件生态,为企业提供高效、稳定、灵活的云数据库解决方案,助力企业数字化转型如虎添翼!
|
6天前
|
存储 人工智能 Java
AI 超级智能体全栈项目阶段二:Prompt 优化技巧与学术分析 AI 应用开发实现上下文联系多轮对话
本文讲解 Prompt 基本概念与 10 个优化技巧,结合学术分析 AI 应用的需求分析、设计方案,介绍 Spring AI 中 ChatClient 及 Advisors 的使用。
325 130
AI 超级智能体全栈项目阶段二:Prompt 优化技巧与学术分析 AI 应用开发实现上下文联系多轮对话