SlideShare a Scribd company logo
PERFORMANCE TIPS 
FOR SYMFONY2 & PHP 
Minsk PHP User Group Meetup #10
Intro 
 Max Romanovsky 
 37 Slides 
 Questions after presentation 
 Out of scope: HW & OS tuning, VM vs HW 
servers 
 “Premature optimization is the root of all evil” 
Knuth’s quote is missing 
 No cats, boobs or other images in slides  
2
Quiz 
3 
 What to optimize? 
 Architecture 
 Code 
 Services
Agenda 
 Overview 
 Measure 
 Services 
 Architecture 
 Code 
 Symfony2 tips 
4
5 Overview
How to start? 
 Forget about microoptimizations for now 
 Курочка по зернышку – весь двор в говне 
 Make it scalable 
 What is cheaper? To scale or to optimize? 
6
Tune 
 Tune services 
 Tune architecture 
 Consider tuning code 
7
Quiz 
8 
 What was the sloooooowest? 
 DB queries 
 Network communication 
 PHP configuration 
 VM/HW server 
 Stupid code
What could be slow 
9 
 Network communication (with client, inside 
LAN) 
 VM/HW server 
 OS & runtime itself 
 Communication with services 
 Code (finally!)
10 Measure
Stop! Measure 
11 
 Measure before 
 Measure during 
 Measure after 
 Measure periodically 
 measure 
 Measure 
 MEASURE!!1
Quiz 
12 
 What do you use? 
 Symfony Profiler 
 symfony/stopwatch 
 Из говна и палок 
 Xhprof 
 Xdebug 
 Zend Profiler
Tools 
13 
 Xhprof / uprofiler 
 Xdebug  
 Framework tools  
  = overhead & irrelevant results
Question 
14 
 Can we compare xhprof & xdebug results? 
 Are they relevant?
Overhead & irrelevant results? 
15 
 Runtime (i.e. code execution) is slower with 
profiler enabled 
 Communication with services is not slower 
 Mess in results 
 You are analyzing DIFFERENT results
Use lightweight profiler 
16 
 XHProf 
 XHgui (saves runs to RDBMS) 
 Uprofiler (fork?) 
 https://github.com/FriendsOfPHP/uprofiler
Measure performance in real 
world 
17 
 Turn on profiler periodically 
 For 1% of requests 
 For 1 app server 
 Record & replay user activity 
 Use Jmeter to record scenarios 
 Use good old ab, siege, http_load
Tune 
18 
 Tune 1 factor at once 
 Store configuration & measuring results in 
VCS 
 Measure after tuning
19 Services
Why? 
20 
 Receive profit without changing a single line of 
code
Question 
21 
 Do you know what is an Opcache? 
 Do you use it?
PHP 
22 
 Don’t use the latest PHP version, please! 
 Use PHP-FPM (or even HHVM?) 
 Opcache or APC 
 APCu 
 Compile stable libraries as PHP extensions 
 Twig 
 Redis 
 AMQP
Composer 
23 
 composer install --optimize-autoloader
24 Architecture
Architecture 
 Make it scalable. Period. 
 Use PAAS services 
 CDN 
 File storage 
 Choose efficient protocols & frameworks 
 Apache Thrift 
 Google Protocol Buffers 
25
Cache 
26 
 Raw data 
 Computed data 
 View layer
Cache 
27 
 Raw data = DB/Data Source 
 MySQL query cache 
 HTTP API reverse proxy cache
Cache 
28 
 Computed data = Key-value 
 Persistent? 
 Consistent? 
 Check your DB features
Cache 
29 
 View layer = HTTP cache 
 Nginx 
 Varnish
30 Code
Why not to optimize 
31 
 Improve architecture 
 Man, it’s PHP! It is designed to be SLOOOOW 
 Optimize code for people, not for machines 
 Курочка по зернышку?.. 
 Well… OK. But profile
