SlideShare una empresa de Scribd logo
1 de 92
Profiling PHP
  Applications
    July 2011 - Justin Carmony


            #uphpu
wifi: C7bluffdale -- c7dcguest
About Me

• CTO of Dating DNA
• CIO of CEVO LLC
• Make Websites & iPhone Apps
• Worked on Websites for Dell, nVidia,
  DirectTV, and other big clients.
Experience

• Lots of work with “Middle-Scale” websites.
• Lucky to Work on Fun Projects
• Lots of Web Service Stuff
• Learned most of this from other really
  smart people.
We’ll Use An Example
    and an awesome one at that...
We Have Similar Jobs
      Awesome, huh?
MythBusters
•   They get a Myth

•   Break it down to its
    different parts

•   They Conduct a Bunch
    of Tests

•   They Draw Conclusions

•   and have a Fun Time
Developers
•   We get Myths
    (Hey, this is slow)

•   We Break it down to
    the different pieces

•   We Conduct a Bunch of
    Tests.

•   We Draw Conclusions
    (and normally make
    changes)

•   and Have a Fun Time...
So Lets Get Started!
   php /lets/get/started.php now
First Off, Some
  PHP Myths
 and there are a lot of them!
Common Performance
  Claims (Myths)
•   echo instead of print()   •   single quotes, not double
                                  quotes
•   echo commas, not
    periods                   •   include instead of
                                  include_once
•   don’t use custom
    functions/classes         •   === faster than ==

•   pass by reference         •   for faster than foreach
    instead of by value
To Quote
Derick Rethans
   Author of Xdebug...
“I can only say one thing about this....

           Complete & Utter

         Bull****”
or in MythBusters Terminology....
I’m Serious, There are a
  LOT of these Myths
These Example Came from Google’s Top 10 results for
              “php performance tips”
These “Performance
Tips” Rarely Make a
     Difference
Thats Like Debating the Windshield Wipers’s
      Effect on this Car’s Performance
Intuition Based
 Optimizations
  i.e. how to not effectively
     improve performance




      Phrase Coined by Dave Smith
   http://thesmithfam.org/blog/2011/02/
Your Intuitions are
    WRONG
      90% of the time
Example:
Fuel Efficiency Myths
MythBusters Tested
• Keeping Your AC Off vs Windows Down
• Idling Better than Stop/Start
• Magical Aerodynamics
• Dirt-Free Filters
• Special Fuel Additives to Slow Burn
 All Busted! They Didn’t Make a Difference,
        Or Worsened Fuel Efficiency
How About
   Driving Angry?




 After Testing, Tory & Grant Used
33% More Fule While Driving Angry
Effective Profiling
   is based on
 Actual Results
There are Two Types
of Profiling “Modes”
Normal Profiling




   Lets Try this Configuration Change
and Measure the Performance Difference
Emergency Profiling




Aaaaaaaaaaaaah the Website is Down!!!!
    Why is it so slow??? Fix it!!!!!!
Same Techniques
      Apply to Both

• Some you’ll want to chose first depending
  on your situation.
• You’ll want to be careful when profiling in
  Production, you can make things worse.
Understanding the
   Full Picture
Browser                        Static Files
                                                       Database and/or
                                                         Data Store


                 Web Server


                                  PHP App


                                                Server OS


Web Services &
 Resources                                                      Hardware
                              Cache
Don’t Panic!
Goal: Find Slow Parts
  aka Bottlenecks
Profiling & Testing
 Different Parts
Tools!
Browser                        Static Files
                                                       Database and/or
                                                         Data Store


                 Web Server


                                  PHP App


                                                Server OS


Web Services &
 Resources                                                      Hardware
                              Cache
FireBug
FireBug
Google Page Speed
Other Tools

• YSlow
  http://developer.yahoo.com/yslow/
• Pingdom Tools
  http://tools.pingdom.com/
• WireShark / Fiddler2
Browser                        Static Files
                                                       Database and/or
                                                         Data Store


                 Web Server


                                  PHP App


                                                Server OS


Web Services &
 Resources                                                      Hardware
                              Cache
apachetop




apachetop -f /var/log/apache/example.com.access.log
Apachetop works
   with nginx
