SlideShare a Scribd company logo
You cannot optimize
what you cannot measure
blackfire.io @blackfireio # blackfireio
How to measure PHP code
performance
● Microtime
● Benchmarking Libraries
● Application Performance Monitoring
● Load testing
● Profiling
https://blackfire.io/docs/24-days/03-what-is-blackfire
Measuring performance
impacts performance
blackfire.io @blackfireio # blackfireio
Understanding the overhead
● Instrumentation
● Tools ready for production vs tools made for
development only
● Instrumenting all requests vs specific requests
blackfire.io @blackfireio # blackfireio
Profiling is about measuring how much
resources your code is consuming
Wall time I/O CPU
Memory Network SQLHTTP Time
https://blackfire.io/docs/24-days/07-time-flavors
blackfire.io @blackfireio # blackfireio
Time is volatile
● Time is not a stable metric. External factors such as machine load can
have significant impacts on wall time between two profiles of identical
code.
● Time is just a consequence of what happened in the code
● Use time to identify the slow parts in your code and then:
○ iterate and compare
○ write assertions on the root cause
● Profiling is about understanding how code works at runtime
https://blackfire.io/docs/24-days/12-tests-best-pratices
blackfire.io @blackfireio # blackfireio
Callgraphs, timelines and more
● Find the function calls that
consume the most resources
● Know where to stop optimizing
● Trade-off time vs memory and
performance vs code complexity
● Profiling should not always be a
lonely activity
blackfire.io @blackfireio
#blackfireio
What are the issues
we encounter with
Magento 2
You cannot optimize
what you cannot measure
You cannot measure
what you don’t execute.
blackfire.io @blackfireio # blackfireio
Varnish, can you ignore me?
acl profile {
# Allowed IP
"111.112.113.114";
}
sub vcl_recv {
if (req.http.X-Blackfire-Query && client.ip ~ profile) {
if (req.esi_level > 0) {
unset req.http.X-Blackfire-Query;
} else {
return (pass);
}
}
}
blackfire.io @blackfireio # blackfireio
What about the Full Page Cache?
And all the others.
blackfire.io @blackfireio # blackfireio
You have to compare.
blackfire.io @blackfireio # blackfireio
The main issues
● SQL Queries
● Network
● CPU Time
● Memory
● I/O Wait
● External HTTP requests
● PHP & Bad PHP code
blackfire.io @blackfireio # blackfireio
SQL Queries
● Use indexes and correct types.
● Limit the number of results you need.
● Avoid SQL requests…
● If you can’t avoid them, cache the output or
use LocalStorage/CacheStorage if insensitive information.
● Use Magento Repositories.
SQL Requests are the main issue.
blackfire.io @blackfireio # blackfireio
● Use local networks with local IP addresses.
Network
blackfire.io @blackfireio # blackfireio
CPU Time
● Avoid consuming operations: loops, events…
● Use Magento Repositories.
● KISS : Keep It Simple Stupid.
blackfire.io @blackfireio # blackfireio
Memory
● Use the MagentoFrameworkModelResourceModelIterator for your
loops.
● Use PHP! Avoid creating so many objects when you can do the
operation with one function call.
● Use the Magento Dependency Injection.
● Use Magento Repositories.
blackfire.io @blackfireio # blackfireio
I/O Wait
● Use php://memory and php://temp. Because Memory is always faster
than I/O.
● Optimize composer: composer dump-autoload --optimize --no-dev
blackfire.io @blackfireio # blackfireio
External HTTP Requests
● Don’t do that.
● If you really have to: use RabbitMQ.
● And if you really have no choice: use asynchronous?
● And if you really really have no choice: use a small timeout and deal with
the errors properly.
blackfire.io @blackfireio # blackfireio
PHP & Bad PHP code
blackfire.io @blackfireio # blackfireio
PHP & Bad PHP code
● Upgrade to the latest version of PHP.
● Prefer a PHP core function to a lot of objects and methods.
●
Under the hood
blackfire.io @blackfireio # blackfireio
The metrics
● Is Magento 2 installed? CE or EE?
● Is the cache enabled?
● Cache manipulation.
● Product loads.
● Interceptors measurement.
● Mode detector: production/developer/default.
● …
blackfire.io @blackfireio # blackfireio
The metrics
magento2.all.cache.full_page.builtin.hit:
label: "Hit full page cache using builtin"
matching_calls:
php:
- callee: "=Magento[…]BuiltinPlugin::addDebugHeader"
caller: "=Magento[…]BuiltinPlugin::aroundDispatch"
blackfire.io @blackfireio # blackfireio
The metrics
mymetrics.image.operation:
matching_calls:
php:
- callee: "/.*image.*/"
Will match imagecreate, getimagesize etc.
blackfire.io @blackfireio # blackfireio
The recommendations
'The Magento 2 Full Page Cache should be enabled':
assertions:
- 'metrics.magento2.[…]full_page.builtin.hit.count == 1'
exclude:
- '.*/checkout.*'
- '.*/customer/section/load'
- '.*/catalogsearch'
[…]
blackfire.io @blackfireio # blackfireio
The recommendations
'Do not make any image operation':
assertions:
- 'metrics.mymetrics.image.operation.count == 0'
blackfire.io @blackfireio # blackfireio
Put some limits: .blackfire.yml
tests:
Pages should be fast enough:
path: /.*
assertions:
- main.wall_time < 850ms
- main.io < 500ms
- main.cpu_time < 500ms
Pages should not consume too much memory:
path: /.*
assertions:
- main.memory < 50M
- main.peak_memory < 75M
Homepage should not do too many SQL queries:
path: /
assertions:
- metrics.sql.queries.count <= 12
Checkout pages should be light:
path: /checkout/.*
assertions:
- metrics.output.network_out < 100KB
blackfire.io @blackfireio # blackfireio
Scenarios
scenarios:
Home:
- /
Cart:
- /checkout/cart/
Login:
- /customer/account/login/
blackfire.io @blackfireio # blackfireio
Profile Everywhere!