What to optimize. Boooring 
32 
 DB 
 Move calculations to DB 
 Move aggregation to DB 
 MOVE LIMIT TO DB!!1 
 Move calculations outside the loop 
 Don’t concatenate string insanely 
 Don’t pass huge arrays by value to functions 
 Don’t use arrays anyway 
33 Symfony2 tips
As seen on TV 
34 
 http://symfony.com/doc/current/book/performa 
nce.html 
 Use a Byte Code Cache 
 Composer's Class Map 
 Caching the Autoloader with APC 
 Use Bootstrap Files
Tipzzz 
35 
 Services 
 Lazy with ocramius/proxy-manager 
 Controllers 
 Console commands 
 Move app/cache to tmpfs 
 Twig C extension 
 Don’t use router:dump. It’s deprecated 
 https://github.com/symfony/symfony/issues/9652 
 Don’t use Symfony Profiler for profiling 
More? 
36 
 http://symfony.com/blog/push-it-to-the-limits-symfony2- 
for-high-performance-needs 
 https://www.youtube.com/watch?v=b8ewqVGu 
77w 
 https://profiler.sensiolabs.com/ - still waiting for 
invite
The End 
37 
 max.romanovsky@gmail.com 
 http://maxromanovsky.com

More Related Content

What's hot

Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
Mathew Beane
 
Statyczna analiza kodu PHP
Statyczna analiza kodu PHPStatyczna analiza kodu PHP
Statyczna analiza kodu PHP
The Software House
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
Jacques Woodcock
 
Application Deployment Using Ansible
Application Deployment Using AnsibleApplication Deployment Using Ansible
Application Deployment Using Ansible
Cliffano Subagio
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
Adam Englander
 
Php Performance On Windows
Php Performance On WindowsPhp Performance On Windows
Php Performance On Windows
ruslany
 
Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)
Anton Babenko
 
Composer | PHP Dependency Manager
Composer | PHP Dependency ManagerComposer | PHP Dependency Manager
Composer | PHP Dependency Manager
Ujjwal Ojha
 
Puppet evolutions
Puppet evolutionsPuppet evolutions
Puppet evolutions
Alessandro Franceschi
 
Securing Legacy CFML Code
Securing Legacy CFML CodeSecuring Legacy CFML Code
Securing Legacy CFML Code
ColdFusionConference
 
Can you contain the future - Docker, Container Technologies, The Future, and You
Can you contain the future - Docker, Container Technologies, The Future, and YouCan you contain the future - Docker, Container Technologies, The Future, and You
Can you contain the future - Docker, Container Technologies, The Future, and You
ColdFusionConference
 
Intro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio CodeIntro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio Code
ColdFusionConference
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Julian Robichaux
 
This is how we REST
This is how we RESTThis is how we REST
This is how we REST
ColdFusionConference
 
OpenNTF Webinar May 2021 - Jesse
OpenNTF Webinar May 2021 - JesseOpenNTF Webinar May 2021 - Jesse
OpenNTF Webinar May 2021 - Jesse
Jesse Gallagher
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀
Chen Cheng-Wei
 
Building dynamic websites with Mod perl and apache
Building dynamic websites with Mod perl and apacheBuilding dynamic websites with Mod perl and apache
Building dynamic websites with Mod perl and apache
Kamal Nayan
 
Virtual Bolt Workshop - March 16, 2020
Virtual Bolt Workshop - March 16, 2020Virtual Bolt Workshop - March 16, 2020
Virtual Bolt Workshop - March 16, 2020
Puppet
 

What's hot (19)

Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
Statyczna analiza kodu PHP
Statyczna analiza kodu PHPStatyczna analiza kodu PHP
Statyczna analiza kodu PHP
 
mod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLImod_php vs FastCGI vs FPM vs CLI
mod_php vs FastCGI vs FPM vs CLI
 
Application Deployment Using Ansible
Application Deployment Using AnsibleApplication Deployment Using Ansible
Application Deployment Using Ansible
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Php Performance On Windows
Php Performance On WindowsPhp Performance On Windows
Php Performance On Windows
 
Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)
 
