SlideShare a Scribd company logo
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

More Related Content

What's hot

How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
Enrico 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 2012
Wim 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 2011
Wim Godden
 
Developing cacheable PHP applications - Confoo 2018
Developing cacheable PHP applications - Confoo 2018Developing cacheable PHP applications - Confoo 2018
Developing cacheable PHP applications - Confoo 2018
Thijs 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 @ PHPTour
Wim Godden
 
Single page apps with drupal 7
Single page apps with drupal 7Single page apps with drupal 7
Single page apps with drupal 7
Chris Tankersley
 
Going crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyGoing crazy with Varnish and Symfony
Going crazy with Varnish and Symfony
David de Boer
 
Running php on nginx
Running php on nginxRunning php on nginx
Running php on nginx
Harald Zeitlhofer
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018
Thijs Feryn
 
eZ Publish Caching Mechanisms
eZ Publish Caching MechanismseZ Publish Caching Mechanisms
eZ Publish Caching Mechanisms
Kaliop-slide
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
Wallace 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 2018
Thijs 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 2018
Codemotion
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
Elizabeth 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 train
Xinchen 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 2014
Barel Barelon
 
SydPHP March 2012 Meetup
SydPHP March 2012 MeetupSydPHP March 2012 Meetup
SydPHP March 2012 Meetup
Graham 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 sites
Yann Malet
 

What's hot (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
 

Viewers also liked

PHP High Availability High Performance
PHP High Availability High PerformancePHP High Availability High Performance
PHP High Availability High Performance
Amazee Labs
 
PHP Optimization
PHP OptimizationPHP Optimization
PHP Optimization
djesch
 
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
120bi
 
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
Fotostrana
 
EscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend OptimizationEscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend Optimization
Jonathan Klein
 
UXFest - RUM Distillation 101
UXFest - RUM Distillation 101UXFest - RUM Distillation 101
UXFest - RUM Distillation 101
Jonathan 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 Panel
Jonathan Klein
 
JSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web DesignJSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web Design
Jonathan Klein
 
DIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicDIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest Magic
Jonathan Klein
 
PHP On Steroids
PHP On SteroidsPHP On Steroids
PHP On Steroids
Jonathan Oxer
 
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
ZendCon
 
BTV PHP - Building Fast Websites
BTV PHP - Building Fast WebsitesBTV PHP - Building Fast Websites
BTV PHP - Building Fast Websites
Jonathan Klein
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
Ignacio 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 REST
Adam 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
 

Viewers also liked (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 to 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: PHPNW10
Combell NV
 
Dutch php conference_2010_opm
Dutch php conference_2010_opmDutch php conference_2010_opm
Dutch php conference_2010_opmisnull
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
Zend by Rogue Wave Software
 
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 code
Danilo 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 confoo
Combell NV
 
php & performance
 php & performance php & performance
php & performance
simon8410
 
Intro to CakePHP
Intro to CakePHPIntro to CakePHP
Intro to CakePHP
Walther Lalk
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
Ricard 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 hoster
Combell 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 Hosting
WPSFO Meetup Group
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
毅 吕
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
SiteGround.com
 
Performance and scalability with drupal
Performance and scalability with drupalPerformance and scalability with drupal
Performance and scalability with drupalRonan Berder
 

Similar to 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
 

Recently uploaded

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 

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

Editor's Notes

  1. StatsD Aggregates things by 5 second intervals by default