performance and optimization cakefest 2014

53
PROFILING & OPTIMIZATION Tools, guidelines, and techniques

Upload: markstory

Post on 28-May-2015

693 views

Category:

Software


0 download

DESCRIPTION

A talk I gave at Cakefest 2014

TRANSCRIPT

Page 1: Performance and optimization CakeFest 2014

PROFILING & OPTIMIZATIONTools, guidelines, and techniques

Page 2: Performance and optimization CakeFest 2014

PERFORMANCE

Page 3: Performance and optimization CakeFest 2014

WHY BOTHER?

Page 4: Performance and optimization CakeFest 2014

HIGHER CONVERSION RATES

Page 5: Performance and optimization CakeFest 2014

SLOW MOBILE CONNECTIONS

Page 6: Performance and optimization CakeFest 2014

CONSERVE CAPACITY

Page 7: Performance and optimization CakeFest 2014

RULES; MORE LIKE GUIDELINES

Page 8: Performance and optimization CakeFest 2014

Guideline

MEASURE EVERYTHING

Page 9: Performance and optimization CakeFest 2014

Guideline

HUNT THE BIG FISH

Page 10: Performance and optimization CakeFest 2014

Guideline

START CHEAP & ITERATE

Page 11: Performance and optimization CakeFest 2014

Cost Order

Minify assets

Compress images

Reduce the number of HTTP requests

Optimize database queries

Add caching

Code optimization

Page 12: Performance and optimization CakeFest 2014

JUNK UP FRONT

Page 13: Performance and optimization CakeFest 2014

Junk Up Front

Page 14: Performance and optimization CakeFest 2014

MeasuringChrome developer tools

Page 15: Performance and optimization CakeFest 2014

Junk up front

Number of requests

Number of hosts

Image count & image size

Script count & script size

Page 16: Performance and optimization CakeFest 2014

Fixing

Smushit (pngcrush, jpegtran, imagemagick)

Uglify.js, CSSMin

Make, phing, rake, grunt, shell scripts

Image sprites

Page 17: Performance and optimization CakeFest 2014

Guideline

AVOID WORK TO GO FASTER

Page 18: Performance and optimization CakeFest 2014

WEBSERVER TRICKS

Page 19: Performance and optimization CakeFest 2014

MeasuringChrome developer tools

Page 20: Performance and optimization CakeFest 2014

Webserver tricks

GZIP all the things.

Far Future cache headers.

Consider a CDN.

Page 21: Performance and optimization CakeFest 2014

SQL MOLASSES

Page 22: Performance and optimization CakeFest 2014

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.

Page 23: Performance and optimization CakeFest 2014

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.

Page 24: Performance and optimization CakeFest 2014

Explain QueriesVisual explain makes it easier.

Page 25: Performance and optimization CakeFest 2014

Indexes

Index commonly used columns.

Column order in matters in indexes.

Page 26: Performance and optimization CakeFest 2014

CACHING

Page 27: Performance and optimization CakeFest 2014

Caching

Can be expensive to rollout, if you need new infrastructure

Cache expiration is really really hard.

Page 28: Performance and optimization CakeFest 2014

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.

Page 29: Performance and optimization CakeFest 2014

Where to cache

Hopefully in Memcache/Redis

Failing that in Apc/Wincache

Files - Sometimes not faster.

Page 30: Performance and optimization CakeFest 2014

Optimize cache use

Watch cache miss rate.

Tune cache expiration so you miss less often.

Page 31: Performance and optimization CakeFest 2014

Guideline

OPTIMIZE CODE LAST, MOST OF THE TIME

Page 32: Performance and optimization CakeFest 2014

JAVASCRIPT

Page 33: Performance and optimization CakeFest 2014

PHP

Page 34: Performance and optimization CakeFest 2014

Javascript tools

Chrome dev tools are the gold standard.

CPU profiles are invaluable.

Heap comparisons can be used to find memory leaks.

Page 35: Performance and optimization CakeFest 2014

Cpu ProfilerChrome dev tools

Page 36: Performance and optimization CakeFest 2014

Cpu ProfilerChrome dev tools

Page 37: Performance and optimization CakeFest 2014

Cpu ProfilerChrome dev tools

Page 38: Performance and optimization CakeFest 2014

Cpu ProfilerChrome dev tools

Page 39: Performance and optimization CakeFest 2014

PHP TOOLS

Page 40: Performance and optimization CakeFest 2014

Debug KitDeeper insights into CakePHP

Page 41: Performance and optimization CakeFest 2014

XHProf

PECL extension produced by Facebook.

Captures runtime metrics at a function level.

Possible to use in a sub-sample of production unlike xdebug.

Page 42: Performance and optimization CakeFest 2014

XhguiNicer UI to XHProf data

Page 43: Performance and optimization CakeFest 2014

XhguiNicer UI to XHProf data

Page 44: Performance and optimization CakeFest 2014

XDebug

Not suitable for servers with traffic,

Very detailed results.

Page 45: Performance and optimization CakeFest 2014

WebgrindXDebug UI

Page 46: Performance and optimization CakeFest 2014

Other PHP tweaks

Opcode caching is a must.

Don’t use file based sessions.

Page 47: Performance and optimization CakeFest 2014

RECAP

Page 48: Performance and optimization CakeFest 2014

MEASURE EVERYTHING

Page 49: Performance and optimization CakeFest 2014

BE THRIFTY

Page 50: Performance and optimization CakeFest 2014

START IN THE FRONT

Page 51: Performance and optimization CakeFest 2014

AVOID WORK

Page 52: Performance and optimization CakeFest 2014

OPTIMIZE CODE

Page 53: Performance and optimization CakeFest 2014

THANKS