【问题标题】:High Memory Usage in ExpressionEngine TemplatesExpressionEngine 模板中的高内存使用率
【发布时间】:2012-10-28 17:34:49
【问题描述】:

我在安装 ExpressionEngine v2.5.3 时遇到了问题,我认为内存使用量过高。这是最近的 EE1 - EE2 升级,如果有影响的话。

此项目的空模板使用 10MB 内存。我在另一个 v2.5.3 项目上进行了测试,那里有一个空页面使用 2MB 内存。我看到普通模板的使用量超过 30 MB,并且浏览器经常失去与服务器的连接。

是否是插件导致内存使用量增加?向后跟踪的最佳方法是什么?

此次升级后安装肯定会正常运行。


模板调试

(0.000011 / 9.01MB) - Begin Template Processing -
(0.000172 / 9.01MB) URI: test
(0.000185 / 9.01MB) Path.php Template: /
(0.000199 / 9.01MB) Retrieving Template
(0.000210 / 9.01MB) Parsing Template URI
(0.002112 / 9.02MB) Template Group Found: test
(0.002166 / 9.02MB) Retrieving Template from Database: test/index
(0.003599 / 9.02MB) Template Found
(0.003690 / 9.02MB) Template Type: webpage
(0.003711 / 9.02MB) Parsing Site Variables
(0.003767 / 9.02MB) Snippets (Keys): structure:is:page|structure:is:listing|structure:is:listing:parent|structure:page:entry_id|structure:page:template_id|structure:page:title|structure:page:slug|structure:page:uri|structure:page:url|structure:page:channel|structure:page:channel_short_name|structure:parent:entry_id|structure:parent:title|structure:parent:slug|structure:parent:uri|structure:parent:url|structure:parent:child_ids|structure:parent:channel|structure:parent:channel_short_name|structure:top:entry_id|structure:top:title|structure:top:slug|structure:top:uri|structure:top:url|structure:child_listing:channel_id|structure:child_listing:short_name|structure:freebie:entry_id|structure:child_ids|structure:sibling_ids|structure_1|structure_2|structure_3|structure_4|structure_5|structure_6|structure_7|structure_8|structure_9|structure_10|structure_last_segment|site_id|site_label|site_short_name|last_segment
(0.003784 / 9.02MB) Snippets (Values): FALSE||||||||||||||||||||||test|/test/|/test/||||||test||||||||||test|1|Ranch|default_site|test
(0.003926 / 9.02MB) Parse Date Format String Constants
(0.003943 / 9.02MB) Parse Current Time Variables
(0.003968 / 9.02MB) Parsing Segment, Embed, and Global Vars Conditionals
(0.007698 / 9.11MB) - Beginning Tag Processing -
(0.007719 / 9.11MB) - End Tag Processing -
(0.008645 / 9.12MB) Calling Extension Class/Method: Structure_ext/template_post_parse
(0.008789 / 9.11MB) - End Template Processing -
(0.008803 / 9.11MB) Parse Global Variables
(0.009574 / 9.11MB) Template Parsing Finished
Memory Usage: 10,163,144 bytes

【问题讨论】:

  • 如果禁用扩展,这个空模板的内存使用会怎样?
  • 禁用扩展会使内存使用量达到 7.5MB

标签: expressionengine


【解决方案1】:

不同版本的 php,以及不同的 php 实现方式,例如 mod_php 与 fastcgi,以及 php 本身启用的不同功能会导致不同级别的内存使用。

要测试只执行 php 而不是在 EE 的模板引擎中执行的内存使用情况,请尝试以下代码。

<?php
    function echo_memory_usage() {
        $mem_usage = memory_get_usage(true);

        if ($mem_usage < 1024)
            echo $mem_usage." bytes";
        elseif ($mem_usage < 1048576)
            echo round($mem_usage/1024,2)." kilobytes";
        else
            echo round($mem_usage/1048576,2)." megabytes";

        echo "<br/>";
    }
?>

【讨论】:

  • 在普通 PHP 文件中打印出 256 KB。
  • 在 EE 模板中打印出 9.25 兆字节
  • 对于它的价值,我刚刚在本地 MAMP 服务器上运行了几个测试,安装了或多或少的 vanilla EE 和一个空模板。禁用 APC(操作码缓存)后,模板调试器输出几乎与您的完全相同,大约 9MB。启用 APC 后,它会在初始请求后降至 2MB。您是否在此服务器上运行其他站点?他们的表现明显更好吗?如果没有,我认为您想查看服务器而不是 EE。
  • 很遗憾,此主机上没有其他站点。很奇怪,您看到 9MB 而我在另一个安装相同版本时看到 2MB。
  • MediaGirl,您在另一台服务器上是否有 APC 字节码缓存,使用 2MB 而不是 9MB?
【解决方案2】:

您可以使用 Graphite 插件快速查明瓶颈:

https://github.com/joelbradbury/Graphite.ee_addon

我发现 Graphite 本身确实可以减慢您的页面速度,但如果您可以让它加载,那就太棒了。

【讨论】:

    【解决方案3】:

    从一个空模板开始,并打开模板调试,这是一个好的开始,并且消除了任何可能导致高内存使用的标签。

    在您的 2Mb 使用安装和您当前的 10Mb 使用安装之间是否有任何不同的设置或附加设置?由于消除了模板标签,您可能需要查看可能会增加开销的附加组件,特别是扩展。欢迎在此处发布您已安装的插件。

    同时禁用跟踪和将模板保存为文件可能会节省一些内存。

    【讨论】:

    • 10MB 内存使用来自一个空模板。是的,这个安装不同于 2MB 的安装......不同的站点都在一起,但 EE 版本相同。跟踪已关闭。不保存为模板。只有在空白模板中调用的插件是结构。我可以在查询中看到这一点。
    • 你能不能,只是作为一个测试,欺骗数据库,删除结构,然后尝试加载一个空白模板,看看有什么区别?
    【解决方案4】:

    看来我的问题的答案是 ~9MB 是 EE 安装中空白模板的正常起始级别。

    从 2MB 开始的模板位于启用了 APC 字节码缓存的 EngineHosting VPS/VSC 帐户上,因此存在数量差异。

    【讨论】:

    • 有趣...我的空白模板大小为 4.6MB,托管在 Clook.net 上
    • 该服务器上是否启用了“APC 字节码缓存”或类似的东西?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 2018-07-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多