SlideShare una empresa de Scribd logo
1 de 33
PHP Performance Principles and Tools By Kevin Schroeder Technology Evangelist Zend Technologies I have stickers!
About Kevin  Past: Programming/Sys Admin  Current: Technology Evangelist/Author/Composer          @kpschrade
Follow us! Zend Technologies http://twitter.com/zend http://twitter.com/kpschrade (me!)
Join us at ZendConThe premier PHP conference!October 17-19, 2011 – Santa Clara, CA Conference Themes Cloud Computing Learn about the latest developments in PHP Cloud infrastructure, management and application services Mobile and User Experience Learn how to build engaging mobile apps with the latest PHP technologies and tools Enterprise and Professional PHPExplore PHP best practices, new technologies and practical tips with industry experts Conference Highlights ,[object Object]
Sessions designed for all knowledge levels
Intensive tutorials for accelerated learning
PHP Certification crash courses and testing
Exhibit hall showcasing the latest products
Special networking opportunities during meals and eventswww.zendcon.com
Quiz Who here is a sysadmin? Who here is a developer? Who here is both?
WARNING! Performance is a HIGHLY context sensitive topic There are no answers here; only possible directions Do not micro-optimize 20ms cf. 100ms is not a 5 fold improvement in performance, it is a 5 fold waste of your time Unless you’re Yahoo, Google, Facebook, etc. The perception of performance is as important as actual performance Use the scientific method to find performance problems Observe Hypothesize Experiment Solve one problem at a time and MEASURE RESULTS!
General categories of performance problems
Performance – Database Symptoms Pages take a long time to load with Apache/IIS/PHP using proportionally less of the CPU time compared to DB Causes The list could go on for 4.23x105slides There are so many ways you can screw up your queries Tools Intra-application query monitoring, usually via a DB adapter abstraction layer Zend Server – A distinct group of monitoring options for DB calls in PHP
Performance - Database Possible remedies Simplify your queries Make your queries more complex Tune your database Don’t just automatically allocate more memory Don’t just create indexes Keeping this light because there are other, better, MySQL performance experts (many of them here)
Performance – Network Latency Symptoms Depends on where the latency is occurring Often slow page responses with low CPU usage Causes Network Saturation (probably not too likely) DNS Reverse Lookups TCP Handshakes High number of “hops” TCP Backlog … and much more Tools Wireshark Tcpdump Zend Server – monitor slow socket function execution
The TCP handshake T/TCP SYN + Response Data + FIN T/TCP SYN + Response Data + ACK +FIN ACK
Performance – IO Contention Symptoms  Unpredictable and difficult to reproduce page load times, but often corresponds to request frequency Causes Too few spindles serving too much data High write concurrency Insufficient free system RAM Insufficient depth of data directory structure Tools Zend Server (in extreme cases, long fopen() calls) vmstat & top (Linux) System Internals Process Explorer (Windows)
Performance – IO Contention Remedies Increase the number of disks Favor directory depth over width for storing raw data files Increase RAM so read operations can be pulled from memory
Performance – CPU Utilization Symptoms Page load times either correspond directly to CPU utilization or are consistently slow Causes Badcode or over-architected solutions Excessive recursion Excessive IO High server utilization too few servers serving too much traffic Tools top & vmstat (Linux) System Internals Process Explorer (Windows)
Performance – CPU Utilization There are often 2 different paths this will usually follow User time Time spent executing the code that you wrote System time Time spent running functionality that your code calls, such as networking, file system, etc.
Performance – Network Connectivity Symptoms Database or web service calls take long to execute Causes If read functions die unexpectedly, bad network hardware might be a cause Slow DNS queries Full TCP backlog Tools Zend Server – monitor failed calls to socket_connect(), fsockopen() or fread() Wireshark Tcpdump
OO Beware of magic! __get, __set, __call Situations where they are often used When representing another object that it has no knowledge of - I.e. Soap requests, COM objects, Java objects, database tables When there are property-level permissions on an object’s properties.  Keeping the properties private and using __get/set to determine access If used sparingly they won’t affect you, but many modern applications have lots of recursion or large underlying architectures that can have unpredicted consequences
!Preg Use preg_match for data checking only when you have to stripos(‘http://’, $website) is over twice as fast as preg_match(‘/http:/i’, $website) ctype_alnum() is almost 5 times as fast as preg_match(‘/^*$/’); Casting “if ($test == (int)$test)” is well over 5 times faster than preg_match(‘/^*$/) Preg will probably not bite you unless you have a lot of recursive logic that depends on it
Tools
OS tools to use Devs are really bad about thinking about the OS Use OS tooling!!! vmstat top tcpdump & wireshark strace Try stracehttpd –X at least once lsof You can map file descriptors found in strace to descriptors in lsof
Zend Server Monitors for several events like slow requests, slow DB calls, high memory usage, etc. Provides the context for those requests Can be configured to provide profile-like data from production installations Has a built in queuing mechanism that allows you to offload non-immediate processing (which can actually be quite a lot)
Do you queue? Offloading long running processes to a queuing system can help make your front end servers scale more vertically Examples include Job Queues Zend Server 5 (http://www.eschrade.com/ tag: job-queue) Gearman Beanstalk Message Queues ActiveMQ RabbitMQ
TODO || ! TODO
What not to do This is not complete!!! “Oh we’ll just cache it” “Our NFS server is just fine for serving PHP files” Use a frigging deployment mechanism “That LIKE query is necessary” You may need to structure your data a little different Don’t make your DB gues You might need to use a search engine instead Zend_Search_Lucene SOLR “Using arrays is faster than objects, we’ll use them instead” “Monitoring/diagnostic tools are too expensive”
List of things to do This is not complete!!! THINK before you code!! Minimize require_once calls/use an autoloader Try to make your architecture more horizontal rather than vertical People from Java backgrounds tend to go more vertical There is often a correlation between long stack traces and poor performance Use Lazy Loading/Load on Demand SPL arrays and such are great for this
List of things to do Use diagnostic tools! Zend Server Monitoring and Code Tracing Some kind of profiler  Utilize compiled PHP functionality for iterative complex functionality. Use Ajax Allows you to make a more responsive page by having fast content available immediately and slow content available as it’s ready
List of things to do With multiple service calls, consider batching multiple NB-IO requests Facebook does this, so it must be cool Synchronous requests – 4.2 seconds Asynchronous requests using curl – 1.5 seconds
Fin

Más contenido relacionado

La actualidad más candente

Bp106 Worst Practices Final
Bp106   Worst Practices FinalBp106   Worst Practices Final
Bp106 Worst Practices FinalBill Buchan
 
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuRapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuSalesforce Developers
 
Scalable Distributed System Architecture
Scalable Distributed System ArchitectureScalable Distributed System Architecture
Scalable Distributed System ArchitectureNicholas van de Walle
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Jackson F. de A. Mafra
 
Learn How Selenium And Jenkins Fit In DevOps | Edureka Live
Learn How Selenium And Jenkins Fit In DevOps | Edureka LiveLearn How Selenium And Jenkins Fit In DevOps | Edureka Live
Learn How Selenium And Jenkins Fit In DevOps | Edureka LiveEdureka!
 
Automating Compliance with InSpec - Chef Singapore Meetup
Automating Compliance with InSpec - Chef Singapore MeetupAutomating Compliance with InSpec - Chef Singapore Meetup
Automating Compliance with InSpec - Chef Singapore MeetupMatt Ray
 
Immutable Server generation: The new App Deployment
Immutable Server generation: The new App DeploymentImmutable Server generation: The new App Deployment
Immutable Server generation: The new App DeploymentAxel Fontaine
 
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon
 
Getting started with fiddler
Getting started with fiddlerGetting started with fiddler
Getting started with fiddlerZhi Zhong
 
High-Performance Magento in the Cloud
High-Performance Magento in the CloudHigh-Performance Magento in the Cloud
High-Performance Magento in the CloudAOE
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on WindowsShahar Evron
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with ChefJonathan Weiss
 
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Simplilearn
 
Configuration Management and Salt
Configuration Management and SaltConfiguration Management and Salt
Configuration Management and Salt55020
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefAll Things Open
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentDan Stine
 
Architecting for Continuous Delivery
Architecting for Continuous DeliveryArchitecting for Continuous Delivery
Architecting for Continuous DeliveryAxel Fontaine
 

La actualidad más candente (20)

Bp106 Worst Practices Final
Bp106   Worst Practices FinalBp106   Worst Practices Final
Bp106 Worst Practices Final
 
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on HerokuRapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
Rapid Prototyping Chatter with a PHP/Hack Canvas App on Heroku
 
Scalable Distributed System Architecture
Scalable Distributed System ArchitectureScalable Distributed System Architecture
Scalable Distributed System Architecture
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
 
Learn How Selenium And Jenkins Fit In DevOps | Edureka Live
Learn How Selenium And Jenkins Fit In DevOps | Edureka LiveLearn How Selenium And Jenkins Fit In DevOps | Edureka Live
Learn How Selenium And Jenkins Fit In DevOps | Edureka Live
 
Automating Compliance with InSpec - Chef Singapore Meetup
Automating Compliance with InSpec - Chef Singapore MeetupAutomating Compliance with InSpec - Chef Singapore Meetup
Automating Compliance with InSpec - Chef Singapore Meetup
 
Immutable Server generation: The new App Deployment
Immutable Server generation: The new App DeploymentImmutable Server generation: The new App Deployment
Immutable Server generation: The new App Deployment
 
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
DevSecCon London 2017 - MacOS security, hardening and forensics 101 by Ben Hu...
 
Getting started with fiddler
Getting started with fiddlerGetting started with fiddler
Getting started with fiddler
 
High-Performance Magento in the Cloud
High-Performance Magento in the CloudHigh-Performance Magento in the Cloud
High-Performance Magento in the Cloud
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on Windows
 
Require js training
Require js trainingRequire js training
Require js training
 
Django Documentation
Django DocumentationDjango Documentation
Django Documentation
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
 
Configuration Management and Salt
Configuration Management and SaltConfiguration Management and Salt
Configuration Management and Salt
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated Deployment
 
Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016
 
Architecting for Continuous Delivery
Architecting for Continuous DeliveryArchitecting for Continuous Delivery
Architecting for Continuous Delivery
 

Similar a PHP Performance: Principles and tools

Scaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformScaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformShahar Evron
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practiceswebuploader
 
Slides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetingsSlides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetings10n Software, LLC
 
Modern Application Stacks
Modern Application StacksModern Application Stacks
Modern Application Stackschartjes
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginnerswebhostingguy
 
Server Monitoring (Scaling while bootstrapped)
Server Monitoring  (Scaling while bootstrapped)Server Monitoring  (Scaling while bootstrapped)
Server Monitoring (Scaling while bootstrapped)Ajibola Aiyedogbon
 
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseBlack Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseTim Vaillancourt
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.pptwebhostingguy
 
Top 30 Scalability Mistakes
Top 30 Scalability MistakesTop 30 Scalability Mistakes
Top 30 Scalability MistakesJohn Coggeshall
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability MistakesJohn Coggeshall
 
ConFoo 2017: Introduction to performance optimization of .NET web apps
ConFoo 2017: Introduction to performance optimization of .NET web appsConFoo 2017: Introduction to performance optimization of .NET web apps
ConFoo 2017: Introduction to performance optimization of .NET web appsPierre-Luc Maheu
 
Making it fast: Zotonic & Performance
Making it fast: Zotonic & PerformanceMaking it fast: Zotonic & Performance
Making it fast: Zotonic & PerformanceArjan
 
Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?varien
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesJohn Coggeshall
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015Christopher Curtin
 
Profiling php applications
Profiling php applicationsProfiling php applications
Profiling php applicationsJustin Carmony
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability MistakesJohn Coggeshall
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1nhepner
 

Similar a PHP Performance: Principles and tools (20)

Scaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformScaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend Platform
 
scale_perf_best_practices
scale_perf_best_practicesscale_perf_best_practices
scale_perf_best_practices
 
Slides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetingsSlides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetings
 
Modern Application Stacks
Modern Application StacksModern Application Stacks
Modern Application Stacks
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
 
Server Monitoring (Scaling while bootstrapped)
Server Monitoring  (Scaling while bootstrapped)Server Monitoring  (Scaling while bootstrapped)
Server Monitoring (Scaling while bootstrapped)
 
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseBlack Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
 
Webtechnologies
Webtechnologies Webtechnologies
Webtechnologies
 
WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
 
Top 30 Scalability Mistakes
Top 30 Scalability MistakesTop 30 Scalability Mistakes
Top 30 Scalability Mistakes
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability Mistakes
 
Search Lucene
Search LuceneSearch Lucene
Search Lucene
 
ConFoo 2017: Introduction to performance optimization of .NET web apps
ConFoo 2017: Introduction to performance optimization of .NET web appsConFoo 2017: Introduction to performance optimization of .NET web apps
ConFoo 2017: Introduction to performance optimization of .NET web apps
 
Making it fast: Zotonic & Performance
Making it fast: Zotonic & PerformanceMaking it fast: Zotonic & Performance
Making it fast: Zotonic & Performance
 
Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 Mistakes
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015
 
Profiling php applications
Profiling php applicationsProfiling php applications
Profiling php applications
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability Mistakes
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1
 

Más de 10n Software, LLC

Delaying Gratification: Using queues to build efficient systems
Delaying Gratification: Using queues to build efficient systemsDelaying Gratification: Using queues to build efficient systems
Delaying Gratification: Using queues to build efficient systems10n Software, LLC
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks10n Software, LLC
 
Creating stunning data analytics dashboard using php and flex
Creating stunning data analytics dashboard using php and flexCreating stunning data analytics dashboard using php and flex
Creating stunning data analytics dashboard using php and flex10n Software, LLC
 
Slideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You QueueSlideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You Queue10n Software, LLC
 

Más de 10n Software, LLC (13)

Delaying Gratification: Using queues to build efficient systems
Delaying Gratification: Using queues to build efficient systemsDelaying Gratification: Using queues to build efficient systems
Delaying Gratification: Using queues to build efficient systems
 
10 things
10 things10 things
10 things
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks
 
Do you queue (updated)
Do you queue (updated)Do you queue (updated)
Do you queue (updated)
 
Flex for php developers
Flex for php developersFlex for php developers
Flex for php developers
 
Creating stunning data analytics dashboard using php and flex
Creating stunning data analytics dashboard using php and flexCreating stunning data analytics dashboard using php and flex
Creating stunning data analytics dashboard using php and flex
 
Php security common 2011
Php security common 2011Php security common 2011
Php security common 2011
 
North east user group tour
North east user group tourNorth east user group tour
North east user group tour
 
Slideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You QueueSlideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You Queue
 
Do you queue
Do you queueDo you queue
Do you queue
 
Zend Server - OSI Days
Zend Server - OSI DaysZend Server - OSI Days
Zend Server - OSI Days
 
Zend Framework Workshop
Zend Framework WorkshopZend Framework Workshop
Zend Framework Workshop
 
Flex and Zend Framework
Flex and Zend FrameworkFlex and Zend Framework
Flex and Zend Framework
 

Último

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Último (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

PHP Performance: Principles and tools

  • 1. PHP Performance Principles and Tools By Kevin Schroeder Technology Evangelist Zend Technologies I have stickers!
  • 2. About Kevin Past: Programming/Sys Admin Current: Technology Evangelist/Author/Composer @kpschrade
  • 3. Follow us! Zend Technologies http://twitter.com/zend http://twitter.com/kpschrade (me!)
  • 4.
  • 5. Sessions designed for all knowledge levels
  • 6. Intensive tutorials for accelerated learning
  • 7. PHP Certification crash courses and testing
  • 8. Exhibit hall showcasing the latest products
  • 9. Special networking opportunities during meals and eventswww.zendcon.com
  • 10. Quiz Who here is a sysadmin? Who here is a developer? Who here is both?
  • 11. WARNING! Performance is a HIGHLY context sensitive topic There are no answers here; only possible directions Do not micro-optimize 20ms cf. 100ms is not a 5 fold improvement in performance, it is a 5 fold waste of your time Unless you’re Yahoo, Google, Facebook, etc. The perception of performance is as important as actual performance Use the scientific method to find performance problems Observe Hypothesize Experiment Solve one problem at a time and MEASURE RESULTS!
  • 12. General categories of performance problems
  • 13. Performance – Database Symptoms Pages take a long time to load with Apache/IIS/PHP using proportionally less of the CPU time compared to DB Causes The list could go on for 4.23x105slides There are so many ways you can screw up your queries Tools Intra-application query monitoring, usually via a DB adapter abstraction layer Zend Server – A distinct group of monitoring options for DB calls in PHP
  • 14. Performance - Database Possible remedies Simplify your queries Make your queries more complex Tune your database Don’t just automatically allocate more memory Don’t just create indexes Keeping this light because there are other, better, MySQL performance experts (many of them here)
  • 15. Performance – Network Latency Symptoms Depends on where the latency is occurring Often slow page responses with low CPU usage Causes Network Saturation (probably not too likely) DNS Reverse Lookups TCP Handshakes High number of “hops” TCP Backlog … and much more Tools Wireshark Tcpdump Zend Server – monitor slow socket function execution
  • 16. The TCP handshake T/TCP SYN + Response Data + FIN T/TCP SYN + Response Data + ACK +FIN ACK
  • 17. Performance – IO Contention Symptoms Unpredictable and difficult to reproduce page load times, but often corresponds to request frequency Causes Too few spindles serving too much data High write concurrency Insufficient free system RAM Insufficient depth of data directory structure Tools Zend Server (in extreme cases, long fopen() calls) vmstat & top (Linux) System Internals Process Explorer (Windows)
  • 18. Performance – IO Contention Remedies Increase the number of disks Favor directory depth over width for storing raw data files Increase RAM so read operations can be pulled from memory
  • 19. Performance – CPU Utilization Symptoms Page load times either correspond directly to CPU utilization or are consistently slow Causes Badcode or over-architected solutions Excessive recursion Excessive IO High server utilization too few servers serving too much traffic Tools top & vmstat (Linux) System Internals Process Explorer (Windows)
  • 20. Performance – CPU Utilization There are often 2 different paths this will usually follow User time Time spent executing the code that you wrote System time Time spent running functionality that your code calls, such as networking, file system, etc.
  • 21. Performance – Network Connectivity Symptoms Database or web service calls take long to execute Causes If read functions die unexpectedly, bad network hardware might be a cause Slow DNS queries Full TCP backlog Tools Zend Server – monitor failed calls to socket_connect(), fsockopen() or fread() Wireshark Tcpdump
  • 22. OO Beware of magic! __get, __set, __call Situations where they are often used When representing another object that it has no knowledge of - I.e. Soap requests, COM objects, Java objects, database tables When there are property-level permissions on an object’s properties. Keeping the properties private and using __get/set to determine access If used sparingly they won’t affect you, but many modern applications have lots of recursion or large underlying architectures that can have unpredicted consequences
  • 23. !Preg Use preg_match for data checking only when you have to stripos(‘http://’, $website) is over twice as fast as preg_match(‘/http:/i’, $website) ctype_alnum() is almost 5 times as fast as preg_match(‘/^*$/’); Casting “if ($test == (int)$test)” is well over 5 times faster than preg_match(‘/^*$/) Preg will probably not bite you unless you have a lot of recursive logic that depends on it
  • 24. Tools
  • 25. OS tools to use Devs are really bad about thinking about the OS Use OS tooling!!! vmstat top tcpdump & wireshark strace Try stracehttpd –X at least once lsof You can map file descriptors found in strace to descriptors in lsof
  • 26. Zend Server Monitors for several events like slow requests, slow DB calls, high memory usage, etc. Provides the context for those requests Can be configured to provide profile-like data from production installations Has a built in queuing mechanism that allows you to offload non-immediate processing (which can actually be quite a lot)
  • 27. Do you queue? Offloading long running processes to a queuing system can help make your front end servers scale more vertically Examples include Job Queues Zend Server 5 (http://www.eschrade.com/ tag: job-queue) Gearman Beanstalk Message Queues ActiveMQ RabbitMQ
  • 28. TODO || ! TODO
  • 29. What not to do This is not complete!!! “Oh we’ll just cache it” “Our NFS server is just fine for serving PHP files” Use a frigging deployment mechanism “That LIKE query is necessary” You may need to structure your data a little different Don’t make your DB gues You might need to use a search engine instead Zend_Search_Lucene SOLR “Using arrays is faster than objects, we’ll use them instead” “Monitoring/diagnostic tools are too expensive”
  • 30. List of things to do This is not complete!!! THINK before you code!! Minimize require_once calls/use an autoloader Try to make your architecture more horizontal rather than vertical People from Java backgrounds tend to go more vertical There is often a correlation between long stack traces and poor performance Use Lazy Loading/Load on Demand SPL arrays and such are great for this
  • 31. List of things to do Use diagnostic tools! Zend Server Monitoring and Code Tracing Some kind of profiler Utilize compiled PHP functionality for iterative complex functionality. Use Ajax Allows you to make a more responsive page by having fast content available immediately and slow content available as it’s ready
  • 32. List of things to do With multiple service calls, consider batching multiple NB-IO requests Facebook does this, so it must be cool Synchronous requests – 4.2 seconds Asynchronous requests using curl – 1.5 seconds
  • 33. Fin
  • 35. To contact me after my presentation, text XIK to INTRO (46876) Follow us! Zend Technologies http://twitter.com/zend http://twitter.com/kpschrade (me!)
  • 36.
  • 37. Sessions designed for all knowledge levels
  • 38. Intensive tutorials for accelerated learning
  • 39. PHP Certification crash courses and testing
  • 40. Exhibit hall showcasing the latest products
  • 41. Special networking opportunities during meals and eventswww.zendcon.com
  • 42. List of things to do Similarly, be careful when dealing with lots of Ajax data Developers running test data often under-estimate how much data their code will send back The browser needs to process that data With large data sets the browser may take a while to update the DOM 2 options Use staggered loading Pass rendered content to the browser and attach with innerHTML
  • 43. List of things to do Be aware of your page size Oracle – 104kb – 861ms Zend – 183kb – 2.4 seconds Microsoft – 238kb – 4.4 seconds IBM – 640 kb – 4.6 seconds There is a relatively direct relationship between the amount of data on your web page and the render time