I gave this talk on 4/27/11 at the Boston PHP Meetup Group. It covers both server side and client side optimizations, as well as monitoring tools and techniques.
Developer Data Modeling Mistakes: From Postgres to NoSQL
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
1. Web Performance, Scalability, and Testing Techniques Boston PHP Meetup Group – April 2011 Jonathan Klein jklein@csnstores.com @jonathanklein
2. What We’ll Cover Why Listen to Me? Why Performance Matters Measuring Server Side Performance Speeding up the Server Frontend Optimization Measuring Full Page Load Time Homework
3. What We’ll Cover Why Listen to Me? Why Performance Matters Measuring Server Side Performance Speeding up the Server Frontend Optimization Measuring Full Page Load Time Homework Fun Performance Adventure!
4. Introduction Senior Software Engineer/Performance Guy at CSN Stores Organizer of the Boston Web Performance Meetup Group CSN Stores Stats: ~1400 requests/sec for static content ~400 requests/sec for dynamic content ~10 million unique visitors per month On a typical Monday we serve 75,000,000 static files
5. Currently converting all store code to PHP Windows Server FreeBSD IIS Lighttpd ~100,000 lines of ASP Classic ~50,000 lines of PHP code ~5 weeks away from launch
6. Why Do We Care about Performance? A Faster Website Will Make You More Money
7.
8. Firefox Firefox reduced the load time of their download page by 2.2 seconds Downloads went up 15.4% This could drive 60 MILLION yearly downloads
9. Google Injected a 400ms delay into search 0.44% fewer searches/user 0.76% after 6 weeks After delay was removed, 0.21% fewer searches
13. Server Side Monitoring Lots of Options: Paid: Coradiant dynaTrace Correlsense http://www.real-user-monitoring.com/ - Free Version Free: Access Logs Nagios Ganglia Hosted WebPagetest Selenium/dynaTrace Ajax Edition
14. Server Side Monitoring <?php $start = microtime(true); …script content… $end = microtime(true); do_stuff(‘Description’, $end - $start); ?>
15. WTH is do_stuff()? do_stuff() can do one of: Log to a database (not ideal) Write to a text file (eww) Make a StatsD call over UDP (good) -http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/
26. Database Optimizations Reduce Joins Select * from Select Foo, Bar, Baz from… Minimize/consolidate subqueries Add indexes where needed We added one index: Procedure dropped from 3.5 sec & 4500 reads to .06 sec and 130 reads! Be careful with where clauses (don’t calculate stuff in them)
27. Example SELECT id, name, salary FROM employee WHERE salary < 25000; NOT SELECT id, name, salary FROM employee WHERE salary + 10000 < 35000;
28. Example SELECT id, name, salary FROM employee WHERE salary < 25000; NOT SELECT id, name, salary FROM employee WHERE salary + 10000 < 35000;
36. PHP Code Optimizations Set the max loop value before the loop: $max = count($rows); for ($i = 0; $i < $max; $i++) { echo $i; } require_once() is slow Minimize use of define() Yes, single quotes are slightly faster than double quotes
37. PHP Code Optimizations Could go on and on… http://www.wmtips.com/php/tips-optimizing-php-code.htm Minimal returns Find the hotspots in your application and fix them
38. Example… Homepage takes 5 seconds to load Optimize PHP… Reduce PHP execution time by 50%! But wait! PHP execution was only taking 100ms Saves you 50ms in load time 1% of total page load
39. HipHop for PHP Built by Facebook and Open Sourced Compiles PHP into C++ Currently supports PHP 5.2 http://developers.facebook.com/blog/post/358/ https://github.com/facebook/hiphop-php
41. Webserver Optimizations Pick the right one Lighttpd/Nginx instead of Apache Designed to solve the C10K problem Lighttpd Used By: Youtube Wikipedia Meebo
42.
43. If you are stuck on Apache… mod_deflate Gzips content for faster transfer times mod_pagespeed Automatic performance improvements KeepAlives on Server won’t create a new connection for every resource
50. Client side Optimization is Critical 80-90% of load time takes place on the client For mobile 97%
51. Best Practices Reduce HTTP Requests Combine CSS, JS Use image sprites .classname{ background: url(sprite.png) no-repeat 0 -432px; }
52. Best Practices Minify CSS/JS Strip comments and whitespace Automate this – YUI Compressor http://developer.yahoo.com/yui/compressor/ Gzip all text HTML CSS JS Optimize Images…
53. Image Optimization For graphics use PNG8 (256 color limitation) No more .gif (unless animated) JPEGs can be saved at lower quality (75%-80%) Smush all images
64. Expires Headers Set a far future date on static resources CSS/JS/Images Release new version by changing the filename Benefits repeat visitors and repeat page views
79. Conclusion “Speed is the most important feature. If your application is slow, people won’t use it. I see this more with mainstream users than I do with power users...If something is slow, they’re just gone.” - Fred Wilson (10 Golden Principles of Web Apps)
80. Conclusion “Speed is the most important feature. If your application is slow, people won’t use it. I see this more with mainstream users than I do with power users...If something is slow, they’re just gone.” - Fred Wilson (10 Golden Principles of Web Apps)
81. ?> We’re Hiring! www.csnstores.com/careers Get In Touch: www.meetup.com/Web-Performance-Boston/ jklein@csnstores.com @jonathanklein