SlideShare una empresa de Scribd logo
1 de 65
August 11th, 2012

High Performance PHP
               Northeast PHP 2012
                      Jonathan Klein
        jonathan.n.klein@gmail.com
                     @jonathanklein
Agenda
  Who am I?
  Why Performance Matters
  Profiling PHP Applications
  Code Level Optimizations
  Big Wins
  Load Testing
  Takeaways
Introduction

• Web Performance Platform Lead at Wayfair

• Boston Web Performance Meetup Group Organizer

• Led a team that converted most of Wayfair’s storefront
  codebase from Classic ASP to PHP.
   1. Rewrote ~100,000 lines of code


• Wayfair Stats:
  1. 450 reqs/sec for dynamic content (PHP pages)

   2. 1600 reqs/sec for static content (including CDN)

   3. Codebase has > 400,000 lines of PHP (some is 3rd party)



                                                                3
The Value of Performance
Real World Examples

• Firefox: -2.2 seconds = 15.4% more downloads

• Shopzilla: -5 seconds = 7-12% increase in revenue

• Google: +400ms = 0.76% fewer searches

• Amazon: +100ms = -1% revenue



http://www.phpied.com/the-performance-business-pitch/



                                                        6
80/20 Rule




  80% of page load time takes place on the
                  client




                                             7
We’re going to talk about the other 20%
A fast page load is 2 seconds



This means you have 400ms to get that HTML off
                 your server
But network time could be ~100ms



This means you have 400ms 300ms to build the
                   page
The average length of an eye blink
     is 100-400 milliseconds




         Full Page Load – 2 Seconds




      Base HTML – 400ms

   Server Generation Time – 300ms
Profiling PHP Applications
        Monitoring and Tracing
Monitoring/Tracing Tools