More Related Content

What's hot

Salesforce Partner Program for ISV Partners
Salesforce Partner Program for ISV PartnersSalesforce Partner Program for ISV Partners
Salesforce Partner Program for ISV Partners
Salesforce Partners
 
Turbocharge Your PM Career: Unleashing 5 Game-Changing Tactics
Turbocharge Your PM Career: Unleashing 5 Game-Changing TacticsTurbocharge Your PM Career: Unleashing 5 Game-Changing Tactics
Turbocharge Your PM Career: Unleashing 5 Game-Changing Tactics
Product School
 
From Product Vision to Story Map - Lean / Agile Product shaping
From Product Vision to Story Map - Lean / Agile Product shapingFrom Product Vision to Story Map - Lean / Agile Product shaping
From Product Vision to Story Map - Lean / Agile Product shaping
Jérôme Kehrli
 
The Most Important PM Virtue by Disney SVP of Product
The Most Important PM Virtue by Disney SVP of ProductThe Most Important PM Virtue by Disney SVP of Product
The Most Important PM Virtue by Disney SVP of Product
Product School
 
Headless - the future of e-commerce
Headless - the future of e-commerceHeadless - the future of e-commerce
Headless - the future of e-commerce
Jamie Maria Schouren
 
How to Build a Robust Product Roadmap by Salesforce VP of Product
How to Build a Robust Product Roadmap by Salesforce VP of ProductHow to Build a Robust Product Roadmap by Salesforce VP of Product
How to Build a Robust Product Roadmap by Salesforce VP of Product
Product School
 
How to Create a Product Vision by Dropbox PM
How to Create a Product Vision by Dropbox PMHow to Create a Product Vision by Dropbox PM
How to Create a Product Vision by Dropbox PM
Product School
 
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTOHow to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
Product School
 
