閱讀582 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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的緩存機製,在高並發的情況下所會遇到的問題進行了闡述,至於如何應對和處理這個問題,我覺得方式可能有很多種,留給大家去思考



最後更新:2017-04-03 14:53:52

  上一篇:go poj 1326 Mileage Bank【四舍五入】
  下一篇:go android橫豎屏顯示