Upload
pascaldevink
View
549
Download
3
Tags:
Embed Size (px)
DESCRIPTION
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.
Citation preview
“More pageviews coming up?Improve page loading speed?
Add more boxes!”- Anonymous developer
Thursday, January 17, 13
Let’s speed it up a bit
Pascal de Vink (@pascaldevink)
13 performance optimizing strategies[*]
Thursday, January 17, 13
About me
Thursday, January 17, 13
Why does it matter?
Thursday, January 17, 13
So, it hurts...
Thursday, January 17, 13
So, it hurts...
• Your users
Thursday, January 17, 13
So, it hurts...
• Your users
• Your search ranking[1]
Thursday, January 17, 13
So, it hurts...
• Your users
• Your search ranking[1]
• Your profit[2]
Thursday, January 17, 13
Measure it
• Request/second benchmarking with AB or jmeter
• Page load speed with WebPageTest[3]
Thursday, January 17, 13
#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
#1 HTTP cache headers
• Add:
• But, be aware of its use, eg with authentication pages
Cache-Control: public max-age=[seconds]Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT
Thursday, January 17, 13
#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
#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
#4 CDN
• Content Delivery Network
• Used for streaming video
• Based on the browser limit of 2 requests (not applicable anymore)
Thursday, January 17, 13
#4 CDN
Thursday, January 17, 13
#4 CDN
• CloudFlare is a free CDN[6]
• Amazon CloudFront is cheap[7]
• Amazon S3 works too[8]
• Roll your own
Thursday, January 17, 13
#5 Static site generation
• Generate page(s) only if changed
• Hype: blogging on dropbox/github pages[9]
Thursday, January 17, 13
#6 Tune apache
• KeepAlive, KeepAliveTimeout, StartServers, MaxClients[10]
Thursday, January 17, 13
#6b Get rid of apache
Thursday, January 17, 13
#7 Opcode caching
• Pre-compiling PHP in memory[10]
• APC, eAccelerator, Zend server
Thursday, January 17, 13
#8 Varnish
• Load balancing
• Serving assets
• Maintenance mode
Thursday, January 17, 13
#9 Memcached• In-memory object caching system[11]
Thursday, January 17, 13
#10 Improve your SQL
• Use lazy-loading
• Tune MySQL[12]
• Use NoSQL
Thursday, January 17, 13
#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
#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
#13 Use output buffering
• Specially for huge pages
• StreamedResponse in Symfony 2.1
Thursday, January 17, 13
Bonus #14 Use Google SPDY
• Prioritizing & multiplexing
• Encryption & compression baked in
• Hint/push content
• Chromium, Firefox & Opera only
Thursday, January 17, 13
Bonus #15 Use WebSockets
• Faster then AJAX request
• Great for instant client communication
Thursday, January 17, 13
In conclusion• #1 HTTP Cache Headers
• #2 GZIP Compression
• #3 Minification
• #4 CDN
• #5 Static site generation
• #6 Tune or ditch Apache
• #7 Opcode caching
• #8 Varnish
• #9 Memcached
• #10 Improve your SQL
• #11 Load it off the request
• #12 Improve file handling
• #13 Use output buffering
• Bonus #14 Use Google SPDY
• Bonus #15 Use websockets
Thursday, January 17, 13
One more thing
Thursday, January 17, 13
One more thing
Thursday, January 17, 13
One more thing
Thursday, January 17, 13
Questions?
@pascaldevink
https://joind.in/talk/view/8066
Thursday, January 17, 13
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-installation
Thursday, January 17, 13