performance and optimization cakefest 2014
DESCRIPTION
A talk I gave at Cakefest 2014TRANSCRIPT
PROFILING & OPTIMIZATIONTools, guidelines, and techniques
PERFORMANCE
WHY BOTHER?
HIGHER CONVERSION RATES
SLOW MOBILE CONNECTIONS
CONSERVE CAPACITY
RULES; MORE LIKE GUIDELINES
Guideline
MEASURE EVERYTHING
Guideline
HUNT THE BIG FISH
Guideline
START CHEAP & ITERATE
Cost Order
Minify assets
Compress images
Reduce the number of HTTP requests
Optimize database queries
Add caching
Code optimization
JUNK UP FRONT
Junk Up Front
MeasuringChrome developer tools
Junk up front
Number of requests
Number of hosts
Image count & image size
Script count & script size
Fixing
Smushit (pngcrush, jpegtran, imagemagick)
Uglify.js, CSSMin
Make, phing, rake, grunt, shell scripts
Image sprites
Guideline
AVOID WORK TO GO FASTER
WEBSERVER TRICKS
MeasuringChrome developer tools
Webserver tricks
GZIP all the things.
Far Future cache headers.
Consider a CDN.
SQL MOLASSES
Database slowness
Many backend performance issues are caused by too many, or slow queries.
Mysql has a pretty terrible query planner.
Sub-queries and derived table joins will eventually catch fire.
Slow query logs, mtop, or monitoring like new relic are your best friend.
Database slowness
Slow query logs - Percona makes great tools for MySQL.
Disable query caching.
Run EXPLAIN on slow queries.
Add indexes/tweak queries, and repeat.
Explain QueriesVisual explain makes it easier.
Indexes
Index commonly used columns.
Column order in matters in indexes.
CACHING
Caching
Can be expensive to rollout, if you need new infrastructure
Cache expiration is really really hard.
What to Cache
Results that don’t change often
Use monitoring/analytics to find the busiest pages.
Start using caching there.
Expand once you’ve learned more.
Where to cache
Hopefully in Memcache/Redis
Failing that in Apc/Wincache
Files - Sometimes not faster.
Optimize cache use
Watch cache miss rate.
Tune cache expiration so you miss less often.
Guideline
OPTIMIZE CODE LAST, MOST OF THE TIME
JAVASCRIPT
PHP
Javascript tools
Chrome dev tools are the gold standard.
CPU profiles are invaluable.
Heap comparisons can be used to find memory leaks.
Cpu ProfilerChrome dev tools
Cpu ProfilerChrome dev tools
Cpu ProfilerChrome dev tools
Cpu ProfilerChrome dev tools
PHP TOOLS
Debug KitDeeper insights into CakePHP
XHProf
PECL extension produced by Facebook.
Captures runtime metrics at a function level.
Possible to use in a sub-sample of production unlike xdebug.
XhguiNicer UI to XHProf data
XhguiNicer UI to XHProf data
XDebug
Not suitable for servers with traffic,
Very detailed results.
WebgrindXDebug UI
Other PHP tweaks
Opcode caching is a must.
Don’t use file based sessions.
RECAP
MEASURE EVERYTHING
BE THRIFTY
START IN THE FRONT
AVOID WORK
OPTIMIZE CODE
THANKS