Composer | PHP Dependency Manager
Composer | PHP Dependency ManagerComposer | PHP Dependency Manager
Composer | PHP Dependency Manager
 
Puppet evolutions
Puppet evolutionsPuppet evolutions
Puppet evolutions
 
Securing Legacy CFML Code
Securing Legacy CFML CodeSecuring Legacy CFML Code
Securing Legacy CFML Code
 
Can you contain the future - Docker, Container Technologies, The Future, and You
Can you contain the future - Docker, Container Technologies, The Future, and YouCan you contain the future - Docker, Container Technologies, The Future, and You
Can you contain the future - Docker, Container Technologies, The Future, and You
 
Intro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio CodeIntro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio Code
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
 
This is how we REST
This is how we RESTThis is how we REST
This is how we REST
 
Cfml features modern_coding
Cfml features modern_codingCfml features modern_coding
Cfml features modern_coding
 
OpenNTF Webinar May 2021 - Jesse
OpenNTF Webinar May 2021 - JesseOpenNTF Webinar May 2021 - Jesse
OpenNTF Webinar May 2021 - Jesse
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀
 
Building dynamic websites with Mod perl and apache
Building dynamic websites with Mod perl and apacheBuilding dynamic websites with Mod perl and apache
Building dynamic websites with Mod perl and apache
 
Virtual Bolt Workshop - March 16, 2020
Virtual Bolt Workshop - March 16, 2020Virtual Bolt Workshop - March 16, 2020
Virtual Bolt Workshop - March 16, 2020
 

Viewers also liked

Держим руку на пульсе проекта. Мониторинг PHP-приложений
Держим руку на пульсе проекта. Мониторинг PHP-приложенийДержим руку на пульсе проекта. Мониторинг PHP-приложений
Держим руку на пульсе проекта. Мониторинг PHP-приложений
Max Romanovsky
 
Symfony 2 under control
Symfony 2 under controlSymfony 2 under control
Symfony 2 under control
Max Romanovsky
 
Living documentation mini-workshop
Living documentation mini-workshopLiving documentation mini-workshop
Living documentation mini-workshop
Matthias Noback
 
Increase your performance and code quality
Increase your performance and code qualityIncrease your performance and code quality
Increase your performance and code quality
Dusko Vesin
 
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Max Romanovsky
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 Developers
Marcin Chwedziak
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
Leonardo Proietti
 
Rationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringRationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoring
Giulio De Donato
 

Viewers also liked (8)

Держим руку на пульсе проекта. Мониторинг PHP-приложений
Держим руку на пульсе проекта. Мониторинг PHP-приложенийДержим руку на пульсе проекта. Мониторинг PHP-приложений
Держим руку на пульсе проекта. Мониторинг PHP-приложений
 
Symfony 2 under control
Symfony 2 under controlSymfony 2 under control
Symfony 2 under control
 
Living documentation mini-workshop
Living documentation mini-workshopLiving documentation mini-workshop
Living documentation mini-workshop
 
Increase your performance and code quality
Increase your performance and code qualityIncrease your performance and code quality
Increase your performance and code quality
 
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 Developers
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Rationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringRationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoring
 

Similar to Performance tips for Symfony2 & PHP

Joomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation TestingJoomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation Testing
Shyam Sunder Verma
 
On component interface
On component interfaceOn component interface
On component interface
Laurence Chen
 
Data flow architecture of spa @ codibly [warning for open minds only]
Data flow architecture of spa @ codibly [warning  for open minds only]Data flow architecture of spa @ codibly [warning  for open minds only]
Data flow architecture of spa @ codibly [warning for open minds only]
Łukasz Dobosz
 
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Ontico
 
Labview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRLLabview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRL
Mohammad Sabouri
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
Zend by Rogue Wave Software
 