The Product Visioning Workshop: A Proven Method for Product Planning and Prio...
The Product Visioning Workshop: A Proven Method for Product Planning and Prio...The Product Visioning Workshop: A Proven Method for Product Planning and Prio...
The Product Visioning Workshop: A Proven Method for Product Planning and Prio...
Perfetti Media
 
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTOHow to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
Product School
 
Sharepoint 2019 Training
Sharepoint 2019 TrainingSharepoint 2019 Training
Sharepoint 2019 Training
Agusto Sipahutar
 
Sharepoint Basics
Sharepoint BasicsSharepoint Basics
Sharepoint Basics
Shervin Thomas
 
Product Owner & Product Manager Training
Product Owner & Product Manager TrainingProduct Owner & Product Manager Training
Product Owner & Product Manager Training
Rob Betcher
 
KPI analytics for saas startups
KPI analytics for saas startupsKPI analytics for saas startups
KPI analytics for saas startups
Artyom Efremov
 
SharePoint Folders & Metadata
SharePoint Folders & MetadataSharePoint Folders & Metadata
SharePoint Folders & Metadata
Drew Madelung
 
Utilizing SharePoint for Project Management
Utilizing SharePoint for Project ManagementUtilizing SharePoint for Project Management
Utilizing SharePoint for Project Management
Gregory Zelfond
 
Product Roadmap
Product RoadmapProduct Roadmap
Product Roadmap
Thang Nguyen
 
Don't Suck at SharePoint - Avoid the common mistakes
Don't Suck at SharePoint - Avoid the common mistakesDon't Suck at SharePoint - Avoid the common mistakes
Don't Suck at SharePoint - Avoid the common mistakes
Benjamin Niaulin
 
Platforms for the Future of Work, Roger Dickey, Gigster
Platforms for the Future of Work, Roger Dickey, GigsterPlatforms for the Future of Work, Roger Dickey, Gigster
Platforms for the Future of Work, Roger Dickey, Gigster
Lean Startup Co.
 
Salesforce CPQ, Orders, Contracts, Amendments and Renewals
Salesforce CPQ, Orders, Contracts, Amendments and RenewalsSalesforce CPQ, Orders, Contracts, Amendments and Renewals
Salesforce CPQ, Orders, Contracts, Amendments and Renewals
Vinay Sail
 

What's hot (20)

Salesforce Partner Program for ISV Partners
Salesforce Partner Program for ISV PartnersSalesforce Partner Program for ISV Partners
Salesforce Partner Program for ISV Partners
 
Turbocharge Your PM Career: Unleashing 5 Game-Changing Tactics
Turbocharge Your PM Career: Unleashing 5 Game-Changing TacticsTurbocharge Your PM Career: Unleashing 5 Game-Changing Tactics
Turbocharge Your PM Career: Unleashing 5 Game-Changing Tactics
 
From Product Vision to Story Map - Lean / Agile Product shaping
From Product Vision to Story Map - Lean / Agile Product shapingFrom Product Vision to Story Map - Lean / Agile Product shaping
From Product Vision to Story Map - Lean / Agile Product shaping
 
The Most Important PM Virtue by Disney SVP of Product
The Most Important PM Virtue by Disney SVP of ProductThe Most Important PM Virtue by Disney SVP of Product
The Most Important PM Virtue by Disney SVP of Product
 
Headless - the future of e-commerce
Headless - the future of e-commerceHeadless - the future of e-commerce
Headless - the future of e-commerce
 
How to Build a Robust Product Roadmap by Salesforce VP of Product
How to Build a Robust Product Roadmap by Salesforce VP of ProductHow to Build a Robust Product Roadmap by Salesforce VP of Product
How to Build a Robust Product Roadmap by Salesforce VP of Product
 
How to Create a Product Vision by Dropbox PM
How to Create a Product Vision by Dropbox PMHow to Create a Product Vision by Dropbox PM
How to Create a Product Vision by Dropbox PM
 
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTOHow to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
 
