This document summarizes 13 strategies for optimizing website performance: 1) adding HTTP cache headers, 2) minification, 3) GZIP compression, 4) using a CDN, 5) static site generation, 6) tuning Apache settings, 7) using opcode caching, 8) implementing Varnish, 9) leveraging Memcached, 10) improving SQL, 11) offloading tasks, 12) optimizing file handling, and 13) output buffering. Additional bonuses include using SPDY and WebSockets. Measuring performance and various Apache, PHP, and database configuration tips were also discussed.
7. So, it hurts...
• Your users
• Your search ranking
[1]
Thursday, January 17, 13
8. So, it hurts...
• Your users
• Your search ranking
[1]
• Your profit[2]
Thursday, January 17, 13
9. Measure it
• Request/second benchmarking with AB or
jmeter
• Page load speed with WebPageTest[3]
Thursday, January 17, 13
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 Nottingham
Thursday, January 17, 13
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 pages
Thursday, January 17, 13
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 tools
Thursday, January 17, 13
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
23. #10 Improve your SQL
• Use lazy-loading
• Tune MySQL [12]
• Use NoSQL
Thursday, January 17, 13
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 updates
Thursday, January 17, 13
25. #12 Improve your file
handling
• Reduce your include_path to a single entry or don't
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. #13 Use output buffering
• Specially for huge pages
• StreamedResponse in Symfony 2.1
Thursday, January 17, 13
27. Bonus #14 Use Google
SPDY
• Prioritizing & multiplexing
• Encryption & compression baked in
• Hint/push content
• Chromium, Firefox & Opera only
Thursday, January 17, 13
28. Bonus #15 Use
WebSockets
• Faster then AJAX request
• Great for instant client communication
Thursday, January 17, 13
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 Memcached
Thursday, January 17, 13