PHPDay 2013 - High Performance PHP
Upcoming SlideShare
Loading in...5
×
 

PHPDay 2013 - High Performance PHP

on

  • 7,596 views

This is a talk that I gave in Verona, Italy at PHPDay 2013 on May 18th.

This is a talk that I gave in Verona, Italy at PHPDay 2013 on May 18th.

Statistics

Views

Total Views
7,596
Views on SlideShare
7,246
Embed Views
350

Actions

Likes
10
Downloads
80
Comments
0

4 Embeds 350

http://jkle.in 341
http://news.live.dev.cheggnet.com 6
http://localhost 2
http://www.jkle.in 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Not a general improvement - test YOUR site
  • Halfway through, SLOW DOWN!
  • Talk about how APC is local to the machine
  • HipHop VM has made development easier

PHPDay 2013 - High Performance PHP PHPDay 2013 - High Performance PHP Presentation Transcript

  • HighPerformance PHPPHPDay 2013Jonathan Klein@jonathankleinSaturday, May 18, 13
  • Slides, Links:jkle.in/phpdaySaturday, May 18, 13
  • Some Etsy Stats• 1.4 billion page views/month• Almost $1B in sales last year• Over 1M lines of PHPSaturday, May 18, 13
  • Agenda• Why Performance Matters• Profiling PHP Applications• Code Level Optimizations• Big Wins• Load Testing• TakeawaysSaturday, May 18, 13
  • The Value ofPerformanceSaturday, May 18, 13
  • Saturday, May 18, 13
  • Real World Exampleshttp://www.phpied.com/the-performance-business-pitch/Saturday, May 18, 13
  • Real World Examples• Firefox: -2.2 seconds = 15.4% more downloadshttp://www.phpied.com/the-performance-business-pitch/Saturday, May 18, 13
  • Real World Examples• Firefox: -2.2 seconds = 15.4% more downloads• Shopzilla: -5 seconds = 7-12% increase inrevenuehttp://www.phpied.com/the-performance-business-pitch/Saturday, May 18, 13
  • Real World Examples• Firefox: -2.2 seconds = 15.4% more downloads• Shopzilla: -5 seconds = 7-12% increase inrevenue• Google: +400ms = 0.76% fewer searcheshttp://www.phpied.com/the-performance-business-pitch/Saturday, May 18, 13
  • Real World Examples• Firefox: -2.2 seconds = 15.4% more downloads• Shopzilla: -5 seconds = 7-12% increase inrevenue• Google: +400ms = 0.76% fewer searches• Amazon: +100ms = -1% revenuehttp://www.phpied.com/the-performance-business-pitch/Saturday, May 18, 13
  • ~80% of pageload time takesplace on the clientSaturday, May 18, 13
  • ...if your backendis fastSaturday, May 18, 13
  • A fast page load is 2 secondsThis means you have 400ms to get thatHTML off your serverSaturday, May 18, 13
  • But network time could be ~100msThis means you have 400ms 300ms tobuild the pageSaturday, May 18, 13
  • < 100ms feels instant< 1 sec feels like flow< 10 sec to keep user’s attentionhttp://www.nngroup.com/articles/response-times-3-important-limits/Saturday, May 18, 13
  • < 100ms feels instant< 1 sec feels like flow< 10 sec to keep user’s attentionFull Page Load – 2 Secondshttp://www.nngroup.com/articles/response-times-3-important-limits/Saturday, May 18, 13
  • < 100ms feels instant< 1 sec feels like flow< 10 sec to keep user’s attentionFull Page Load – 2 SecondsBase HTML – 400mshttp://www.nngroup.com/articles/response-times-3-important-limits/Saturday, May 18, 13
  • < 100ms feels instant< 1 sec feels like flow< 10 sec to keep user’s attentionFull Page Load – 2 SecondsBase HTML – 400msServer Generation Time – 300mshttp://www.nngroup.com/articles/response-times-3-important-limits/Saturday, May 18, 13
  • Profiling PHPApplicationsSaturday, May 18, 13
  • Monitoring/Tracing• Paid:• Tracelytics (bought by AppNeta)• AppDynamics (building a PHP solution)• dynaTrace (building a PHP solution)• New Relic (has a free option)• Free:• StatsD/Graphite• xhprofSaturday, May 18, 13
  • Monitoring/Tracing• Paid:• Tracelytics (bought by AppNeta)• AppDynamics (building a PHP solution)• dynaTrace (building a PHP solution)• New Relic• Free:• StatsD/Graphite• xhprofSaturday, May 18, 13
  • StatsD (UDP packets)$start = microtime(true);/* script content */$end = microtime(true);StatsD::timing(foo.bar, $end - $start);More Info: http://goo.gl/LbDPESaturday, May 18, 13
  • Graphite• Written by Orbitz• Real-time graphing engine for StatsD data(among other things)• http://graphite.wikidot.com/• Architecture: http://www.aosabook.org/en/graphite.htmlSaturday, May 18, 13
  • Etsy Conversations PHP TimeExecution CountSaturday, May 18, 13
  • Search Page PHP Time (95th Percentile)Saturday, May 18, 13
  • Search PageExecution CountSaturday, May 18, 13
  • Stacked Search TimersSaturday, May 18, 13
  • xhprof• PHP Extension (need to install)• http://pecl.php.net/package/xhprof• Code level tracing• Significant overhead, use in DEV only!• Add ?xhprof=1 to URL• Results in browserSaturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Lesson:Profile Your CodeSaturday, May 18, 13
  • Code LevelOptimizationsSaturday, May 18, 13
  • Writing Efficient PHPSet max value before loop:$max = count($rows);for ($i = 0; $i < $max; $i++) {echo $i;}require_once() is slowMinimize use of define()Yes, single quotes are slightly faster than double quotes, but...Saturday, May 18, 13
  • Almost Every Micro-Optimization isWorthlessSaturday, May 18, 13
  • http://phpbench.com/Saturday, May 18, 13
  • http://phpbench.com/Saturday, May 18, 13
  • http://phpbench.com/Saturday, May 18, 13
  • Writing Efficient PHPSet max value before loop:$max = count($rows);for ($i = 0; $i < $max; $i++) {echo $i;}Okay, this one is pretty goodSaturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • So Why Even MentionMicro-Optimizations?Saturday, May 18, 13
  • http://code.flickr.net/2009/12/02/flipping-out/Saturday, May 18, 13
  • strtok() to implode()Saturday, May 18, 13
  • Lesson:Focus on the BigWinsSaturday, May 18, 13
  • “Premature optimization is the root of all evil”- Donald KnuthSaturday, May 18, 13
  • Big WinsSaturday, May 18, 13
  • Upgrade PHPSaturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/36484Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/36484Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/364845.4 is ~20-40% faster than 5.3Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/364845.4 is ~20-40% faster than 5.3http://news.php.net/php.internals/57760Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/364845.4 is ~20-40% faster than 5.3http://news.php.net/php.internals/57760Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/364845.4 is ~20-40% faster than 5.3http://news.php.net/php.internals/57760Upgrading 5.2 --> 5.4 gives a 45-70% improvement!Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/364845.4 is ~20-40% faster than 5.3http://news.php.net/php.internals/57760Upgrading 5.2 --> 5.4 gives a 45-70% improvement!http://php.net/migration53Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/364845.4 is ~20-40% faster than 5.3http://news.php.net/php.internals/57760Upgrading 5.2 --> 5.4 gives a 45-70% improvement!http://php.net/migration53http://php.net/migration54Saturday, May 18, 13
  • Upgrade PHP5.3 is ~20% faster than 5.2http://news.php.net/php.internals/364845.4 is ~20-40% faster than 5.3http://news.php.net/php.internals/57760Upgrading 5.2 --> 5.4 gives a 45-70% improvement!http://php.net/migration53http://php.net/migration54Saturday, May 18, 13
  • PHP 5.4 is 5 Times Faster than PHP 4http://static.zend.com/topics/White-paper-PHP4-PHP5.pdfSaturday, May 18, 13
  • Etsy’s Upgrade to PHP 5.4Saturday, May 18, 13
  • Use an OpcodeCache (APC)Saturday, May 18, 13
  • Standard Page ExecutionSaturday, May 18, 13
  • With An Opcode CacheSaturday, May 18, 13
  • Opcode CacheVanilla settings: 30-40% improvementTurn off APC Stat: additional ~2ximprovement-- Understand what is happening herehttp://www.slideshare.net/vortexau/improving-php-application-performance-with-apc-presentationSaturday, May 18, 13
  • Cache Data in aKey-Value StoreSaturday, May 18, 13
  • APC User Cache<?php$foo = "Hello, World!";apc_store(some_key, $foo);?><?phpvar_dump(apc_fetch(some_key));?>-------- Output --------string(12) "Hello World!"Saturday, May 18, 13
  • APC User CacheSaturday, May 18, 13
  • APC User Cache• Avoid fragmentation - keep utilization under 10%Saturday, May 18, 13
  • APC User Cache• Avoid fragmentation - keep utilization under 10%• Assign 1GB, only fill 100MBSaturday, May 18, 13
  • APC User Cache• Avoid fragmentation - keep utilization under 10%• Assign 1GB, only fill 100MB• Compress objects that are > 10KB before storingSaturday, May 18, 13
  • APC User Cache• Avoid fragmentation - keep utilization under 10%• Assign 1GB, only fill 100MB• Compress objects that are > 10KB before storing• Reduce garbage collection in the source ofapc_store()Saturday, May 18, 13
  • APC User Cache• Avoid fragmentation - keep utilization under 10%• Assign 1GB, only fill 100MB• Compress objects that are > 10KB before storing• Reduce garbage collection in the source ofapc_store()• Consider CDBSaturday, May 18, 13
  • APC User Cache• Avoid fragmentation - keep utilization under 10%• Assign 1GB, only fill 100MB• Compress objects that are > 10KB before storing• Reduce garbage collection in the source ofapc_store()• Consider CDB• http://engineering.wayfair.com/moving-constants-out-of-apc-and-into-cdb/Saturday, May 18, 13
  • Memcached• Usually a separate server• In-memory key-value store• Extremely simple and fast• http://memcached.org/Saturday, May 18, 13
  • APC vs. MemcachedAPC User Cache MemcachedLocal to the Server Shared Network ResourceGood for small objects Large or small objectsGood for mostly readworkloadsCan read and write quicklyOnly one instance Can be clusteredSaturday, May 18, 13
  • Fix All Errors• PHP 5.3: E_ALL | E_STRICT• PHP 5.4: E_ALL• Can also do error_reporting(-1);Saturday, May 18, 13
  • Child Processes4-6 processes per CPU core.Beyond that just add servers.(Test your app)Saturday, May 18, 13
  • HipHop for PHP• Developed/Open Sourced by Facebook• Now a VM + JIT compilation• 5x improvement in throughput over PHP 5.2• http://developers.facebook.com/blog/post/2010/02/02/hiphop-for-php--move-fast/• https://www.facebook.com/notes/facebook-engineering/speeding-up-php-based-development-with-hiphop-vm/10151170460698920• https://github.com/facebook/hiphop-phpSaturday, May 18, 13
  • UnderstandFrameworkOverheadSaturday, May 18, 13
  • http://systemsarchitect.net/performance-benchmark-of-popular-php-frameworks/Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Symfony is 20xslower than rawPHPSaturday, May 18, 13
  • Load TestingSaturday, May 18, 13
  • JMeter• Open Source• Generate load via a GUI or commandline• Can watch req/s degrade with moreusers• Easy to useSaturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Saturday, May 18, 13
  • Be CarefulSaturday, May 18, 13
  • Be Careful• JMeter looks a lot like a DOS attackSaturday, May 18, 13
  • Be Careful• JMeter looks a lot like a DOS attack• Make sure you know what is failingSaturday, May 18, 13
  • Be Careful• JMeter looks a lot like a DOS attack• Make sure you know what is failing• Look at monitoring while test is runningSaturday, May 18, 13
  • Be Careful• JMeter looks a lot like a DOS attack• Make sure you know what is failing• Look at monitoring while test is running• Run in ProductionSaturday, May 18, 13
  • Be Careful• JMeter looks a lot like a DOS attack• Make sure you know what is failing• Look at monitoring while test is running• Run in Production• Run a test, make a change, run it againSaturday, May 18, 13
  • TakeawaysSaturday, May 18, 13
  • “How Fast IsYour Site?”Saturday, May 18, 13
  • This is a terrible quesitonSaturday, May 18, 13
  • Why is it terrible?Saturday, May 18, 13
  • Why is it terrible?• Lack of contextSaturday, May 18, 13
  • Why is it terrible?• Lack of context• Are we talking about average or a percentile?Saturday, May 18, 13
  • Why is it terrible?• Lack of context• Are we talking about average or a percentile?• Server side time or client?Saturday, May 18, 13
  • Why is it terrible?• Lack of context• Are we talking about average or a percentile?• Server side time or client?• Who is measuring it?Saturday, May 18, 13
  • Why is it terrible?• Lack of context• Are we talking about average or a percentile?• Server side time or client?• Who is measuring it?• When is it being measured?Saturday, May 18, 13
  • Why is it terrible?• Lack of context• Are we talking about average or a percentile?• Server side time or client?• Who is measuring it?• When is it being measured?• Real users or synthetic?Saturday, May 18, 13
  • We still have to answer itSaturday, May 18, 13
  • Pick Tight SLAs“The homepage of our site will load in<300ms at the 80th percentile, measuredby sampling 10% of our real users over a24 hour period every day at 8AM.”Saturday, May 18, 13
  • Pick Tight SLAs“The homepage of our site will load in<300ms at the 80th percentile, measuredby sampling 10% of our real users over a24 hour period every day at 8AM.”Saturday, May 18, 13
  • Things to RememberSaturday, May 18, 13
  • Things to Remember• Measure and monitor your applicationSaturday, May 18, 13
  • Things to Remember• Measure and monitor your application• Focus on big winsSaturday, May 18, 13
  • Things to Remember• Measure and monitor your application• Focus on big wins• Run the latest (stable) version of PHPSaturday, May 18, 13
  • Things to Remember• Measure and monitor your application• Focus on big wins• Run the latest (stable) version of PHP• Make sure you are using APC correctlySaturday, May 18, 13
  • Things to Remember• Measure and monitor your application• Focus on big wins• Run the latest (stable) version of PHP• Make sure you are using APC correctly• It’s always the database (stay in this room)Saturday, May 18, 13
  • Things to Remember• Measure and monitor your application• Focus on big wins• Run the latest (stable) version of PHP• Make sure you are using APC correctly• It’s always the database (stay in this room)• Caching is your friendSaturday, May 18, 13
  • Things to Remember• Measure and monitor your application• Focus on big wins• Run the latest (stable) version of PHP• Make sure you are using APC correctly• It’s always the database (stay in this room)• Caching is your friend• Know what system resources you depend onSaturday, May 18, 13
  • There is a lot more to talk aboutSaturday, May 18, 13
  • Get in Touchhttp://web-performance.meetup.com/www.etsy.com/careersjonathan@etsy.com@jonathankleinSaturday, May 18, 13