The Product Visioning Workshop: A Proven Method for Product Planning and Prio...
The Product Visioning Workshop: A Proven Method for Product Planning and Prio...The Product Visioning Workshop: A Proven Method for Product Planning and Prio...
The Product Visioning Workshop: A Proven Method for Product Planning and Prio...
 
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTOHow to Master Product-Led Growth Strategy in B2B by Gainsight CTO
How to Master Product-Led Growth Strategy in B2B by Gainsight CTO
 
Sharepoint 2019 Training
Sharepoint 2019 TrainingSharepoint 2019 Training
Sharepoint 2019 Training
 
Sharepoint Basics
Sharepoint BasicsSharepoint Basics
Sharepoint Basics
 
Product Owner & Product Manager Training
Product Owner & Product Manager TrainingProduct Owner & Product Manager Training
Product Owner & Product Manager Training
 
KPI analytics for saas startups
KPI analytics for saas startupsKPI analytics for saas startups
KPI analytics for saas startups
 
SharePoint Folders & Metadata
SharePoint Folders & MetadataSharePoint Folders & Metadata
SharePoint Folders & Metadata
 
Utilizing SharePoint for Project Management
Utilizing SharePoint for Project ManagementUtilizing SharePoint for Project Management
Utilizing SharePoint for Project Management
 
Product Roadmap
Product RoadmapProduct Roadmap
Product Roadmap
 
Don't Suck at SharePoint - Avoid the common mistakes
Don't Suck at SharePoint - Avoid the common mistakesDon't Suck at SharePoint - Avoid the common mistakes
Don't Suck at SharePoint - Avoid the common mistakes
 
Platforms for the Future of Work, Roger Dickey, Gigster
Platforms for the Future of Work, Roger Dickey, GigsterPlatforms for the Future of Work, Roger Dickey, Gigster
Platforms for the Future of Work, Roger Dickey, Gigster
 
Salesforce CPQ, Orders, Contracts, Amendments and Renewals
Salesforce CPQ, Orders, Contracts, Amendments and RenewalsSalesforce CPQ, Orders, Contracts, Amendments and Renewals
Salesforce CPQ, Orders, Contracts, Amendments and Renewals
 

Similar to Magento 2 performance profiling and best practices

Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best PracticesBodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Meet Magento Italy
 
Pentester++
Pentester++Pentester++
Pentester++
CTruncer
 
Pen Testing Development
Pen Testing DevelopmentPen Testing Development
Pen Testing Development
CTruncer
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
Stanislav Petrov
 
Website & Internet + Performance testing
Website & Internet + Performance testingWebsite & Internet + Performance testing
Website & Internet + Performance testing
Roman Ananev
 
Debugging (Django) application in PyCharm
Debugging (Django) application in PyCharmDebugging (Django) application in PyCharm
Debugging (Django) application in PyCharm
pavelkoci
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
Alessandro Molina
 
Scraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPScraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHP
Paul Redmond
 
The New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by PythonThe New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by Python
All Things Open
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
Lakshman Prasad
 
Create Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGapCreate Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGapSteve Phillips
 
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
 
Fluent 2018: Tracking Performance of the Web with HTTP Archive
Fluent 2018: Tracking Performance of the Web with HTTP ArchiveFluent 2018: Tracking Performance of the Web with HTTP Archive
Fluent 2018: Tracking Performance of the Web with HTTP Archive
Paul Calvano
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Pantheon
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
DECK36
 
Doctrine Project
Doctrine ProjectDoctrine Project
Doctrine Project
Daniel Lima
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability Engineering
Andrew Kirkpatrick
 
20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content
Elad Elrom
 
Performance profiling and testing of symfony application 2
Performance profiling and testing of symfony application 2Performance profiling and testing of symfony application 2
Performance profiling and testing of symfony application 2
Andrew Yatsenko
 