API workshop by AWS and 3scale
API workshop by AWS and 3scaleAPI workshop by AWS and 3scale
API workshop by AWS and 3scale
3scale
 
Using RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocolUsing RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocol
Tho Q Luong Luong
 
How Browser and server works
How Browser and server worksHow Browser and server works
How Browser and server worksWeb Developer
 
System Benchmarking
System BenchmarkingSystem Benchmarking
System Benchmarking
Raghav Nayak
 
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
Charles Beyer
 
Devops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftDevops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShift
Yaniv cohen
 
Cytoscape CI Chapter 2
Cytoscape CI Chapter 2Cytoscape CI Chapter 2
Cytoscape CI Chapter 2
bdemchak
 
Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?
Veselin Pizurica
 
Learn more about the tremendous value Open Data Plane brings to NFV
Learn more about the tremendous value Open Data Plane brings to NFVLearn more about the tremendous value Open Data Plane brings to NFV
Learn more about the tremendous value Open Data Plane brings to NFV
Ghodhbane Mohamed Amine
 
Connect Bridge
Connect BridgeConnect Bridge
Connect Bridge
Connecting Software
 
Benchmarking Hadoop and Big Data
Benchmarking Hadoop and Big DataBenchmarking Hadoop and Big Data
Benchmarking Hadoop and Big Data
Nicolas Poggi
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
Kyrylo Reznykov
 
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
InfluxData
 

Similar to Performance tips for Symfony2 & PHP (20)

Joomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation TestingJoomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation Testing
 
On component interface
On component interfaceOn component interface
On component interface
 
Data flow architecture of spa @ codibly [warning for open minds only]
Data flow architecture of spa @ codibly [warning  for open minds only]Data flow architecture of spa @ codibly [warning  for open minds only]
Data flow architecture of spa @ codibly [warning for open minds only]
 
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
 
Labview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRLLabview1_ Computer Applications in Control_ACRRL
Labview1_ Computer Applications in Control_ACRRL
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
API workshop by AWS and 3scale
API workshop by AWS and 3scaleAPI workshop by AWS and 3scale
API workshop by AWS and 3scale
 
Using RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocolUsing RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocol
 
How Browser and server works
How Browser and server worksHow Browser and server works
How Browser and server works
 
Introduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSPIntroduction to Blackfin BF532 DSP
Introduction to Blackfin BF532 DSP
 
System Benchmarking
System BenchmarkingSystem Benchmarking
System Benchmarking
 
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
 
Devops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftDevops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShift
 
Cytoscape CI Chapter 2
Cytoscape CI Chapter 2Cytoscape CI Chapter 2
Cytoscape CI Chapter 2
 
Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?
 
Learn more about the tremendous value Open Data Plane brings to NFV
Learn more about the tremendous value Open Data Plane brings to NFVLearn more about the tremendous value Open Data Plane brings to NFV
Learn more about the tremendous value Open Data Plane brings to NFV
 
Connect Bridge
Connect BridgeConnect Bridge
Connect Bridge
 
Benchmarking Hadoop and Big Data
Benchmarking Hadoop and Big DataBenchmarking Hadoop and Big Data
Benchmarking Hadoop and Big Data
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
 
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
 

Recently uploaded

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 

Recently uploaded (20)

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 

