Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Performance tips for Symfony2 & PHP

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 37 Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Anzeige

Ähnlich wie Performance tips for Symfony2 & PHP (20)

Anzeige

Performance tips for Symfony2 & PHP

  1. 1. PERFORMANCE TIPS FOR SYMFONY2 & PHP Minsk PHP User Group Meetup #10
  2. 2. Intro  Max Romanovsky  37 Slides  Questions after presentation  Out of scope: HW & OS tuning, VM vs HW servers  “Premature optimization is the root of all evil” Knuth’s quote is missing  No cats, boobs or other images in slides  2
  3. 3. Quiz 3  What to optimize?  Architecture  Code  Services
  4. 4. Agenda  Overview  Measure  Services  Architecture  Code  Symfony2 tips 4
  5. 5. 5 Overview
  6. 6. How to start?  Forget about microoptimizations for now  Курочка по зернышку – весь двор в говне  Make it scalable  What is cheaper? To scale or to optimize? 6
  7. 7. Tune  Tune services  Tune architecture  Consider tuning code 7
  8. 8. Quiz 8  What was the sloooooowest?  DB queries  Network communication  PHP configuration  VM/HW server  Stupid code
  9. 9. What could be slow 9  Network communication (with client, inside LAN)  VM/HW server  OS & runtime itself  Communication with services  Code (finally!)
  10. 10. 10 Measure
  11. 11. Stop! Measure 11  Measure before  Measure during  Measure after  Measure periodically  measure  Measure  MEASURE!!1
  12. 12. Quiz 12  What do you use?  Symfony Profiler  symfony/stopwatch  Из говна и палок  Xhprof  Xdebug  Zend Profiler
  13. 13. Tools 13  Xhprof / uprofiler  Xdebug   Framework tools    = overhead & irrelevant results
  14. 14. Question 14  Can we compare xhprof & xdebug results?  Are they relevant?
  15. 15. Overhead & irrelevant results? 15  Runtime (i.e. code execution) is slower with profiler enabled  Communication with services is not slower  Mess in results  You are analyzing DIFFERENT results
  16. 16. Use lightweight profiler 16  XHProf  XHgui (saves runs to RDBMS)  Uprofiler (fork?)  https://github.com/FriendsOfPHP/uprofiler
  17. 17. Measure performance in real world 17  Turn on profiler periodically  For 1% of requests  For 1 app server  Record & replay user activity  Use Jmeter to record scenarios  Use good old ab, siege, http_load
  18. 18. Tune 18  Tune 1 factor at once  Store configuration & measuring results in VCS  Measure after tuning
  19. 19. 19 Services
  20. 20. Why? 20  Receive profit without changing a single line of code
  21. 21. Question 21  Do you know what is an Opcache?  Do you use it?
  22. 22. PHP 22  Don’t use the latest PHP version, please!  Use PHP-FPM (or even HHVM?)  Opcache or APC  APCu  Compile stable libraries as PHP extensions  Twig  Redis  AMQP
  23. 23. Composer 23  composer install --optimize-autoloader
  24. 24. 24 Architecture
  25. 25. Architecture  Make it scalable. Period.  Use PAAS services  CDN  File storage  Choose efficient protocols & frameworks  Apache Thrift  Google Protocol Buffers 25
  26. 26. Cache 26  Raw data  Computed data  View layer
  27. 27. Cache 27  Raw data = DB/Data Source  MySQL query cache  HTTP API reverse proxy cache
  28. 28. Cache 28  Computed data = Key-value  Persistent?  Consistent?  Check your DB features
  29. 29. Cache 29  View layer = HTTP cache  Nginx  Varnish
  30. 30. 30 Code
  31. 31. Why not to optimize 31  Improve architecture  Man, it’s PHP! It is designed to be SLOOOOW  Optimize code for people, not for machines  Курочка по зернышку?..  Well… OK. But profile
  32. 32. What to optimize. Boooring 32  DB  Move calculations to DB  Move aggregation to DB  MOVE LIMIT TO DB!!1  Move calculations outside the loop  Don’t concatenate string insanely  Don’t pass huge arrays by value to functions  Don’t use arrays anyway 
  33. 33. 33 Symfony2 tips
  34. 34. As seen on TV 34  http://symfony.com/doc/current/book/performa nce.html  Use a Byte Code Cache  Composer's Class Map  Caching the Autoloader with APC  Use Bootstrap Files
  35. 35. Tipzzz 35  Services  Lazy with ocramius/proxy-manager  Controllers  Console commands  Move app/cache to tmpfs  Twig C extension  Don’t use router:dump. It’s deprecated  https://github.com/symfony/symfony/issues/9652  Don’t use Symfony Profiler for profiling 
  36. 36. More? 36  http://symfony.com/blog/push-it-to-the-limits-symfony2- for-high-performance-needs  https://www.youtube.com/watch?v=b8ewqVGu 77w  https://profiler.sensiolabs.com/ - still waiting for invite
  37. 37. The End 37  max.romanovsky@gmail.com  http://maxromanovsky.com

×