Let's speed it up a bit (AmsterdamPHP)

737 views

Published on

It is said that when asking people how a website can be optimised for speed, about 14 answers come up. For both simple HTML sites on shared hosting and advanced multi-server web applications, I'm sharing these answers as strategies to speed up your (php powered) website in this talk.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
737
On SlideShare
0
From Embeds
0
Number of Embeds
25
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Let's speed it up a bit (AmsterdamPHP)

  1. 1. “More pageviews coming up? Improve page loading speed? Add more boxes!” - Anonymous developerThursday, January 17, 13
  2. 2. Let’s speed it up a bit 13 performance optimizing strategies[*] Pascal de Vink (@pascaldevink)Thursday, January 17, 13
  3. 3. About meThursday, January 17, 13
  4. 4. Why does it matter?Thursday, January 17, 13
  5. 5. So, it hurts...Thursday, January 17, 13
  6. 6. So, it hurts... • Your usersThursday, January 17, 13
  7. 7. So, it hurts... • Your users • Your search ranking [1]Thursday, January 17, 13
  8. 8. So, it hurts... • Your users • Your search ranking [1] • Your profit[2]Thursday, January 17, 13
  9. 9. Measure it • Request/second benchmarking with AB or jmeter • Page load speed with WebPageTest[3]Thursday, January 17, 13
  10. 10. #1 HTTP cache headers “If the content of the script changes only depending on what’s in the URL, it is cacheable; if the output depends on a cookie, authentication information or other external criteria, it probably isn’t”[4] - Mark NottinghamThursday, January 17, 13
  11. 11. #1 HTTP cache headers • Add:Cache-Control: public max-age=[seconds] Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT • But, be aware of its use, eg with authentication pagesThursday, January 17, 13
  12. 12. #2 Minification • Place javascript at the bottom of the html • Place CSS at the top of the html • Use Minify JavaScript & CSS • Always write JavaScript & CSS in external file • Try to reduce number of JavaScript & CSS files • Assetic[5] can help you use toolsThursday, January 17, 13
  13. 13. #3 GZIP compression <IfModule mod_deflate.c> SetOutputFilter DEFLATE # Don’t compress SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary #Dealing with proxy servers <IfModule mod_headers.c> Header append Vary User-Agent </IfModule> </IfModule>Thursday, January 17, 13
  14. 14. #4 CDN • Content Delivery Network • Used for streaming video • Based on the browser limit of 2 requests (not applicable anymore)Thursday, January 17, 13
  15. 15. #4 CDNThursday, January 17, 13
  16. 16. #4 CDN • CloudFlare is a free CDN[6] • Amazon CloudFront is cheap [7] • Amazon S3 works too [8] • Roll your ownThursday, January 17, 13
  17. 17. #5 Static site generation • Generate page(s) only if changed • Hype: blogging on dropbox/github pages[9]Thursday, January 17, 13
  18. 18. #6 Tune apache • KeepAlive, KeepAliveTimeout, StartServers, MaxClients[10]Thursday, January 17, 13
  19. 19. #6b Get rid of apacheThursday, January 17, 13
  20. 20. #7 Opcode caching • Pre-compiling PHP in memory[10] • APC, eAccelerator, Zend serverThursday, January 17, 13
  21. 21. #8 Varnish • Load balancing • Serving assets • Maintenance modeThursday, January 17, 13
  22. 22. #9 Memcached • In-memory object caching system[11]Thursday, January 17, 13
  23. 23. #10 Improve your SQL • Use lazy-loading • Tune MySQL [12] • Use NoSQLThursday, January 17, 13
  24. 24. #11 Load it off the request • Message queues (ActiveMQ, RabbitMQ) • Load off : • Mails (notifications) • Background changes (change of product 1 changes product 2) • Logging (non vital) • Cache updatesThursday, January 17, 13
  25. 25. #12 Improve your file handling • Reduce your include_path to a single entry or dont use it at all • Include or require absolute paths • Ensure that each try to include a file is a hit • Avoid file_exists(), is_file(), is_dir(), is_link() etc. • Avoid autoloading[13]Thursday, January 17, 13
  26. 26. #13 Use output buffering • Specially for huge pages • StreamedResponse in Symfony 2.1Thursday, January 17, 13
  27. 27. Bonus #14 Use Google SPDY • Prioritizing & multiplexing • Encryption & compression baked in • Hint/push content • Chromium, Firefox & Opera onlyThursday, January 17, 13
  28. 28. Bonus #15 Use WebSockets • Faster then AJAX request • Great for instant client communicationThursday, January 17, 13
  29. 29. In conclusion • #1 HTTP Cache Headers • #10 Improve your SQL • #2 GZIP Compression • #11 Load it off the request • #3 Minification • #12 Improve file handling • #4 CDN • #13 Use output buffering • #5 Static site generation • Bonus #14 Use Google • #6 Tune or ditch Apache SPDY • #7 Opcode caching • Bonus #15 Use • #8 Varnish websockets • #9 MemcachedThursday, January 17, 13
  30. 30. One more thingThursday, January 17, 13
  31. 31. One more thingThursday, January 17, 13
  32. 32. One more thingThursday, January 17, 13
  33. 33. Questions? https://joind.in/talk/view/8066 @pascaldevinkThursday, January 17, 13
  34. 34. References • infographics: http://mashable.com/2012/11/22/slow-websites/ • varnish: http://deglos.com/blog/2010/09/22/drupal-and-varnish-quick-intro • Webservers performance http://www.rootusers.com/web-server-performance-benchmark/ • [1] http://copperegg.com/slow-websites-hurt-search-engine-rankings/ • [2] http://econsultancy.com/nl/blog/11274-67-of-consumers-cite-slow-websites-as-the-main-cause-of-basket-abandonment • [3] http://www.webpagetest.org • [4] http://www.mnot.net/cache_docs/ • [5] http://symfony.com/doc/2.0/cookbook/assetic/asset_management.html • [6] http://www.cloudflare.com/ • [7] http://aws.amazon.com/cloudfront/ • [8] http://aws.amazon.com/s3/ • [9] http://octopress.org/ • [10] http://www.bootstrappingindependence.com/technology/how-to-improve-website-performance-with-drupal-php-mysql-and-apache/ • [11] http://memcached.org/ • [12] http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installationThursday, January 17, 13

×