Performance tips for Symfony2 & PHP

  • 1. PERFORMANCE TIPS FOR SYMFONY2 & PHP Minsk PHP User Group Meetup #10
  • 2. Intro  Max Romanovsky  37 Slides  Questions after presentation  Out of scope: HW & OS tuning, VM vs HW servers  “Premature optimization is the root of all evil” Knuth’s quote is missing  No cats, boobs or other images in slides  2
  • 3. Quiz 3  What to optimize?  Architecture  Code  Services
  • 4. Agenda  Overview  Measure  Services  Architecture  Code  Symfony2 tips 4
  • 6. How to start?  Forget about microoptimizations for now  Курочка по зернышку – весь двор в говне  Make it scalable  What is cheaper? To scale or to optimize? 6
  • 7. Tune  Tune services  Tune architecture  Consider tuning code 7
  • 8. Quiz 8  What was the sloooooowest?  DB queries  Network communication  PHP configuration  VM/HW server  Stupid code
  • 9. What could be slow 9  Network communication (with client, inside LAN)  VM/HW server  OS & runtime itself  Communication with services  Code (finally!)
  • 11. Stop! Measure 11  Measure before  Measure during  Measure after  Measure periodically  measure  Measure  MEASURE!!1
  • 12. Quiz 12  What do you use?  Symfony Profiler  symfony/stopwatch  Из говна и палок  Xhprof  Xdebug  Zend Profiler
  • 13. Tools 13  Xhprof / uprofiler  Xdebug   Framework tools    = overhead & irrelevant results
  • 14. Question 14  Can we compare xhprof & xdebug results?  Are they relevant?
  • 15. Overhead & irrelevant results? 15  Runtime (i.e. code execution) is slower with profiler enabled  Communication with services is not slower  Mess in results  You are analyzing DIFFERENT results
  • 16. Use lightweight profiler 16  XHProf  XHgui (saves runs to RDBMS)  Uprofiler (fork?)  https://github.com/FriendsOfPHP/uprofiler
  • 17. Measure performance in real world 17  Turn on profiler periodically  For 1% of requests  For 1 app server  Record & replay user activity  Use Jmeter to record scenarios  Use good old ab, siege, http_load
  • 18. Tune 18  Tune 1 factor at once  Store configuration & measuring results in VCS  Measure after tuning
  • 20. Why? 20  Receive profit without changing a single line of code
  • 21. Question 21  Do you know what is an Opcache?  Do you use it?
  • 22. PHP 22  Don’t use the latest PHP version, please!  Use PHP-FPM (or even HHVM?)  Opcache or APC  APCu  Compile stable libraries as PHP extensions  Twig  Redis  AMQP
  • 23. Composer 23  composer install --optimize-autoloader
  • 25. Architecture  Make it scalable. Period.  Use PAAS services  CDN  File storage  Choose efficient protocols & frameworks  Apache Thrift  Google Protocol Buffers 25
  • 26. Cache 26  Raw data  Computed data  View layer
  • 27. Cache 27  Raw data = DB/Data Source  MySQL query cache  HTTP API reverse proxy cache
  • 28. Cache 28  Computed data = Key-value  Persistent?  Consistent?  Check your DB features
  • 29. Cache 29  View layer = HTTP cache  Nginx  Varnish
  • 31. Why not to optimize 31  Improve architecture  Man, it’s PHP! It is designed to be SLOOOOW  Optimize code for people, not for machines  Курочка по зернышку?..  Well… OK. But profile
  • 32. What to optimize. Boooring 32  DB  Move calculations to DB  Move aggregation to DB  MOVE LIMIT TO DB!!1  Move calculations outside the loop  Don’t concatenate string insanely  Don’t pass huge arrays by value to functions  Don’t use arrays anyway 
  • 34. As seen on TV 34  http://symfony.com/doc/current/book/performa nce.html  Use a Byte Code Cache  Composer's Class Map  Caching the Autoloader with APC  Use Bootstrap Files
  • 35. Tipzzz 35  Services  Lazy with ocramius/proxy-manager  Controllers  Console commands  Move app/cache to tmpfs  Twig C extension  Don’t use router:dump. It’s deprecated  https://github.com/symfony/symfony/issues/9652  Don’t use Symfony Profiler for profiling 
  • 36. More? 36  http://symfony.com/blog/push-it-to-the-limits-symfony2- for-high-performance-needs  https://www.youtube.com/watch?v=b8ewqVGu 77w  https://profiler.sensiolabs.com/ - still waiting for invite
  • 37. The End 37  max.romanovsky@gmail.com  http://maxromanovsky.com