• Paid:
   1. Tracelytics (bought by AppNeta)
   2. AppDynamics (building a PHP solution)
   3. dynaTrace (building a PHP solution
   4. New Relic

• Free:
   1. StatsD/Graphite
   2. Xdebug
   3. Nagios
   4. Ganglia

                                              13
Monitoring/Tracing Tools

• Paid:
   1. Tracelytics (bought by AppNeta)
   2. AppDynamics (building a PHP solution)
   3. dynaTrace (building a PHP solution
   4. New Relic

• Free:
   1. StatsD/Graphite
   2. Xdebug
   3. Nagios
   4. Ganglia

                                              14
StatsD

UDP Packets – extremely low overhead

<?php
$start = microtime(true);

…script content…

$end      = microtime(true);

MyStats::timing('foo.bar', $end - $start);
?>


http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/



                                                                              15
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.html




                                                                   16
Xdebug

• PHP extension (need to install) - http://xdebug.org/

• Code level tracing
   1. Exposes hotspots


• Significant overhead, use in DEV only!

• Add ?XDEBUG_PROFILE=true to a URL

• View results:
   1. kcachegrind on linux
   2. wincachegrind on Windows




                                                         20
Lesson: Profile Your Code
Code Level Optimizations
Writing Efficient PHP

• Set max value before 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




                                                       27
Almost Every Micro-Optimization is
           Worthless
http://phpbench.com/
http://phpbench.com/
http://phpbench.com/
Writing Efficient PHP

• Set the max loop value before the loop:
  $max = count($rows);
  for ($i = 0; $i < $max; $i++) {
     echo $i;
  }




                       Okay, this one is pretty good



                                                       32
So Why Even Mention
Micro-Optimizations?
Lesson: Focus on the Big Wins


“Premature optimization is the root of all evil”
              - Donald Knuth
Big Wins
Upgrade PHP

       5.3 is ~20% faster than 5.2
          http://news.php.net/php.internals/36484


      5.4 is ~20-40% faster than 5.3
          http://news.php.net/php.internals/57760




   Upgrading 5.2  5.4 gives a 45-70%
             improvement!

              http://php.net/migration53
              http://php.net/migration54


                                                    38
PHP 5.4 is 5 Times Faster than PHP4
      http://static.zend.com/topics/White-paper-PHP4-PHP5.pdf
Use APC (Correctly)

           APC – Alternative PHP Cache




                                         40
Opcode Cache Performance

• Vanilla settings  30-40% improvement

• Turn off APC Stat  additional ~2x
  improvement!
      -- Understand what is happening here




http://www.slideshare.net/vortexau/improving-php-application-performance-with-apc-
presentation



                                                                                     41
APC User Cache

<?php
$bar = 'Hello World!';
apc_store('foo', $bar);
?>

<?php
var_dump(apc_fetch('foo'));
?>
-------- Output --------
string(12) "Hello World!"


                              42
APC User Cache Optimizations

• Avoid fragmentation - keep utilization under 10%
   1. Assign 1GB, only fill 100MB


• Compress objects that are > 10KB before storing

• Reduce garbage collection in the source of
  apc_store()

• Consider CDB
   1. http://engineering.wayfair.com/moving-constants-out-of-apc-and-into-cdb/




                                                                                 43
Caching

• Avoid hitting the database

• Cache in APC/Memcached

• 1:00 tomorrow: “Caching With Memcached”




                                            44
Fix All Errors

• PHP 5.3: E_ALL | E_STRICT

• PHP 5.4: E_ALL

• Can also do error_reporting(-1);




                                     45
Child Processes

• 4-6 processes per CPU core.

• Beyond that just add servers.

                 (Test your app)




                                   46
HipHop for PHP

• Developed/Open Sourced by Facebook

• Transforms PHP source code into highly optimized C++

• Reduces CPU for Facebook’s servers by 50%




http://developers.facebook.com/blog/post/2010/02/02/hiphop-for-php--move-fast/
https://github.com/facebook/hiphop-php




                                                                                 47
Load Testing
JMeter

• Open Source

• Generate load via a GUI or command line

• Can watch req/s peak out

• Easy to use (just make sure you set the
  correct path to Java on your computer).



                                            49
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 again



                                             55
Takeaways
“How Fast Is Your Site?”
This is a terrible question
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?




                                                  59
We still have to answer it
Pick Tight SLAs



“The homepage of our site will load in
<300ms at the 80th percentile, measured
by sampling 10% of our real users over a
24 hour period every day at 8AM.”




                                           61
Pick Tight SLAs



“The homepage of our site will load in
<300ms at the 80th percentile, measured
by sampling 10% of our real users over a
24 hour period every day at 8AM.”




                                           62
Things to Remember

1. Measure and monitor your application
2. Focus on big wins
3. Run the latest (stable) version of PHP
4. Make sure you are using APC correctly
5. It’s always the database: go to “The Proper Care
   and Feeding of a MySQL Database” talk
6. Caching is your friend: go to the “Caching With
   Memcached” talk
7. Know what system resources you depend on




                                                      63
There is a lot more
Get In Touch

http://www.meetup.com/Web-Performance-Boston/


               wayfair.com/careers

            jonathan.n.klein@gmail.com

                 @jonathanklein




                                                65

Más contenido relacionado

La actualidad más candente

How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applicationsEnrico Zimuel
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Wim Godden
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Wim Godden
 
Developing cacheable PHP applications - Confoo 2018
Developing cacheable PHP applications - Confoo 2018Developing cacheable PHP applications - Confoo 2018
Developing cacheable PHP applications - Confoo 2018Thijs Feryn
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourWim Godden
 
Single page apps with drupal 7
Single page apps with drupal 7Single page apps with drupal 7
Single page apps with drupal 7Chris Tankersley
 
Going crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyGoing crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyDavid de Boer
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Thijs Feryn
 
eZ Publish Caching Mechanisms
eZ Publish Caching MechanismseZ Publish Caching Mechanisms
eZ Publish Caching MechanismsKaliop-slide
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webWallace Reis
 
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018Thijs Feryn
 
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018Codemotion
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architectureElizabeth Smith
 
PHP7 - The New Engine for old good train
PHP7 - The New Engine for old good trainPHP7 - The New Engine for old good train
PHP7 - The New Engine for old good trainXinchen Hui
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server Masahiro Nagano
 
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014Barel Barelon
 
SydPHP March 2012 Meetup
SydPHP March 2012 MeetupSydPHP March 2012 Meetup
SydPHP March 2012 MeetupGraham Weldon
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sitesYann Malet
 

La actualidad más candente (20)

How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
Developing cacheable PHP applications - Confoo 2018
Developing cacheable PHP applications - Confoo 2018Developing cacheable PHP applications - Confoo 2018
Developing cacheable PHP applications - Confoo 2018
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTour
 
Single page apps with drupal 7
Single page apps with drupal 7Single page apps with drupal 7
Single page apps with drupal 7
 
Going crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyGoing crazy with Varnish and Symfony
Going crazy with Varnish and Symfony
 
Running php on nginx
Running php on nginxRunning php on nginx
Running php on nginx
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018
 
eZ Publish Caching Mechanisms
eZ Publish Caching MechanismseZ Publish Caching Mechanisms
eZ Publish Caching Mechanisms
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
 
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
PHP7 - The New Engine for old good train
PHP7 - The New Engine for old good trainPHP7 - The New Engine for old good train
PHP7 - The New Engine for old good train
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
 
SydPHP March 2012 Meetup
SydPHP March 2012 MeetupSydPHP March 2012 Meetup
SydPHP March 2012 Meetup
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
 

Destacado

PHP High Availability High Performance
PHP High Availability High PerformancePHP High Availability High Performance
PHP High Availability High PerformanceAmazee Labs
 
PHP Optimization
PHP OptimizationPHP Optimization
PHP Optimizationdjesch
 
Scaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHPScaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHP120bi
 
Architechture of a social network for 30M users
Architechture of a social network for 30M usersArchitechture of a social network for 30M users
Architechture of a social network for 30M usersFotostrana
 
EscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend OptimizationEscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend OptimizationJonathan Klein
 
UXFest - RUM Distillation 101
UXFest - RUM Distillation 101UXFest - RUM Distillation 101
UXFest - RUM Distillation 101Jonathan Klein
 
Riding rails for 10 years
Riding rails for 10 yearsRiding rails for 10 years
Riding rails for 10 yearsjduff
 
Edge Conf Rendering Performance Panel
Edge Conf Rendering Performance PanelEdge Conf Rendering Performance Panel
Edge Conf Rendering Performance PanelJonathan Klein
 
JSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web DesignJSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web DesignJonathan Klein
 
DIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicDIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicJonathan Klein
 
High Performance Php My Sql Scaling Techniques
High Performance Php My Sql Scaling TechniquesHigh Performance Php My Sql Scaling Techniques
High Performance Php My Sql Scaling TechniquesZendCon
 
BTV PHP - Building Fast Websites
BTV PHP - Building Fast WebsitesBTV PHP - Building Fast Websites
BTV PHP - Building Fast WebsitesJonathan Klein
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
PHP UK 2017 - Don't Lose Sleep - Secure Your RESTPHP UK 2017 - Don't Lose Sleep - Secure Your REST
PHP UK 2017 - Don't Lose Sleep - Secure Your RESTAdam Englander
 
How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)
How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)
How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)Tammy Everts
 
