调整 magento 以提高性能 [英] Tweaking magento for performance

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

问题描述

我正在查看 magento 站点的性能(服务器加载时间),并且正在尝试调整搜索结果页面.我意识到当我禁用所有繁重的事情时,比如顶部导航、lev 分层导航和产品列表,然后我清除了所有缓存,然后在这个 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、Web 服务器(支持 nginx 而不是 Apache)和 MySQL.另外,为 Magento 设置一个好的缓存后端.所有这些都包括在内,例如在同样适用于 CE 的 Magento 性能白皮书中.

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. 缓存标签

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

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(boolean),这个块将被永远缓存(没有过期).如果设置为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 以提高性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