-2

I've built a web application with Symfony 3.1 and PHP 7. On my own computer it's running fine, but on the web server it's very slow. Now I want to know why. Not only to have that web app to run faster, but to understand some more about the software itself.

My own computer is has an Intel i7 processor and 8 GB of RAM, running on Ubuntu 16.10. The server has two cores, 4 GB of RAM and runs on CentOS 6.

Comparison between laptop and server

My laptop

My computer

The web server:

My web server

They are different in terms of both hard- and software, so I don't expect them to be completely the same, but I don't understand why there is a huge difference between them: Symfony initialization is 13x faster, the rendering of Twig templates is 25x faster.

I used the Symfony profiler and Blackfire.io to find out why my application is slow, but that only explains the performance of the application itself. Since the page is a lot faster on my computer, I've to find out why the application is slower on my web server.

IOPS?

I found this blog how to test the disk performance using fio. I found that my computer performs about 20x better than the server (19.9K/6718 vs 1056 /375 iops). It seems like iops is the bottle neck.

What's next?

One solution is very simple: get a server with better iops performance.

But how do I find out how I can improve my application? Or maybe my web servers' settings? I've installed Opcache and as far as I can see (using this tool), it's working fine.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97

1 Answers1

3

1 - Check if opcache is activated and well configured. Increase the value of opcache.max_accelerated_files to the maximum because Symfony load tons of files.

2 - Generate a richer class map for the autoload process, run this command : composer dump-autoload --optimize.

3 - Get a SSD disk on your server. You don't need a lot of space, 128gb is far enough for Symfony, and use a normal disk for your assets if you need a lot of extra space.

4 - Use a RAM cache like Redis or Memcache. For example I reduced by 200% my load time on Windows after I installed Redis and configured properly Doctrine in my config.yml file

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true
    metadata_cache_driver:
        type: service
        id: doctrine.cache
    query_cache_driver:
        type: service
        id: doctrine.cache
    result_cache_driver:
        type: service
        id: doctrine.cache

And the service file :

  doctrine.cache:
    class: Doctrine\Common\Cache\PredisCache
    arguments: [ "@redis" ]

If nothing works, get an other server :)

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Raphaël Malié
  • 3,912
  • 21
  • 37
  • Thanks! 1. Opcache is activated and working fine. 2. Already done. 3. Server has small SSD, but provider says their newer setup has even faster storage. Will try to move to newer VPS. 4. Will try it! – Stephan Vierkant Nov 25 '16 at 15:59