Apache’s mod_status
   <Location /server-status>
   SetHandler server-status

   Order Deny,Allow
   Deny from all
   Allow from 25.131.42.122
   </Location>

   # ExtendedStatus On
Apache’s mod_status
siege
siege

• Command Line Tool
• Run Concurrent HTTP Requests
• Runs on Linux & Mac OS
• Windows Users: Run a VM
• Great Way to Test End Result
siege

• Create txt file with lists of URLs to hit
• Run Command:
  siege -c 10 -r 10 -f urls.txt
• c = concurrent
  r = # of requests
  f = path to URL file
siege
siege
Other Tools
• nginx stub status (similar to mod_status)
  http://wiki.nginx.org/HttpStubStatusModule
• Apache Bench & http_load -- CLI
• JMeter -- Java Desktop App
Browser                        Static Files
                                                       Database and/or
                                                         Data Store


                 Web Server


                                  PHP App


                                                Server OS


Web Services &
 Resources                                                      Hardware
                              Cache
My Favorite New Tools:
  XHProf & XHGui
XHProf

• Developed by Facebook
• Works well for both Development
  & Production* Profiling
• pecl extension
• Decent UI for viewing Results
   * - Use Sampling & Special CPU Flags for Production
    http://mirror.facebook.net/facebook/xhprof/doc.html
XHGui
• Improved GUI
• Easy to Setup
• Built In Sampling
• Advanced Configuration
• MySQL Backend
• I recommend using this!
   https://github.com/preinheimer/xhprof
More Fun to Show
     Demo Time
Xdebug Profiler
• Install Xdebug
• Enable Xdebug Profiling
• Outputs a Cachegrind Log
• Use KCachegrind / WinCachegrind /
  Webgrind to view
• For the Rich, MacCallGrind for $150
Enabling Xdebug
           Profiling
xdebug.profiler_enable=1
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=cachegrind.out.%p


     Xdebug Profiling Not for Production
           (unless you have a 100TB HDD laying around)
Webgrind
Timing Points

• Most Frameworks have Built-In Profiling /
  Timing Points
• Most ORMs have them as well
• You can do them yourself
• A must for Database Queries
Timing Points
$start = microtime(true); // true to get as float

/* Do your Crazy Code, i.e. query */

$end = microtime(true);

$time = round($end - $start, 4);
Other Tools

• Inclued
  http://php.net/manual/en/book.inclued.php
• Memtrack
  http://php.net/manual/en/
  book.memtrack.php
Browser                        Static Files
                                                       Database and/or
                                                         Data Store


                 Web Server


                                  PHP App


                                                Server OS


Web Services &
 Resources                                                      Hardware
                              Cache
Databases
• Typically, First Thing to Slow Down
• Things to that will Kill the DB:
   • Missing Indexes
   • Nested Queries
   • Large Joins
   • Locked Queries
Jet Profiler

• MySQL Profiler
• Free Version (Okay) & Paid (Awesome)
• Not Cheap ($399)
 • But Worth It
• Analytics Over Time
Jet Profiler
MySQL Commands

• explain <query>
• show processlist
• show variables
• show status
mtop
Browser                        Static Files
                                                       Database and/or
                                                         Data Store


                 Web Server


                                  PHP App


                                                Server OS


Web Services &
 Resources                                                      Hardware
                              Cache
vmstat
command: vmstat 1
vmstat

• swap > 0 means swapping
  Memory Issue
• cpu sys + us really high
  CPU / Code / PHP Problem
• cpu wa > 10
  Disk IO Problem*
      * - Technically could be Network IO as well, but typically
           one of the last and more rare bottlenecks to hit
vnstat
command: vnstat -l -i eth0
top
htop
strace
iotop
Other Tools

• netstat
• iostat
• mpstat
• pidstat
• (on ubuntu, install via sysstat package)
Other Tools

• grep, awk, sed
• IPs Connected:
  netstat -plan | grep :80 | awk '{print $5}' |
  sed 's/::ffff://g' | awk -F: '{print $1}' | sort |
  uniq -c | sort -n
Monitoring
           Munin




http://munin-monitoring.org/
Monitoring
     Wormly




http://wormly.com/
Whew, Lots of Tools
 and a lot more out there not in this talk
    Find any cool ones, let me know!