How Shopify Scales Rails
How Shopify Scales RailsHow Shopify Scales Rails
How Shopify Scales Railsjduff
 

Destacado (17)

PHP High Availability High Performance
PHP High Availability High PerformancePHP High Availability High Performance
PHP High Availability High Performance
 
PHP Optimization
PHP OptimizationPHP Optimization
PHP Optimization
 
Scaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHPScaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHP
 
Architechture of a social network for 30M users
Architechture of a social network for 30M usersArchitechture of a social network for 30M users
Architechture of a social network for 30M users
 
EscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend OptimizationEscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend Optimization
 
UXFest - RUM Distillation 101
UXFest - RUM Distillation 101UXFest - RUM Distillation 101
UXFest - RUM Distillation 101
 
Riding rails for 10 years
Riding rails for 10 yearsRiding rails for 10 years
Riding rails for 10 years
 
Edge Conf Rendering Performance Panel
Edge Conf Rendering Performance PanelEdge Conf Rendering Performance Panel
Edge Conf Rendering Performance Panel
 
JSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web DesignJSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web Design
 
DIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicDIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest Magic
 
PHP On Steroids
PHP On SteroidsPHP On Steroids
PHP On Steroids
 
High Performance Php My Sql Scaling Techniques
High Performance Php My Sql Scaling TechniquesHigh Performance Php My Sql Scaling Techniques
High Performance Php My Sql Scaling Techniques
 
BTV PHP - Building Fast Websites
BTV PHP - Building Fast WebsitesBTV PHP - Building Fast Websites
BTV PHP - Building Fast Websites
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
PHP UK 2017 - Don't Lose Sleep - Secure Your RESTPHP UK 2017 - Don't Lose Sleep - Secure Your REST
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
 
How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)
How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)
How Slow Load Times Hurt Your Bottom Line (And 17 Things You Can Do to Fix It)
 
How Shopify Scales Rails
How Shopify Scales RailsHow Shopify Scales Rails
How Shopify Scales Rails
 

Similar a Northeast PHP - High Performance PHP

2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida realPHP Conference Argentina
 
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)Nexcess.net LLC
 
Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10Combell NV
 
