SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 

Kürzlich hochgeladen (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 

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

Hinweis der Redaktion

  1. StatsD Aggregates things by 5 second intervals by default