Normal Profiling

• Start with XHProf/XHGui and FireBug
• Avoid Premature Optimization
   • Complicated Change
   • Little Reward
• Use siege, or alternative, to simulate load.
Emergency Profiling

• Start with OS Level Testing Tools (htop,
  vmstat, vnstat) to check Server
  Performance
• Determine which Resource(s) are being
  over utilized
• Finding the bottleneck is key
Emergency Profiling

• What Changed?
   • Increased Traffic?
   • New Feature?
   • Something Failed/Down?
• Don’t Panic & Start Wildly Guessing
Few Final Thoughts
The Better You
 Understand
   The Problem
The Better You Can
     Fix It
Don’t
Put Off Profiling
Until there is an
Emergency
You Can Throw
  Hardward at the
Problem, but Avoid IT
Ask Others for Ideas
        aka

Brainstorming
Good Luck!
Questions?
Thanks!
     Twitter: JustinCarmony

         IRC: carmony
     #uphpu #phpc #joind.in

             Website:
http://www.justincarmony.com/blog

              Email:
    justin@justincarmony.com

Más contenido relacionado

La actualidad más candente

When Devs Do Ops
When Devs Do OpsWhen Devs Do Ops
When Devs Do OpsWooga
 
Scaling Rails with Memcached
Scaling Rails with MemcachedScaling Rails with Memcached
Scaling Rails with Memcachedguest2259ea
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Mongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case StudyMongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case StudyMitch Pirtle
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No CashYorick Phoenix
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009Jason Davies
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisRicard Clau
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure ClojureDane Schneider
 
Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Taylor Lovett
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Thijs Feryn
 
Page Performance
Page PerformancePage Performance
Page Performanceatorreno
 
Real-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopReal-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopRogue Wave Software
 
Gofer 200707
Gofer 200707Gofer 200707
Gofer 200707oscon2007
 
Top 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudTop 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudRogue Wave Software
 
CSS and image optimization
CSS and image optimizationCSS and image optimization
CSS and image optimizationStoyan Stefanov
 
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Marcel Chastain
 
NotaCon 2011 - Networking for Pentesters
NotaCon 2011 - Networking for PentestersNotaCon 2011 - Networking for Pentesters
NotaCon 2011 - Networking for PentestersRob Fuller
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8rajkumar2011
 
Resource registries plone conf 2014
Resource registries plone conf 2014Resource registries plone conf 2014
Resource registries plone conf 2014Ramon Navarro
 

La actualidad más candente (20)

When Devs Do Ops
When Devs Do OpsWhen Devs Do Ops
When Devs Do Ops
 
Scaling Rails with Memcached
Scaling Rails with MemcachedScaling Rails with Memcached
Scaling Rails with Memcached
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Mongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case StudyMongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case Study
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No Cash
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure Clojure
 
Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3
 
Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018
 
Page Performance
Page PerformancePage Performance
Page Performance
 
Real-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopReal-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and Hadoop
 
Gofer 200707
Gofer 200707Gofer 200707
Gofer 200707
 
Top 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudTop 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloud
 
CSS and image optimization
CSS and image optimizationCSS and image optimization
CSS and image optimization
 
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
 
NotaCon 2011 - Networking for Pentesters
NotaCon 2011 - Networking for PentestersNotaCon 2011 - Networking for Pentesters
NotaCon 2011 - Networking for Pentesters
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8
 
Resource registries plone conf 2014
Resource registries plone conf 2014Resource registries plone conf 2014
Resource registries plone conf 2014
 

Similar a Profiling PHP Applications

Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
PHP Performance: Principles and tools
PHP Performance: Principles and toolsPHP Performance: Principles and tools
PHP Performance: Principles and tools10n Software, LLC
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.pptwebhostingguy
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIvo Jansch
 
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
 
SAP & Open Souce - Give & Take
SAP & Open Souce - Give & TakeSAP & Open Souce - Give & Take
SAP & Open Souce - Give & TakeJan Penninkhof
 
SPSNYC SharePoint Worst Practices
SPSNYC SharePoint Worst PracticesSPSNYC SharePoint Worst Practices
SPSNYC SharePoint Worst PracticesScott Hoag
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHPJonathan Klein
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowMatt Ray
 
