为什么Symfony2应用程序花费70-90%的时间解析YAML? [英] Why is Symfony2 app spending 70-90% of its time parsing YAML?

查看:156
本文介绍了为什么Symfony2应用程序花费70-90%的时间解析YAML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下面的Webgrind输出所示,我的应用程序将其大部分处理时间花费在YAML解析上。

As shown in the Webgrind output below, my app is spending most of its processing time on YAML parsing.

注意:Webgrind输出为百分比。所以加起来,总自我成本显示了处理YAML的总时间的83.63%。

Note: the Webgrind output is in "percent". So, adding up the "Total Self Cost" shows 83.63 percent of the total time is spent processing YAML.

我看过这个相关的主题:

I've seen this related thread:

Symfony2应用程序在每个请求中解析YML

然而,我的实现正在使用ApcClassLoader类,如下所示:

However, my implementation is using the ApcClassLoader class as seen below:

$loader = new ApcClassLoader('odr_dev', $loader);
$loader->register(true);

此外,我已经使用apc.php检查了APC系统,我的类和页面在APC缓存并正在被击中。即使在缓存被填充之后,也可以在任何一个请求的任何一个PROD或DEV上进行。

Additionally, I've checked the APC system using apc.php and my classes and pages are found in the APC cache and are being hit. This takes place on either PROD or DEV on any request even after the caches are populated.

我的理论是,我们有一个循环实体引用,系统不能成功解析YAML以缓存它。所以,它最终会尝试在每个请求中解析YAML。

My theory is that we have a circular entity reference and the system can't successfully parse the YAML in order to cache it. So, it ends up trying to parse the YAML on every request.

但是,我没有看到有关无法解析YAML或日志中的任何内容的任何错误,我不确定如何确定这可能是这种情况还是下一步。

However, I don't see any errors about being unable to parse YAML or anything in the logs and am unsure how to determine if this could be the case or where to look next.

推荐答案

在这个过程中,我发现Doctrine正在使用默认的数组缓存,只对单个页面加载有效。

After stepping through every line of code involved in this process, I found that Doctrine is using the default "array" cache which is only valid for a single page load.

我认为自己和许多其他人认为我们打开了APC,它也被Doctrine用于元数据缓存。事实上,除非另有说明,Doctrine默认为其数组缓存。

I think myself and many others assumed that when we turned on APC it would also be used by Doctrine for metadata caching. In fact, Doctrine defaults to its array cache unless otherwise specified.

此页面列出了Doctrine配置选项:

This page lists the Doctrine configuration options:

http://symfony.com/doc/2.3/reference/configuration/doctrine .html

将缓存驱动程序选项添加到我的 /app/config/config.yml 作为如下所示:

After adding cache driver options to my /app/config/config.yml as shown below:

doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true
        result_cache_driver:
            type: memcached
            host: 127.0.0.1
            port: 11211
            instance_class: Memcached
        metadata_cache_driver:
            type: memcached
            host: 127.0.0.1
            port: 11211
            instance_class: Memcached
        query_cache_driver:
            type: memcached
            host: 127.0.0.1
            port: 11211
            instance_class: Memcached

修复后,同一页面显示YAML解析器交互,并以302ms对5851ms加载,总加速为19X。此外,cachegrind文件从121MB变为3.4MB,这些结果在许多试验中基本一致。

After the fix, the same page shows no YAML parser interaction and loads in 302ms vs. 5851ms for a total speedup of 19X. Additionally, the cachegrind file went from 121MB to 3.4MB and these results are generally consistent over a number of trials.

以下是相同的Webgrind显示区别:

Here is the same Webgrind showing the difference:

所以,基本上这是一个配置问题。从我在StackOverflow问题和其他论坛中看到的内容,似乎有关于缓存如何工作的断开。基本上,您需要明确地对上述的Doctrine缓存进行开放,或者使用基本无用的默认值。

So, basically, it was a configuration issue. From what I've seen in StackOverflow questions and other forums, it seems there is a disconnect here about how caching works. Essentially, you need to explicitly turn it on for Doctrine caching as outlined above or it uses a basically useless default.

Symfony2有时可能是可配置的,这是一个我从来没有想到这是可以单独配置的实例。在这方面,这是一个强大的功能(可以为事情使用单独的缓存),但直到你知道这一点,系统就完全受到影响,就速度而言。

Symfony2 can sometimes be too "configurable" and this is one instance where it never occurred to me that it would be separately configurable. In that regard, it's a powerful feature (being able to use separate caches for things), but until you figure this out, the system is totally compromised as far as speed is concerned.

这篇关于为什么Symfony2应用程序花费70-90%的时间解析YAML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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