Symfony 2性能优化 [英] Symfony 2 performance optimisations

查看:151
本文介绍了Symfony 2性能优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在寻找一个将来可以使用的PHP框架,目前正在使用Symfony 2进行测试.为此,我们重新设计了API,并将其作为一个捆绑在Symfony中实现.事实证明,Symfony似乎非常慢-实际上比我们旧的(甚至设计欠佳)的系统慢.

We're looking for a PHP framework to work with in future and are currently testing out things with Symfony 2. For this, we've redesigned our API and implemented it as a bundle in Symfony. It turned out that Symfony seems to be very slow - actually far slower than our old (not even well-designed) system.

我们试图通过缓存字节码(为此使用APC)来优化性能.尽管我们注意到性能有了很大的提高(之前:加载API大约需要3秒;之后:平均需要0.6秒(比没有 APC的旧系统还要慢0.5秒)",但我们有点激动-但对于像从几乎空的数据库中获取结果之类的简单任务的高加载时间仍然不满意.

We tried to optimise the performance by caching the byte code (using APC for this). While we've noticed a huge improvement in performance (before: about 3 seconds to load the API; after: 0.6 seconds in average (still 0.5 seconds slower than our old system without APC)), we're kind of excited - but still not really pleased with the high loading time of such an easy task like getting one result out of an almost empty database.

我不知道,但是我可以想像这是由于Symfony自动加载了所有类,即使对于特定的捆绑包而言并不需要.

I don't know, but I could imagine this is due to Symfony autoloading all classes, even when not needed for a specific bundle.

现在,在深入研究Symfony之前,我们想寻求进一步的优化,可能是一种排除特定捆绑软件中不需要组件的方法,因为我个人认为这会带来很大的不同.

Now, before we deep-six Symfony, we'd like to look out for further optimisations, possibly a way to exclude unneeded components in a specific bundle, as I personally think this would make a big difference.

对于任何有关如何进一步提高性能的想法,使用Symfony的经验报告或任何对我们寻找框架可能有帮助的其他事情,我将深表感谢.

I'd be thankful for any ideas on how to further improve the performance, experience reports with using Symfony or anything else that could be helpful for us on the lookout for a framework.

有关测试环境的一些信息:

Some information about the testing environment:

  • 操作系统: Ubuntu 12.04.4 LTS(GNU/Linux 3.8.0-38-通用x86_64)
  • Apache版本: Apache/2.2.22(Ubuntu)
  • PHP版本: 5.3.10-1ubuntu3.13
  • 可观的PHP扩展: apc
  • Operating system: Ubuntu 12.04.4 LTS (GNU/Linux 3.8.0-38-generic x86_64)
  • Apache version: Apache/2.2.22 (Ubuntu)
  • PHP version: 5.3.10-1ubuntu3.13
  • Considerable PHP extensions: apc

此外,所有测试都在我们系统的本地副本上完成,因此可以排除可能的网络问题.

Also, all tests are done on a local copy of our system, so possible network issues can be excluded.

推荐答案

这些要点可以优化您的应用程序性能:

These points can optimise your application performance:

  1. 升级PHP. PHP 5.3和PHP 5.4之间的性能提升非常高. PHP 5.5可能会更好,但是并非所有发行版都支持,例如Debian 7.

  1. Upgrade PHP. The performance gain between PHP 5.3 and PHP 5.4 is very high. PHP 5.5 would be even better, but it's not supported by all distributions, like Debian 7.

NGINX比Apache更快,并且配置更容易.

NGINX is faster than Apache and the configuration is easier.

结合使用PHP-FPM和NGINX是一个很好的组合.如果您用Grunt替换Symfony/Assetic,您还可以使用HHVM运行PHP,该速度平均比PHP-FPM快2倍. 警告:HHVM在安全部署之前需要更多的预防措施和测试.您可以关注这两篇文章(法文): JoliCode 大Brains Company

Using PHP-FPM with NGINX is a good combination. You can also run your PHP with HHVM which is in average 2x faster than PHP-FPM, provided you replace Symfony/Assetic with Grunt. Caution: HHVM requires more precaution and testing before deploying safely. You can follow these two articles (in French): JoliCode and Big Brains Company

不建议使用PHP APC扩展.我认为XCache,Memcached或Redis更好,并且目前最受支持.对于PHP> = 5.5,APCu可以替代APC.

PHP APC extension is deprecated. I think that XCache, Memcached or Redis are better, and they're also most supported at the moment. For PHP >= 5.5, APCu can be used as a replacement for APC.

此外,您还可以阅读一些有关Symfony2优化并提供Twig基准测试的文章.

Additionally, you can read a few articles which talk about Symfony2 optimisation and provide Twig benchmarks.

PHP文章:

  • Script high-performance in French
  • Comparison of PHP 5.3 and PHP 5.6 performance in French
  • Check this article to apprehend the PHP optimisation in French
  • Google's recommendations for optimising PHP applications in English
  • 10 best pratices to optimise PHP in English

Symfony2和Twig文章:

Symfony2 and Twig articles:

  • Symfony documentation gives a few tips how to build a performant application in English
  • Template optimisation in French
  • Twig include optimisation in French
  • Use @Cache annotation requests in English
  • Symfony2: Good practices in French
  • Limit the usage of unnecessary bundles
  • Symfony2 Twig performance optimisation in English
  • If you don't want to use the Twig Engine, you can disable it in French
  • Caching in Symfony from it's Cookbook - really impressive!

其他优化:

  • 也许您可以使用Ubuntu的更新版本.
  • 我个人更喜欢使用Debian,因为它非常稳定,因此在服务器上也很流行.
  • 使用像Varnish这样的缓存代理可以画龙点睛.
  • 清漆需要开发人员的暗示,也可能需要形式.使用NGINX FastCGI缓存将FastCGI请求限制为HHVM,FPM或PHP-NG可以解决速度响应.

这篇关于Symfony 2性能优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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