Trend Micro Big Data Platform and Apache Bigtop
Trend Micro Big Data Platform and Apache BigtopTrend Micro Big Data Platform and Apache Bigtop
Trend Micro Big Data Platform and Apache BigtopEvans Ye
 
WordPress Speed & Performance from Pagely's CTO
WordPress Speed & Performance from Pagely's CTOWordPress Speed & Performance from Pagely's CTO
WordPress Speed & Performance from Pagely's CTOLizzie Kardon
 
Server Monitoring (Scaling while bootstrapped)
Server Monitoring  (Scaling while bootstrapped)Server Monitoring  (Scaling while bootstrapped)
Server Monitoring (Scaling while bootstrapped)Ajibola Aiyedogbon
 
Optimizing the performance of WordPress
Optimizing the performance of WordPressOptimizing the performance of WordPress
Optimizing the performance of WordPressJosh Highland Giese
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1nhepner
 
HAProxy tech talk
HAProxy tech talkHAProxy tech talk
HAProxy tech talkicebourg
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practiceswebuploader
 
Evolving Archetecture
Evolving ArchetectureEvolving Archetecture
Evolving Archetectureleo lapworth
 
hbaseconasia2017: Building online HBase cluster of Zhihu based on Kubernetes
hbaseconasia2017: Building online HBase cluster of Zhihu based on Kuberneteshbaseconasia2017: Building online HBase cluster of Zhihu based on Kubernetes
hbaseconasia2017: Building online HBase cluster of Zhihu based on KubernetesHBaseCon
 

Similar a Profiling PHP Applications (20)

Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
PHP Performance: Principles and tools
PHP Performance: Principles and toolsPHP Performance: Principles and tools
PHP Performance: Principles and tools
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web Services
 
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)
 
Webtechnologies
Webtechnologies Webtechnologies
Webtechnologies
 
SAP & Open Souce - Give & Take
SAP & Open Souce - Give & TakeSAP & Open Souce - Give & Take
SAP & Open Souce - Give & Take
 
SPSNYC SharePoint Worst Practices
SPSNYC SharePoint Worst PracticesSPSNYC SharePoint Worst Practices
SPSNYC SharePoint Worst Practices
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & TomorrowTXLF: Chef- Software Defined Infrastructure Today & Tomorrow
TXLF: Chef- Software Defined Infrastructure Today & Tomorrow
 
Trend Micro Big Data Platform and Apache Bigtop
Trend Micro Big Data Platform and Apache BigtopTrend Micro Big Data Platform and Apache Bigtop
Trend Micro Big Data Platform and Apache Bigtop
 
WordPress Speed & Performance from Pagely's CTO
WordPress Speed & Performance from Pagely's CTOWordPress Speed & Performance from Pagely's CTO
WordPress Speed & Performance from Pagely's CTO
 
Server Monitoring (Scaling while bootstrapped)
Server Monitoring  (Scaling while bootstrapped)Server Monitoring  (Scaling while bootstrapped)
Server Monitoring (Scaling while bootstrapped)
 
Optimizing the performance of WordPress
Optimizing the performance of WordPressOptimizing the performance of WordPress
Optimizing the performance of WordPress
 
Web server
Web serverWeb server
Web server
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1
 
HAProxy tech talk
HAProxy tech talkHAProxy tech talk
HAProxy tech talk
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practices
 
Evolving Archetecture
Evolving ArchetectureEvolving Archetecture
Evolving Archetecture
 
hbaseconasia2017: Building online HBase cluster of Zhihu based on Kubernetes
hbaseconasia2017: Building online HBase cluster of Zhihu based on Kuberneteshbaseconasia2017: Building online HBase cluster of Zhihu based on Kubernetes
hbaseconasia2017: Building online HBase cluster of Zhihu based on Kubernetes
 

Último

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
 
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
 
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
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
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
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
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
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
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
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
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
 

Último (20)

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
 
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
 
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
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
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
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
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
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
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
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
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
 

