Symfony2看起来很有前途,功能强大且灵活。所以我们打算在我们的项目中使用Symfony2 + mongodb。但它似乎太慢(Apache/2.2.25 + PHP/5.4.20)。目前该应用程序非常简单。但我已经注意到,当加载一些简单的页面时,httpd.exe将CPU的CPU高达28%。该页面非常精简 - 只是用户简介信息和他的帖子列表。如果性能不会更好,我甚至无法想象如何为数百个用户提供服务(甚至不会谈论像100k用户这样的数字)。Symfony2性能调整
例如CPU负载2%打开重的产品页面ActivationCloud帐户(其获取数据的一个很好的量)(PHP + Smarty的+ SQL)时。
承担Xdebug的输出后一看,我发现时间GRET交易的20%是由ClassLoader->的loadClass(...)使用 - 265个电话
执行以下步骤之后:
*生成的类图
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 \网络\ app.php注释掉
/*
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
*/
的ClassLoader->的loadClass(...)变得更好 '自我' 是11,而不是21
坦率地说,我对我在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
同时弗朗索瓦Zaninotto在他的博客中说http://symfony.com/blog/who-really-uses-symfony Yahoo使用对于书签服务Symfony2,尝试了一些应用程序形式列表http://trac.symfony-project.org/wiki/ApplicationsDevelopedWithSymfony - 他们也没有看起来很慢,Quora http://www.quora.com/Who-is-using-Symfony2-in-production它的发言dailymotion也使用它。
如何使表演可以接受?
不知道关于他的答案的休息,但作为1ED提到;确保你有三个教义的缓存打开,这是一个巨大的差异。另外,你是否在产品或开发环境中运行这些测试? – Mathew