调整magento以获得性能

调整magento以获得性能

本文介绍了调整magento以获得性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找magento网站的性能(服务器加载时间),并且正在尝试调整搜索结果页面.我意识到,当我禁用所有繁琐的事情(如顶部导航,左分层导航和产品列表)时,我清除了所有缓存,然后在这个magento核心执行了60次SQL查询之后又创建了一个数据库.是否有人有任何程序如何清除它们或如何将它们减少到可接受的数量?

i'm looking on performance (server load time) of magento site and i'm trying to tune search result pages. I realized that when I disabled all heavy things like top navigation, lev layered navigation and product listing and I cleared all cache then after this magento core does like 60 SQL queries agains a database. Does anyone have any procedure how to rid of them or how to reduce them to some acceptable amount?

我还能以某种方式减少创建块的时间吗?

Also can I somehow reduce a time spent during creating of blocks?

非常感谢你,杰罗.

推荐答案

Magento是一个非常灵活的电子商务框架,但这种灵活性要付出代价:性能.这个答案是指针和一些有关缓存(尤其是块)的详细信息的集合.

Magento is a extremely flexible ecommerce framework, but that flexibility comes with a price: performance. This answer is a collection of pointers and some details on caching (especially for blocks).

要考虑的一件事是Magento环境,例如调整php,网络服务器(在Apache上优先使用nginx)和MySQL.另外,为Magento设置一个良好的缓存后端.所有这些都包括在内在 Magento性能白皮书中,该白皮书也适用于CE.

One thing to consider is the Magento environment, e.g. tuning the php, the web server (favor nginx over Apache), and MySQL. Also, set up a good caching backend for Magento. All these are covered e.g. in the Magento Performance Whitepaper that applies also to the CE.

设置环境之后,事情的另一面就是代码.
通过启用平面表目录(系统">配置">目录">前端" ),可以减少某些页面的查询数量,但是您始终会有很多查询.

After the environment is set up, the other side of things is the code.
Reducing the number of queries is possible for some pages by enabling the flat table catalog (System > Configuration > Catalog > Frontend), but you will always have a high number of queries.

除了调整环境(APC,内存,CPU)外,您还无法真正减少创建块所花费的时间.因此,正如其他评论者所说,您最好的选择是利用Magento内置的缓存功能.

You also can't really reduce the time spent creating the blocks except by tuning the environment (APC, memory, CPU). So as the other commenters said, your best choice is utilizing the caching functionality that Magento has built in.

由于您在问题中特别提到了块,因此我将详细介绍块缓存.块缓存由三个属性控制:

Because you specifically mentioned blocks in the question, I'll elaborate a bit more on block caching. Block caching is governed by three properties:

  1. cache_lifetime
  2. cache_key
  3. cache_tags

所有这些属性都可以使用setData()或magic setters或通过实现关联的getter方法(getCacheLifetime()getCacheKey()getCacheTags())在块的_construct()方法中设置.

All these properties can be set in the _construct() method of a block using setData() or magic setters, or by implementing the associated getter methods (getCacheLifetime(), getCacheKey(), getCacheTags()).

cache_lifetime 以(整数)秒为单位指定.如果将其设置为false(布尔值),则该块将永远被缓存(没有过期).如果将其设置为null,则不会缓存该块(这是Mage_Core_Block_Abstract中的默认设置).

The cache_lifetime is specified in (integer) seconds. If it is set to false(boolean), the block will be cached for ever (no expiry). If it is set to nullthe block will not be cached (this is the default in Mage_Core_Block_Abstract).

cache_key 是用于标识高速缓存池中的高速缓存记录的唯一字符串.默认情况下,它是由方法getCacheKeyInfo()返回的数组构造的.

The cache_key is the unique string that is used to identify the cache record in the cache pool. By default it is constructed from the array returned by the method getCacheKeyInfo().

// Mage_Core_Block_Abstract
public function getCacheKeyInfo()
{
    return array(
        $this->getNameInLayout()
    );
}

public function getCacheKey()
{
    if ($this->hasData('cache_key')) {
        return $this->getData('cache_key');
    }
    /**
     * don't prevent recalculation by saving generated cache key
     * because of ability to render single block instance with different data
     */
    $key = $this->getCacheKeyInfo();
    //ksort($key);  // ignore order
    $key = array_values($key);  // ignore array keys
    $key = implode('|', $key);
    $key = sha1($key);
    return $key;
}

在自定义块中自定义缓存键的最佳方法是覆盖getCacheKeyInfo()方法,并根据需要添加所需的数据以唯一地标识缓存的块.

The best way to customize the cache key in custom blocks is to override the getCacheKeyInfo() method and add the data that you need to uniquely identify the cached block as needed.

例如,要根据客户群缓存不同版本的块,可以执行以下操作:

For example, in order to cache a different version of a block depending on the customer group you could do:

public function getCacheKeyInfo()
{
    $info = parent::getCacheKeyInfo();
    $info[] = Mage::getSingleton('customer/session')->getCustomerGroupId()
    return $info;
}

cache_tags 是启用缓存分段的数组.您可以删除仅与一个或多个标签匹配的缓存部分.
系统>缓存管理下的管理界面中,您可以看到几个可用的默认缓存标签(例如BLOCK_HTML,CONFIG等).您也可以使用自定义缓存标签,只需指定它们即可.
这是Zend_Cache实现的一部分,与cache_lifetimecache_key相比,自定义的频率要低得多.

The cache_tags are an array that enable cache segmentation. You can delete sections of the cache matching one or more tags only.
In the admin interface under System > Cache Management you can see a couple of the default cache tags that are available (e.g. BLOCK_HTML, CONFIG, ...). You can use custom cache tags, too, simply by specifying them.
This is part of the Zend_Cache implementation, and needs to be customized far less frequently compared to the cache_lifetime and the cache_key.

除了块之外,Magento还缓存许多其他内容(收集数据,配置等).
您可以使用Mage::app()->saveCache()Mage::app()->loadCache()Mage::app()->cleanCache()Mage::app()->removeCache()缓存自己的数据.请在Mage_Core_Model_App中查找有关这些方法的详细信息,它们非常简单.

Besides blocks Magento caches many other things (collection data, configuration, ...).
You can cache your own data using Mage::app()->saveCache(), Mage::app()->loadCache(), Mage::app()->cleanCache() and Mage::app()->removeCache(). Please look in Mage_Core_Model_App for details on these methods, they are rather straight forward.

您还将希望使用整页缓存模块.如果您使用的是Magento EE,那么您已经拥有一个.否则,搜索Magento Connect-有很多选择(商业).
其中一些模块还可以为您优化Magento的各个部分,例如整页缓存方面. Nitrogento (商业).

You will also want to use a full page cache module. If you are using the Magento EE, you already have one. Otherwise search Magento Connect - there are many options (commercial).
Some of those modules also tune various parts of Magento for you beyond the full page caching aspect, e.g. Nitrogento (commercial).

使用像 Varnish 这样的反向代理也是非常有益的.

Using a reverse proxy like Varnish is also very beneficial.

关于此主题的博客文章很多.这是发布者一个帖子 Nitrogento扩展名.
如果您在更小规模的环境中运行Magento,请在在magebase.com上优化文件缓存后端.

There are quite a number of blog posts on this subject. Here is one post by the publishers of the Nitrogento extension.
If you are running Magento on a more low-scale environment, check out my post on the optimization of the file cache backend on magebase.com.

这篇关于调整magento以获得性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:13