Similar to Magento 2 performance profiling and best practices (20)

Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best PracticesBodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
 
Pentester++
Pentester++Pentester++
Pentester++
 
Pen Testing Development
Pen Testing DevelopmentPen Testing Development
Pen Testing Development
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Website & Internet + Performance testing
Website & Internet + Performance testingWebsite & Internet + Performance testing
Website & Internet + Performance testing
 
Debugging (Django) application in PyCharm
Debugging (Django) application in PyCharmDebugging (Django) application in PyCharm
Debugging (Django) application in PyCharm
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Scraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPScraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHP
 
The New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by PythonThe New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by Python
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
Create Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGapCreate Your First "Native" Mobile App with JavaScript + PhoneGap
Create Your First "Native" Mobile App with JavaScript + PhoneGap
 
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
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Fluent 2018: Tracking Performance of the Web with HTTP Archive
Fluent 2018: Tracking Performance of the Web with HTTP ArchiveFluent 2018: Tracking Performance of the Web with HTTP Archive
Fluent 2018: Tracking Performance of the Web with HTTP Archive
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Doctrine Project
Doctrine ProjectDoctrine Project
Doctrine Project
 
How to get started with Site Reliability Engineering
How to get started with Site Reliability EngineeringHow to get started with Site Reliability Engineering
How to get started with Site Reliability Engineering
 
20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content
 
Performance profiling and testing of symfony application 2
Performance profiling and testing of symfony application 2Performance profiling and testing of symfony application 2
Performance profiling and testing of symfony application 2
 

Recently uploaded

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
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
 
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
 
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
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
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
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
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
 

Recently uploaded (20)

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
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
 
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
 
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
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
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
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
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...
 

