php 为什么 Magento 这么慢?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1639213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is Magento so slow?
提问by mr-euro
Is Magento usually so terribly slow?
Magento 通常这么慢吗?
This is my first experience with it and the admin panel simply takes ages to load and save changes. It is a default installation with the test data.
这是我第一次使用它,管理面板需要很长时间才能加载和保存更改。它是带有测试数据的默认安装。
The server where it is hosted serves other non-Magento sites super fast. What is it about the PHP code that Magento uses that makes it so slow, and what can be done to fix it?
托管它的服务器以超快的速度为其他非 Magento 站点提供服务。Magento 使用的 PHP 代码是什么导致它变得如此缓慢,以及可以做些什么来修复它?
回答by Alan Storm
I've only been tangentially involved in optimizing Magento for performance, but here's a few reasons why the system is so slow
我只是间接地参与了优化 Magento 的性能,但这里有一些系统如此缓慢的原因
Parts of Magento use an EAV database system implemented on top of MySQL. This means querying for a single "thing" often means querying multiple rows
There's a lot of things behind the scenes (application configuration, system config, layout config, etc.) that involve building up giant XML trees in memory and then "querying" those same trees for information. This takes both memory (storing the trees) and CPU (parsing the trees). Some of these (especially the layout tree) are huge. Also, unless caching is on, these tree are built up from files on diskand on each request.
Magento uses its configuration system to allow you to override classes. This is a powerful feature, but it means anytime a model, helper, or controller is instantiated, extra PHP instructions need to run to determine if an original class file or an override class files is needed. This adds up.
Besides the layout system, Magento's template system involves a lot of recursive rendering. This adds up.
Magento 的一部分使用在 MySQL 之上实现的 EAV 数据库系统。这意味着查询单个“事物”通常意味着查询多行
幕后有很多事情(应用程序配置、系统配置、布局配置等)涉及在内存中构建巨大的 XML 树,然后“查询”这些相同的树以获取信息。这需要内存(存储树)和 CPU(解析树)。其中一些(尤其是布局树)是巨大的。此外,除非打开缓存,否则这些树是根据磁盘上的文件和每个请求构建的。
Magento 使用其配置系统来允许您覆盖类。这是一个强大的功能,但它意味着无论何时实例化模型、帮助程序或控制器,都需要运行额外的 PHP 指令来确定是否需要原始类文件或覆盖类文件。这加起来。
除了布局系统,Magento 的模板系统还涉及到大量的递归渲染。这加起来。
In general, the Magento Engineers were tasked, first and foremost, with building the most flexible, customizable system possible, and worry about performance later.
一般来说,Magento 工程师的首要任务是构建最灵活、最可定制的系统,然后再担心性能。
The first thing you can do to ensure better performance is turn caching on (System -> Cache Management). This will relieve some of the CPU/disk blocking that goes on while Magento is building up its various XML trees.
为了确保更好的性能,您可以做的第一件事是打开缓存(系统 -> 缓存管理)。这将缓解 Magento 构建其各种 XML 树时发生的一些 CPU/磁盘阻塞。
The second thing you'll want to do is ensure your host and operations teamhas experience performance tuning Magento. If you're relying on the $7/month plan to see you through, well, good luck with that.
您要做的第二件事是确保您的主机和运营团队具有 Magento 性能调优的经验。如果您依靠每月 7 美元的计划来帮助您度过难关,那么祝您好运。
回答by benlumley
Further to Alan Storm's recommendations on caching, there's two things I'd specifically recommend you look into related to caching:
除了 Alan Storm 对缓存的建议之外,我特别建议您研究与缓存相关的两件事:
- Make sure caching is in memcached, rather than on disk.
- 确保缓存在 memcached 中,而不是在磁盘上。
I look after a couple of magento installs, and once you get any sort of load on the system, memcached starts to perform much faster. And its dead easy to change it over (relative to doing other magento stuff at least!)
我负责安装了几次 magento,一旦您在系统上获得任何负载,memcached 就会开始运行得更快。而且它很容易改变它(至少相对于做其他 magento 的东西!)
Good starting point is here: http://www.magentocommerce.com/boards/viewthread/12998/P30/- but if you've not used memcached at all before, its worth looking at some general info about it as well.
好的起点在这里:http: //www.magentocommerce.com/boards/viewthread/12998/P30/- 但如果你以前根本没有使用过 memcached,那么它也值得查看一些关于它的一般信息。
- Enable template/view caching.
- 启用模板/视图缓存。
This is a good article: http://inchoo.net/ecommerce/magento/magento-block-caching/
这是一篇好文章:http: //inchoo.net/ecommerce/magento/magento-block-caching/
There are good ones on the magento site too (google magento block caching), but its down at the moment.
magento 站点上也有一些不错的(google magento 块缓存),但目前处于关闭状态。
To add my two cents to the block caching, I'd advise you create your own blocks in /app/code/local, extending the core ones and defining the cache parameters, name them xxx_Cache and then update your layout to use these blocks instead of the core ones. This way, you avoid losing your changes or breaking the system when you upgrade magento.
要将我的两分钱添加到块缓存中,我建议您在 /app/code/local 中创建自己的块,扩展核心块并定义缓存参数,将它们命名为 xxx_Cache 然后更新您的布局以使用这些块的核心。这样,您可以避免在升级 magento 时丢失更改或破坏系统。
回答by Laizer
If you haven't seen it yet, Magento and Rackspace teamed up to create a white paper on performance tuning Magento. It's excellent. https://support.rackspace.com/whitepapers/building-secure-scalable-and-highly-available-magento-stores-powered-by-rackspace-solutions/
如果您还没有看过,Magento 和 Rackspace 联手创建了一份关于 Magento 性能调优的白皮书。它很棒。 https://support.rackspace.com/whitepapers/building-secure-scalable-and-highly-available-magento-stores-powered-by-rackspace-solutions/
--- edit ---
- - 编辑 - -
Another great resource, newly available (Oct 2011) is: http://www.sessiondigital.com/assets/Uploads/Mag-Perf-WP-final.pdf
另一个新资源(2011 年 10 月)是:http: //www.sessiondigital.com/assets/Uploads/Mag-Perf-WP-final.pdf
(Thanks due to Alan Storm on this one.)
(感谢 Alan Storm 在这方面。)
回答by Sam Figueroa
There is possibly also a very non-obvious reason why your admin interface is very slow. Magento has a module named Mage_AdminNotification. Try to disable that ext. Because what it does is query magentocommerce.com for new update messages. If their servers are slow your admin page waits and is in effect slow because of the network lag and loading of the external news. If you have secured your outgoing server connection through a firewall this can be even more frustrating, since the admin interface will wait for the timeout when it cannot reach magentocommerce.com
您的管理界面很慢可能还有一个非常不明显的原因。Magento 有一个名为 Mage_AdminNotification 的模块。尝试禁用该分机。因为它所做的是查询 magentocommerce.com 以获取新的更新消息。如果他们的服务器速度很慢,您的管理页面会等待并且实际上由于网络延迟和外部新闻加载而变慢。如果您通过防火墙保护了您的传出服务器连接,这可能会更加令人沮丧,因为管理界面将在无法访问 magentocommerce.com 时等待超时
To disable it: go to System -> Configuration, scroll to the bottom and hit Advanced(in the Advanced section). Now disable Mage_AdminNotificationand save!
要禁用它:转到系统 -> 配置,滚动到底部并点击高级(在高级部分)。现在禁用Mage_AdminNotification并保存!
回答by creuzerm
I only have a superficial experience with Magento. I installed it on a shared grid-server and the page loading was dismal ~5+ seconds. On a lark, I installed it on my optimized for CMS sites dedicated server, and it felt very, very snappy.
我对 Magento 只有肤浅的体验。我将它安装在共享网格服务器上,页面加载很糟糕~5+ 秒。顺便说一句,我将它安装在我为 CMS 站点优化的专用服务器上,感觉非常非常活泼。
My Dedicated hosting had ~10 Joomla! sites and a VBullitin site running.
我的专用主机大约有 10 个 Joomla!站点和运行的 VBullitin 站点。
My guess is it's just not going to be performant on shared hosting. The over-subscription just won't allow enough resources for Magento to run as it ought.
我的猜测是它不会在共享主机上表现出色。超额订阅不会让 Magento 有足够的资源正常运行。
回答by kameo
I'm more involved in the managed server optimization in my company but I may have a few tips for you. First, you can look at the code more closely using the code tracing feature of Zend server. It will allow you to see where and when the things get dirty.
我更多地参与了我公司的托管服务器优化,但我可能会为您提供一些提示。首先,您可以使用 Zend 服务器的代码跟踪功能更仔细地查看代码。它可以让你看到东西变脏的地方和时间。
I totally share benlumley's consideration regarding the cache. Most of the sites we host doesn't even have the block caching enable. This cache has to be explicitly called and not "assumed". So if you code hasn't yet took part of this mechanism, it's something you definitely want to try. If you have a EE version, you can get the Full page up in order to get the best of the beast.
我完全同意 benlumley 对缓存的考虑。我们托管的大多数站点甚至都没有启用块缓存。这个缓存必须被显式调用而不是“假设”。因此,如果您的代码尚未参与此机制,那么您肯定想尝试一下。如果您有 EE 版本,您可以打开整页以获得最佳效果。
A reverse proxy will also help a lot. It'll cache the static ressources, significantly lowering the pressure on the php interpretation stack of your front servers.
反向代理也会有很大帮助。它将缓存静态资源,显着降低前端服务器 php 解释堆栈的压力。
Don't forget to write the sessions & Magento cache to a RAM disk. This will also definitely get you to another level of performances.
不要忘记将会话和 Magento 缓存写入 RAM 磁盘。这也肯定会让你达到另一个水平的表演。
There's still a lot to be said here but I'm running out of time. You have to know that a good site, well coded in a 1.4.1 CE version, running on a 2x5650 Xeon + 16 GB RAM server and having a Rproxy on top can take up to 50 000 unique visitors a day with smooth pages to everybody.
这里还有很多话要说,但我的时间不多了。您必须知道,一个好的网站,在 1.4.1 CE 版本中编码良好,在 2x5650 Xeon + 16 GB RAM 服务器上运行并在顶部有一个 Rproxy 每天最多可以吸引 50 000 个独立访问者,并且每个人都可以看到流畅的页面.
回答by Jonathan
Switching from Apache to LiteSpeed helped us a lot. In addition to: Editing MySQL's settings, installing Fooman Speedster (module to compress/combine js and css files), and installing APC. Magento has also posted a white paper on how to get the best performance out of the enterprise edition, but it is equally applicable to the other versions: http://www.magentocommerce.com/whitepaper/
从 Apache 切换到 LiteSpeed 对我们帮助很大。除了:编辑 MySQL 的设置,安装 Fooman Speedster(压缩/组合 js 和 css 文件的模块),以及安装 APC。Magento 还发布了一份关于如何从企业版中获得最佳性能的白皮书,但它同样适用于其他版本:http: //www.magentocommerce.com/whitepaper/
回答by Scott
When I first installed I had pages that were taking 30 seconds to load. My server was not maxed out in ram or processor, so I didn't know what to do. Looking at firebug's net panel it was loading about 100 files per page, and each one took a long time to connect. After installing fooman speedster and the gzip in the htaccess loads times were down to 3 seconds, like they had been on other shopping carts on my server.
当我第一次安装时,我的页面需要 30 秒才能加载。我的服务器的内存或处理器没有达到最大值,所以我不知道该怎么办。查看 firebug 的网络面板,它每页加载大约 100 个文件,每个文件都需要很长时间才能连接。安装 fooman speedster 和 htaccess 中的 gzip 后,加载时间下降到 3 秒,就像它们在我服务器上的其他购物车上一样。
回答by Thomas
There are many reasons why your Magento shopping cart could be running slow but no excuses for there is a variety of ways to eleviate the problem and make it pretty darn fast. Enabling Gzip by modifying your htaccess file is a start. You can also install the fooman speedster extension. The type of server used also will determine the speed of your store. More tips and a better explanation here http://www.interactone.com/how-to-speed-up-magento/
您的 Magento 购物车可能运行缓慢的原因有很多,但没有任何借口可以通过多种方法来解决问题并使其变得非常快。通过修改 htaccess 文件启用 Gzip 是一个开始。您还可以安装 fooman speedster 扩展。使用的服务器类型也将决定您商店的速度。这里有更多提示和更好的解释http://www.interactone.com/how-to-speed-up-magento/
回答by developer
Magento is very slow because the database design is not very good. The code is a mess and very hard to update and optimize. So all optimizations are done via cache instead of code.
Magento 很慢,因为数据库设计不是很好。代码一团糟,很难更新和优化。所以所有的优化都是通过缓存而不是代码来完成的。
On the other hand. It is a webshop with a lot of tools. So if you need a flexible webshop just buy a very powerfull server and you will be ok.
另一方面。这是一个有很多工具的网上商店。因此,如果您需要一个灵活的网上商店,只需购买一个非常强大的服务器就可以了。