Dutch php conference_2010_opm
Dutch php conference_2010_opmDutch php conference_2010_opm
Dutch php conference_2010_opmisnull
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Combell NV
 
Improve WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of codeImprove WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of codeDanilo Ercoli
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confooCombell NV
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UKRicard Clau
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Fwdays
 
Php through the eyes of a hoster
Php through the eyes of a hosterPhp through the eyes of a hoster
Php through the eyes of a hosterCombell NV
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...Otto Kekäläinen
 
What is Nginx and Why You Should to Use it with Wordpress Hosting
What is Nginx and Why You Should to Use it with Wordpress HostingWhat is Nginx and Why You Should to Use it with Wordpress Hosting
What is Nginx and Why You Should to Use it with Wordpress HostingWPSFO Meetup Group
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on SteroidsSiteGround.com
 
Performance and scalability with drupal
Performance and scalability with drupalPerformance and scalability with drupal
Performance and scalability with drupalRonan Berder
 

Similar a Northeast PHP - High Performance PHP (20)

2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
 
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
ExpressionEngine - Simple Steps to Performance and Security (EECI 2014)
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10
 
Dutch php conference_2010_opm
Dutch php conference_2010_opmDutch php conference_2010_opm
Dutch php conference_2010_opm
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
 
Ipc mysql php
Ipc mysql php Ipc mysql php
Ipc mysql php
 
Improve WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of codeImprove WordPress performance with caching and deferred execution of code
Improve WordPress performance with caching and deferred execution of code
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confoo
 
php & performance
 php & performance php & performance
php & performance
 
Intro to CakePHP
Intro to CakePHPIntro to CakePHP
Intro to CakePHP
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
 
Php through the eyes of a hoster
Php through the eyes of a hosterPhp through the eyes of a hoster
Php through the eyes of a hoster
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
 
What is Nginx and Why You Should to Use it with Wordpress Hosting
What is Nginx and Why You Should to Use it with Wordpress HostingWhat is Nginx and Why You Should to Use it with Wordpress Hosting
What is Nginx and Why You Should to Use it with Wordpress Hosting
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
 
Performance and scalability with drupal
Performance and scalability with drupalPerformance and scalability with drupal
Performance and scalability with drupal
 

