9

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.

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.

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

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.

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.

Edit:

Some information about the testing environment:

  • 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.

4
  • Are you caching the doctrine stuff queries and metadata too?
    – qooplmao
    Aug 20, 2014 at 13:08
  • This is a broad question. Are your running on prod environment? Did you manage to find where is your performance bottleneck? What operating system and php version are you using?
    – Touki
    Aug 20, 2014 at 13:11
  • @Touki I updated my post and added the requested information. We're also running on prod and cached everything possible. Aug 20, 2014 at 13:49
  • Just to address one point: Autoload does not load all classes. There is a cache file that loads quite a few common Symfony classes but by no means all of them. Not even close. And I know you said you are running in production mode but you might want to double check.
    – Cerad
    Aug 20, 2014 at 16:04

3 Answers 3

14

These points can optimise your application performance:

  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.

  2. NGINX is faster than Apache and the configuration is easier.

  3. 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

  4. 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.

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

PHP articles:

Symfony2 and Twig articles:

Others optimisations:

  • Maybe you can use an updated version of Ubuntu.
  • Personally, I prefer using Debian which is also popular for servers because it's very stable.
  • Using a cache proxy like Varnish can be a finishing touch.
  • Varnish requires a developer's implication and maybe a formation. Using NGINX FastCGI Cache to limit FastCGI requests to HHVM, FPM or PHP-NG can resolve speed response.
3
  • 1
    Thanks so far for your answer. Unfortunately, the provided articles are all written in French, and even after hardly focusing on it - I just can't understand a word. :( Are there by any chance any English versions? Aug 20, 2014 at 16:18
  • Yes you have completely reason. I have added few articles in english, I think that you have all tracks for optimize your solution. Aug 21, 2014 at 7:58
  • 1
    Thanks for updating your post. We took a look into each of your suggestions and were able to significantly decrease the loading time of our API to under 0.1 seconds, which is awesome and suits our requirements! Thank you very much for your help, +accept your answer. Aug 22, 2014 at 10:25
2

Did you look this blog post ? http://symfony.com/blog/push-it-to-the-limits-symfony2-for-high-performance-needs

According to your information, i can advise you to try php 5.5 or 5.6 and NGINX with PHP-FPM, it can 40% faster or more.

0

You can try approach suggested in this article: http://stfalcon.com/en/blog/post/performance-symfony2-doctrine2-orm

The author suggests to:

  • Download all necessary connections
  • Update multiple entities by request
  • Get data as an associative array
  • Use reference proxies
  • Don't forget to use Symfony profiler toolbar

The code described is availiable on github: https://github.com/lensky84/performance

1
  • Please add the most important parts of the linked article as part of your answer.
    – CSchulz
    Jun 6, 2016 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.