Profiling PHP Applications

  • 1. Profiling PHP Applications July 2011 - Justin Carmony #uphpu wifi: C7bluffdale -- c7dcguest
  • 2. About Me • CTO of Dating DNA • CIO of CEVO LLC • Make Websites & iPhone Apps • Worked on Websites for Dell, nVidia, DirectTV, and other big clients.
  • 3. Experience • Lots of work with “Middle-Scale” websites. • Lucky to Work on Fun Projects • Lots of Web Service Stuff • Learned most of this from other really smart people.
  • 4. We’ll Use An Example and an awesome one at that...
  • 5.
  • 6. We Have Similar Jobs Awesome, huh?
  • 7. MythBusters • They get a Myth • Break it down to its different parts • They Conduct a Bunch of Tests • They Draw Conclusions • and have a Fun Time
  • 8.
  • 9. Developers • We get Myths (Hey, this is slow) • We Break it down to the different pieces • We Conduct a Bunch of Tests. • We Draw Conclusions (and normally make changes) • and Have a Fun Time...
  • 10.
  • 11. So Lets Get Started! php /lets/get/started.php now
  • 12. First Off, Some PHP Myths and there are a lot of them!
  • 13. Common Performance Claims (Myths) • echo instead of print() • single quotes, not double quotes • echo commas, not periods • include instead of include_once • don’t use custom functions/classes • === faster than == • pass by reference • for faster than foreach instead of by value
  • 14. To Quote Derick Rethans Author of Xdebug...
  • 15. “I can only say one thing about this.... Complete & Utter Bull****”
  • 16. or in MythBusters Terminology....
  • 17. I’m Serious, There are a LOT of these Myths These Example Came from Google’s Top 10 results for “php performance tips”
  • 19. Thats Like Debating the Windshield Wipers’s Effect on this Car’s Performance
  • 20. Intuition Based Optimizations i.e. how to not effectively improve performance Phrase Coined by Dave Smith http://thesmithfam.org/blog/2011/02/
  • 21. Your Intuitions are WRONG 90% of the time
  • 23. MythBusters Tested • Keeping Your AC Off vs Windows Down • Idling Better than Stop/Start • Magical Aerodynamics • Dirt-Free Filters • Special Fuel Additives to Slow Burn All Busted! They Didn’t Make a Difference, Or Worsened Fuel Efficiency
  • 24. How About Driving Angry? After Testing, Tory & Grant Used 33% More Fule While Driving Angry
  • 25. Effective Profiling is based on Actual Results
  • 26. There are Two Types of Profiling “Modes”
  • 27. Normal Profiling Lets Try this Configuration Change and Measure the Performance Difference
  • 28. Emergency Profiling Aaaaaaaaaaaaah the Website is Down!!!! Why is it so slow??? Fix it!!!!!!
  • 29. Same Techniques Apply to Both • Some you’ll want to chose first depending on your situation. • You’ll want to be careful when profiling in Production, you can make things worse.
  • 30. Understanding the Full Picture
  • 31. Browser Static Files Database and/or Data Store Web Server PHP App Server OS Web Services & Resources Hardware Cache
  • 33. Goal: Find Slow Parts aka Bottlenecks
  • 34. Profiling & Testing Different Parts
  • 36. Browser Static Files Database and/or Data Store Web Server PHP App Server OS Web Services & Resources Hardware Cache
  • 40. Other Tools • YSlow http://developer.yahoo.com/yslow/ • Pingdom Tools http://tools.pingdom.com/ • WireShark / Fiddler2
  • 41. Browser Static Files Database and/or Data Store Web Server PHP App Server OS Web Services & Resources Hardware Cache
  • 43. Apachetop works with nginx
  • 44. Apache’s mod_status <Location /server-status> SetHandler server-status Order Deny,Allow Deny from all Allow from 25.131.42.122 </Location> # ExtendedStatus On
  • 46. siege
  • 47. siege • Command Line Tool • Run Concurrent HTTP Requests • Runs on Linux & Mac OS • Windows Users: Run a VM • Great Way to Test End Result
  • 48. siege • Create txt file with lists of URLs to hit • Run Command: siege -c 10 -r 10 -f urls.txt • c = concurrent r = # of requests f = path to URL file
  • 49. siege
  • 50. siege
  • 51. Other Tools • nginx stub status (similar to mod_status) http://wiki.nginx.org/HttpStubStatusModule • Apache Bench & http_load -- CLI • JMeter -- Java Desktop App
  • 52. Browser Static Files Database and/or Data Store Web Server PHP App Server OS Web Services & Resources Hardware Cache
  • 53. My Favorite New Tools: XHProf & XHGui
  • 54. XHProf • Developed by Facebook • Works well for both Development & Production* Profiling • pecl extension • Decent UI for viewing Results * - Use Sampling & Special CPU Flags for Production http://mirror.facebook.net/facebook/xhprof/doc.html
  • 55. XHGui • Improved GUI • Easy to Setup • Built In Sampling • Advanced Configuration • MySQL Backend • I recommend using this! https://github.com/preinheimer/xhprof
  • 56. More Fun to Show Demo Time
  • 57. Xdebug Profiler • Install Xdebug • Enable Xdebug Profiling • Outputs a Cachegrind Log • Use KCachegrind / WinCachegrind / Webgrind to view • For the Rich, MacCallGrind for $150
  • 58. Enabling Xdebug Profiling xdebug.profiler_enable=1 xdebug.profiler_output_dir=/tmp xdebug.profiler_output_name=cachegrind.out.%p Xdebug Profiling Not for Production (unless you have a 100TB HDD laying around)
  • 60. Timing Points • Most Frameworks have Built-In Profiling / Timing Points • Most ORMs have them as well • You can do them yourself • A must for Database Queries
  • 61. Timing Points $start = microtime(true); // true to get as float /* Do your Crazy Code, i.e. query */ $end = microtime(true); $time = round($end - $start, 4);
  • 62. Other Tools • Inclued http://php.net/manual/en/book.inclued.php • Memtrack http://php.net/manual/en/ book.memtrack.php
  • 63. Browser Static Files Database and/or Data Store Web Server PHP App Server OS Web Services & Resources Hardware Cache
  • 64. Databases • Typically, First Thing to Slow Down • Things to that will Kill the DB: • Missing Indexes • Nested Queries • Large Joins • Locked Queries
  • 65. Jet Profiler • MySQL Profiler • Free Version (Okay) & Paid (Awesome) • Not Cheap ($399) • But Worth It • Analytics Over Time
  • 67. MySQL Commands • explain <query> • show processlist • show variables • show status
  • 68. mtop
  • 69. Browser Static Files Database and/or Data Store Web Server PHP App Server OS Web Services & Resources Hardware Cache
  • 71. vmstat • swap > 0 means swapping Memory Issue • cpu sys + us really high CPU / Code / PHP Problem • cpu wa > 10 Disk IO Problem* * - Technically could be Network IO as well, but typically one of the last and more rare bottlenecks to hit
  • 73. top
  • 74. htop
  • 76. iotop
  • 77. Other Tools • netstat • iostat • mpstat • pidstat • (on ubuntu, install via sysstat package)
  • 78. Other Tools • grep, awk, sed • IPs Connected: netstat -plan | grep :80 | awk '{print $5}' | sed 's/::ffff://g' | awk -F: '{print $1}' | sort | uniq -c | sort -n
  • 79. Monitoring Munin http://munin-monitoring.org/
  • 80. Monitoring Wormly http://wormly.com/
  • 81. Whew, Lots of Tools and a lot more out there not in this talk Find any cool ones, let me know!
  • 82. Normal Profiling • Start with XHProf/XHGui and FireBug • Avoid Premature Optimization • Complicated Change • Little Reward • Use siege, or alternative, to simulate load.
  • 83. Emergency Profiling • Start with OS Level Testing Tools (htop, vmstat, vnstat) to check Server Performance • Determine which Resource(s) are being over utilized • Finding the bottleneck is key
  • 84. Emergency Profiling • What Changed? • Increased Traffic? • New Feature? • Something Failed/Down? • Don’t Panic & Start Wildly Guessing
  • 86. The Better You Understand The Problem The Better You Can Fix It
  • 87. Don’t Put Off Profiling Until there is an Emergency
  • 88. You Can Throw Hardward at the Problem, but Avoid IT
  • 89. Ask Others for Ideas aka Brainstorming
  • 92. Thanks! Twitter: JustinCarmony IRC: carmony #uphpu #phpc #joind.in Website: http://www.justincarmony.com/blog Email: justin@justincarmony.com

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n