Último

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Último (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

Northeast PHP - High Performance PHP

  • 1. August 11th, 2012 High Performance PHP Northeast PHP 2012 Jonathan Klein jonathan.n.klein@gmail.com @jonathanklein
  • 2. Agenda Who am I? Why Performance Matters Profiling PHP Applications Code Level Optimizations Big Wins Load Testing Takeaways
  • 3. Introduction • Web Performance Platform Lead at Wayfair • Boston Web Performance Meetup Group Organizer • Led a team that converted most of Wayfair’s storefront codebase from Classic ASP to PHP. 1. Rewrote ~100,000 lines of code • Wayfair Stats: 1. 450 reqs/sec for dynamic content (PHP pages) 2. 1600 reqs/sec for static content (including CDN) 3. Codebase has > 400,000 lines of PHP (some is 3rd party) 3
  • 4. The Value of Performance
  • 5.
  • 6. Real World Examples • Firefox: -2.2 seconds = 15.4% more downloads • Shopzilla: -5 seconds = 7-12% increase in revenue • Google: +400ms = 0.76% fewer searches • Amazon: +100ms = -1% revenue http://www.phpied.com/the-performance-business-pitch/ 6
  • 7. 80/20 Rule 80% of page load time takes place on the client 7
  • 8. We’re going to talk about the other 20%
  • 9. A fast page load is 2 seconds This means you have 400ms to get that HTML off your server
  • 10. But network time could be ~100ms This means you have 400ms 300ms to build the page
  • 11. The average length of an eye blink is 100-400 milliseconds Full Page Load – 2 Seconds Base HTML – 400ms Server Generation Time – 300ms
  • 12. Profiling PHP Applications Monitoring and Tracing
  • 13. Monitoring/Tracing Tools • Paid: 1. Tracelytics (bought by AppNeta) 2. AppDynamics (building a PHP solution) 3. dynaTrace (building a PHP solution 4. New Relic • Free: 1. StatsD/Graphite 2. Xdebug 3. Nagios 4. Ganglia 13
  • 14. Monitoring/Tracing Tools • Paid: 1. Tracelytics (bought by AppNeta) 2. AppDynamics (building a PHP solution) 3. dynaTrace (building a PHP solution 4. New Relic • Free: 1. StatsD/Graphite 2. Xdebug 3. Nagios 4. Ganglia 14
  • 15. StatsD UDP Packets – extremely low overhead <?php $start = microtime(true); …script content… $end = microtime(true); MyStats::timing('foo.bar', $end - $start); ?> http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/ 15
  • 16. 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.html 16
  • 17.
  • 18.
  • 19.
  • 20. Xdebug • PHP extension (need to install) - http://xdebug.org/ • Code level tracing 1. Exposes hotspots • Significant overhead, use in DEV only! • Add ?XDEBUG_PROFILE=true to a URL • View results: 1. kcachegrind on linux 2. wincachegrind on Windows 20
  • 21.
  • 22.
  • 23.
  • 24.
  • 27. Writing Efficient PHP • Set max value before 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 27
  • 32. Writing Efficient PHP • Set the max loop value before the loop: $max = count($rows); for ($i = 0; $i < $max; $i++) { echo $i; } Okay, this one is pretty good 32
  • 33.
  • 34. So Why Even Mention Micro-Optimizations?
  • 35.
  • 36. Lesson: Focus on the Big Wins “Premature optimization is the root of all evil” - Donald Knuth
  • 38. Upgrade PHP 5.3 is ~20% faster than 5.2 http://news.php.net/php.internals/36484 5.4 is ~20-40% faster than 5.3 http://news.php.net/php.internals/57760 Upgrading 5.2  5.4 gives a 45-70% improvement! http://php.net/migration53 http://php.net/migration54 38
  • 39. PHP 5.4 is 5 Times Faster than PHP4 http://static.zend.com/topics/White-paper-PHP4-PHP5.pdf
  • 40. Use APC (Correctly) APC – Alternative PHP Cache 40
  • 41. Opcode Cache Performance • Vanilla settings  30-40% improvement • Turn off APC Stat  additional ~2x improvement! -- Understand what is happening here http://www.slideshare.net/vortexau/improving-php-application-performance-with-apc- presentation 41
  • 42. APC User Cache <?php $bar = 'Hello World!'; apc_store('foo', $bar); ?> <?php var_dump(apc_fetch('foo')); ?> -------- Output -------- string(12) "Hello World!" 42
  • 43. APC User Cache Optimizations • Avoid fragmentation - keep utilization under 10% 1. Assign 1GB, only fill 100MB • Compress objects that are > 10KB before storing • Reduce garbage collection in the source of apc_store() • Consider CDB 1. http://engineering.wayfair.com/moving-constants-out-of-apc-and-into-cdb/ 43
  • 44. Caching • Avoid hitting the database • Cache in APC/Memcached • 1:00 tomorrow: “Caching With Memcached” 44
  • 45. Fix All Errors • PHP 5.3: E_ALL | E_STRICT • PHP 5.4: E_ALL • Can also do error_reporting(-1); 45
  • 46. Child Processes • 4-6 processes per CPU core. • Beyond that just add servers. (Test your app) 46
  • 47. HipHop for PHP • Developed/Open Sourced by Facebook • Transforms PHP source code into highly optimized C++ • Reduces CPU for Facebook’s servers by 50% http://developers.facebook.com/blog/post/2010/02/02/hiphop-for-php--move-fast/ https://github.com/facebook/hiphop-php 47
  • 49. JMeter • Open Source • Generate load via a GUI or command line • Can watch req/s peak out • Easy to use (just make sure you set the correct path to Java on your computer). 49
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55. 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 again 55
  • 57. “How Fast Is Your Site?”
  • 58. This is a terrible question
  • 59. 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? 59
  • 60. We still have to answer it
  • 61. Pick Tight SLAs “The homepage of our site will load in <300ms at the 80th percentile, measured by sampling 10% of our real users over a 24 hour period every day at 8AM.” 61
  • 62. Pick Tight SLAs “The homepage of our site will load in <300ms at the 80th percentile, measured by sampling 10% of our real users over a 24 hour period every day at 8AM.” 62
  • 63. Things to Remember 1. Measure and monitor your application 2. Focus on big wins 3. Run the latest (stable) version of PHP 4. Make sure you are using APC correctly 5. It’s always the database: go to “The Proper Care and Feeding of a MySQL Database” talk 6. Caching is your friend: go to the “Caching With Memcached” talk 7. Know what system resources you depend on 63
  • 64. There is a lot more
  • 65. Get In Touch http://www.meetup.com/Web-Performance-Boston/ wayfair.com/careers jonathan.n.klein@gmail.com @jonathanklein 65

Notas del editor

  1. StatsD Aggregates things by 5 second intervals by default