Symfony2性能调整

 公民不是百姓2 发布于 2023-02-04 13:53

Symfony2看起来如此有前途,强大而灵活.所以我们将在我们的一个项目中使用Symfony2 + mongodb.但它看起来太慢了(Apache/2.2.25 + PHP/5.4.20).目前该应用程序非常简单.但我注意到,当加载一些简单的页面时,httpd.exe将CPU高达28%.该页面非常精简 - 只是用户个人资料信息和他的帖子列表.如果性能不会好得多,我甚至无法想象如何为数百名用户提供服务(甚至不会谈论像100k用户这样的数字).

例如,当打开ActivationCloud帐户的重型"产品"页面(获取大量数据)时,CPU负载为2%(PHP + Smarty + SQL).

看一下Xdebug输出后,我发现ClassLoader-> loadClass(...)使用了20%的gret交易时间 - 265次调用 Xdebug Symfony2应用程序

执行以下步骤后:

*生成的类映射

php composer.phar dump-autoload --optimize

*已安装并启用APC

    [APC]
    extension=php_apc.dll

    apc.enabled=1
    apc.shm_segments=1

    ;32M per WordPress install
    apc.shm_size=128M

    ;Relative to the number of cached files (you may need to 
watch your stats for a day or two to find out a good number)
    apc.num_files_hint=7000

    ;Relative to the size of WordPress
    apc.user_entries_hint=4096

    ;The number of seconds a cache entry is allowed to idle
 in a slot before APC dumps the cache
    apc.ttl=7200
    apc.user_ttl=7200
    apc.gc_ttl=3600

    ;Setting this to 0 will give you the best performance, as APC will
    ;not have to check the IO for changes. However, you must clear 
    ;the APC cache to recompile already cached files. If you are still
    ;developing, updating your site daily in WP-ADMIN, and running W3TC
    ;set this to 1
    apc.stat=1

    ;This MUST be 0, WP can have errors otherwise!
    apc.include_once_override=0

    ;Only set to 1 while debugging
    apc.enable_cli=0

    ;Allow 2 seconds after a file is created before
 it is cached to prevent users from seeing half-written/weird pages
    apc.file_update_protection=2

    ;Leave at 2M or lower. WordPress does't have any file sizes close to 2M
    apc.max_file_size=2M

    ;Ignore files
    apc.filters = "/var/www/apc.php"

    apc.cache_by_default=1
    apc.use_request_time=1
    apc.slam_defense=0
    apc.mmap_file_mask=/var/www/temp/apc.XXXXXX
    apc.stat_ctime=0
    apc.canonicalize=1
    apc.write_lock=1
    apc.report_autofilter=0
    apc.rfc1867=0
    apc.rfc1867_prefix =upload_
    apc.rfc1867_name=APC_UPLOAD_PROGRESS
    apc.rfc1867_freq=0
    apc.rfc1867_ttl=3600
    apc.lazy_classes=0
    apc.lazy_functions=0

预计它会出现奇迹但它没有发生.

*启用APC类加载器 - 在Symfony\web\app.php中取消注释

/*
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
*/

ClassLoader-> loadClass(...)变得更好'Self'是11而不是21 经过一些调整后,Xdebug Symfony2应用程序

坦率地说,我对xdebug中看到的内容感到震惊:(很多重复调用,如Container-> get(...)-317调用,DocumentManager-> getClassMeataData(...) - 301次调用.总计超过2k的函数调用.很难相信.

这些捆绑包安装:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            ... our bundles ...

        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

很遗憾发现Symfony2获得了其他php框架中最糟糕的基准测试结果之一http://www.techempower.com/benchmarks/#section=data-r8&hw=i7&test=json&l=sg

与此同时,Francois Zaninotto在他的博客http://symfony.com/blog/who-really-uses-symfony中说雅虎使用Symfony2作为书签服务,尝试了一些应用程序列表http://trac.symfony- project.org/wiki/ApplicationsDevelopedWithSymfony - 他们在Quora http://www.quora.com/Who-is-using-Symfony2-in-production上看起来并不是很慢,因为每日运动也在使用它.

如何使性能可以接受?

1 个回答
  • 添加后,Symfony的工作速度提高了x10

    realpath_cache_size = 4096k
    

    到php.ini

    2023-02-04 13:55 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有