Magento 2 performance profiling and best practices

  • 1.
  • 2. You cannot optimize what you cannot measure
  • 3. blackfire.io @blackfireio # blackfireio How to measure PHP code performance ● Microtime ● Benchmarking Libraries ● Application Performance Monitoring ● Load testing ● Profiling https://blackfire.io/docs/24-days/03-what-is-blackfire
  • 5. blackfire.io @blackfireio # blackfireio Understanding the overhead ● Instrumentation ● Tools ready for production vs tools made for development only ● Instrumenting all requests vs specific requests
  • 6. blackfire.io @blackfireio # blackfireio Profiling is about measuring how much resources your code is consuming Wall time I/O CPU Memory Network SQLHTTP Time https://blackfire.io/docs/24-days/07-time-flavors
  • 7. blackfire.io @blackfireio # blackfireio Time is volatile ● Time is not a stable metric. External factors such as machine load can have significant impacts on wall time between two profiles of identical code. ● Time is just a consequence of what happened in the code ● Use time to identify the slow parts in your code and then: ○ iterate and compare ○ write assertions on the root cause ● Profiling is about understanding how code works at runtime https://blackfire.io/docs/24-days/12-tests-best-pratices
  • 8. blackfire.io @blackfireio # blackfireio Callgraphs, timelines and more ● Find the function calls that consume the most resources ● Know where to stop optimizing ● Trade-off time vs memory and performance vs code complexity ● Profiling should not always be a lonely activity
  • 9. blackfire.io @blackfireio #blackfireio What are the issues we encounter with Magento 2
  • 10. You cannot optimize what you cannot measure
  • 11. You cannot measure what you don’t execute.
  • 12. blackfire.io @blackfireio # blackfireio Varnish, can you ignore me? acl profile { # Allowed IP "111.112.113.114"; } sub vcl_recv { if (req.http.X-Blackfire-Query && client.ip ~ profile) { if (req.esi_level > 0) { unset req.http.X-Blackfire-Query; } else { return (pass); } } }
  • 13. blackfire.io @blackfireio # blackfireio What about the Full Page Cache? And all the others.
  • 14. blackfire.io @blackfireio # blackfireio You have to compare.
  • 15. blackfire.io @blackfireio # blackfireio The main issues ● SQL Queries ● Network ● CPU Time ● Memory ● I/O Wait ● External HTTP requests ● PHP & Bad PHP code
  • 16. blackfire.io @blackfireio # blackfireio SQL Queries ● Use indexes and correct types. ● Limit the number of results you need. ● Avoid SQL requests… ● If you can’t avoid them, cache the output or use LocalStorage/CacheStorage if insensitive information. ● Use Magento Repositories. SQL Requests are the main issue.
  • 17. blackfire.io @blackfireio # blackfireio ● Use local networks with local IP addresses. Network
  • 18. blackfire.io @blackfireio # blackfireio CPU Time ● Avoid consuming operations: loops, events… ● Use Magento Repositories. ● KISS : Keep It Simple Stupid.
  • 19. blackfire.io @blackfireio # blackfireio Memory ● Use the MagentoFrameworkModelResourceModelIterator for your loops. ● Use PHP! Avoid creating so many objects when you can do the operation with one function call. ● Use the Magento Dependency Injection. ● Use Magento Repositories.
  • 20. blackfire.io @blackfireio # blackfireio I/O Wait ● Use php://memory and php://temp. Because Memory is always faster than I/O. ● Optimize composer: composer dump-autoload --optimize --no-dev
  • 21. blackfire.io @blackfireio # blackfireio External HTTP Requests ● Don’t do that. ● If you really have to: use RabbitMQ. ● And if you really have no choice: use asynchronous? ● And if you really really have no choice: use a small timeout and deal with the errors properly.
  • 22. blackfire.io @blackfireio # blackfireio PHP & Bad PHP code
  • 23. blackfire.io @blackfireio # blackfireio PHP & Bad PHP code ● Upgrade to the latest version of PHP. ● Prefer a PHP core function to a lot of objects and methods. ●
  • 25. blackfire.io @blackfireio # blackfireio The metrics ● Is Magento 2 installed? CE or EE? ● Is the cache enabled? ● Cache manipulation. ● Product loads. ● Interceptors measurement. ● Mode detector: production/developer/default. ● …
  • 26. blackfire.io @blackfireio # blackfireio The metrics magento2.all.cache.full_page.builtin.hit: label: "Hit full page cache using builtin" matching_calls: php: - callee: "=Magento[…]BuiltinPlugin::addDebugHeader" caller: "=Magento[…]BuiltinPlugin::aroundDispatch"
  • 27. blackfire.io @blackfireio # blackfireio The metrics mymetrics.image.operation: matching_calls: php: - callee: "/.*image.*/" Will match imagecreate, getimagesize etc.
  • 28. blackfire.io @blackfireio # blackfireio The recommendations 'The Magento 2 Full Page Cache should be enabled': assertions: - 'metrics.magento2.[…]full_page.builtin.hit.count == 1' exclude: - '.*/checkout.*' - '.*/customer/section/load' - '.*/catalogsearch' […]
  • 29. blackfire.io @blackfireio # blackfireio The recommendations 'Do not make any image operation': assertions: - 'metrics.mymetrics.image.operation.count == 0'
  • 30. blackfire.io @blackfireio # blackfireio Put some limits: .blackfire.yml tests: Pages should be fast enough: path: /.* assertions: - main.wall_time < 850ms - main.io < 500ms - main.cpu_time < 500ms Pages should not consume too much memory: path: /.* assertions: - main.memory < 50M - main.peak_memory < 75M Homepage should not do too many SQL queries: path: / assertions: - metrics.sql.queries.count <= 12 Checkout pages should be light: path: /checkout/.* assertions: - metrics.output.network_out < 100KB
  • 31. blackfire.io @blackfireio # blackfireio Scenarios scenarios: Home: - / Cart: - /checkout/cart/ Login: - /customer/account/login/
  • 32. blackfire.io @blackfireio # blackfireio Profile Everywhere!