SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
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
Profile Everywhere!

Contenu connexe

Tendances

Tendances (20)

Common Traits of High Performing Websites, WebPerfDays Amsterdam 07-Nov-2018
Common Traits of High Performing Websites, WebPerfDays Amsterdam 07-Nov-2018Common Traits of High Performing Websites, WebPerfDays Amsterdam 07-Nov-2018
Common Traits of High Performing Websites, WebPerfDays Amsterdam 07-Nov-2018
 
Headless CMS for Digital Agencies - Case Study by Andy Thompson
Headless CMS for Digital Agencies - Case Study by Andy ThompsonHeadless CMS for Digital Agencies - Case Study by Andy Thompson
Headless CMS for Digital Agencies - Case Study by Andy Thompson
 
Hyvä from a developer perspective
Hyvä from a developer perspectiveHyvä from a developer perspective
Hyvä from a developer perspective
 
How to design a good REST API: Tools, techniques and best practices
How to design a good REST API: Tools, techniques and best practicesHow to design a good REST API: Tools, techniques and best practices
How to design a good REST API: Tools, techniques and best practices
 
WordPress + react
WordPress + reactWordPress + react
WordPress + react
 
The Next Generation Software Stack: Meteor
The Next Generation Software Stack: MeteorThe Next Generation Software Stack: Meteor
The Next Generation Software Stack: Meteor
 
Website Development Using a Headless CMS - Sean Lamacraft, Distinction
Website Development Using a Headless CMS - Sean Lamacraft, DistinctionWebsite Development Using a Headless CMS - Sean Lamacraft, Distinction
Website Development Using a Headless CMS - Sean Lamacraft, Distinction
 
Easy Decoupled Sitebuilding with GraphQL and Next.js
Easy Decoupled Sitebuilding with GraphQL and Next.jsEasy Decoupled Sitebuilding with GraphQL and Next.js
Easy Decoupled Sitebuilding with GraphQL and Next.js
 
TRAX technical highlights
TRAX technical highlightsTRAX technical highlights
TRAX technical highlights
 
Serverless with Firebase - Launchpad Build Burgos
Serverless with Firebase - Launchpad Build Burgos Serverless with Firebase - Launchpad Build Burgos
Serverless with Firebase - Launchpad Build Burgos
 
Design Patterns for Smart Applications
Design Patterns for Smart ApplicationsDesign Patterns for Smart Applications
Design Patterns for Smart Applications
 
Jade: Open Source Case Management for SME Law Firms (Oct 2017)
Jade: Open Source Case Management  for SME Law Firms (Oct 2017)Jade: Open Source Case Management  for SME Law Firms (Oct 2017)
Jade: Open Source Case Management for SME Law Firms (Oct 2017)
 
Nitrodroid 2013 | Building your first Android App on PhoneGap
Nitrodroid 2013 | Building your first Android App on PhoneGapNitrodroid 2013 | Building your first Android App on PhoneGap
Nitrodroid 2013 | Building your first Android App on PhoneGap
 
Using PHP with IBM Bluemix
Using PHP with IBM BluemixUsing PHP with IBM Bluemix
Using PHP with IBM Bluemix
 
Next.js vs React | what to choose for frontend development_
Next.js vs React | what to choose for frontend development_Next.js vs React | what to choose for frontend development_
Next.js vs React | what to choose for frontend development_
 
Outlook on Magento 2
Outlook on Magento 2Outlook on Magento 2
Outlook on Magento 2
 
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and CompositionsLightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
Lightning Web Components- Ep 1 - Decorators, Life Cycle Hooks and Compositions
 
Django Deployer
Django DeployerDjango Deployer
Django Deployer
 
Write Serverless Applications with PowerShell and Azure Functions
Write Serverless Applications with PowerShell and Azure FunctionsWrite Serverless Applications with PowerShell and Azure Functions
Write Serverless Applications with PowerShell and Azure Functions
 
WebPros at CloudFest 2022 - Walk the New Revenue Avenues of Server Management
WebPros at CloudFest 2022 - Walk the New Revenue Avenues of Server ManagementWebPros at CloudFest 2022 - Walk the New Revenue Avenues of Server Management
WebPros at CloudFest 2022 - Walk the New Revenue Avenues of Server Management
 

Similaire à Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices

Similaire à Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices (20)

Magento 2 performance profiling and best practices
Magento 2 performance profiling and best practicesMagento 2 performance profiling and best practices
Magento 2 performance profiling and best practices
 
Pentester++
Pentester++Pentester++
Pentester++
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Pen Testing Development
Pen Testing DevelopmentPen Testing Development
Pen Testing Development
 
Debugging (Django) application in PyCharm
Debugging (Django) application in PyCharmDebugging (Django) application in PyCharm
Debugging (Django) application in PyCharm
 
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
 
Website & Internet + Performance testing
Website & Internet + Performance testingWebsite & Internet + Performance testing
Website & Internet + Performance testing
 
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
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
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
 
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...
 
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
 
Workshop: Introduction to Web Components & Polymer
Workshop: Introduction to Web Components & Polymer Workshop: Introduction to Web Components & Polymer
Workshop: Introduction to Web Components & Polymer
 
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
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Hacking Vulnerable Websites to Bypass Firewalls
Hacking Vulnerable Websites to Bypass FirewallsHacking Vulnerable Websites to Bypass Firewalls
Hacking Vulnerable Websites to Bypass Firewalls
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
More about PHP
More about PHPMore about PHP
More about PHP
 

Plus de Meet Magento Italy

Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Meet Magento Italy
 

Plus de Meet Magento Italy (20)

Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
 
Vinai Kopp - How i develop M2 modules
Vinai Kopp - How i develop M2 modules Vinai Kopp - How i develop M2 modules
Vinai Kopp - How i develop M2 modules
 
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum PerformanceEugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
 
Muliadi jeo - How to sell online in Indonesia
Muliadi jeo - How to sell online in IndonesiaMuliadi jeo - How to sell online in Indonesia
Muliadi jeo - How to sell online in Indonesia
 
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
 
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
 
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
 
Vinai Kopp - FPC Hole punching in Magento 2
Vinai Kopp - FPC Hole punching in Magento 2Vinai Kopp - FPC Hole punching in Magento 2
Vinai Kopp - FPC Hole punching in Magento 2
 
Talesh Seeparsan - The Hound of the Malwarevilles
Talesh Seeparsan - The Hound of the MalwarevillesTalesh Seeparsan - The Hound of the Malwarevilles
Talesh Seeparsan - The Hound of the Malwarevilles
 
Miguel Balparda - A day in support
Miguel Balparda - A day in supportMiguel Balparda - A day in support
Miguel Balparda - A day in support
 
Rosario Toscano - Processi di ottimizzazione per una crescita continua
Rosario Toscano - Processi di ottimizzazione per una crescita continuaRosario Toscano - Processi di ottimizzazione per una crescita continua
Rosario Toscano - Processi di ottimizzazione per una crescita continua
 
Henrik Feld Jakobsen - How to sell online Scandinavia
Henrik Feld Jakobsen - How to sell online ScandinaviaHenrik Feld Jakobsen - How to sell online Scandinavia
Henrik Feld Jakobsen - How to sell online Scandinavia
 
Rabia Qureshi - How to sell online in UK
Rabia Qureshi - How to sell online in UKRabia Qureshi - How to sell online in UK
Rabia Qureshi - How to sell online in UK
 
Matteo Schuerch - How to sell online in Switzerland
Matteo Schuerch - How to sell online in SwitzerlandMatteo Schuerch - How to sell online in Switzerland
Matteo Schuerch - How to sell online in Switzerland
 
Il data-driven nell’e-commerce: il caso studio Alessi
Il data-driven nell’e-commerce: il caso studio AlessiIl data-driven nell’e-commerce: il caso studio Alessi
Il data-driven nell’e-commerce: il caso studio Alessi
 
Philippe Bernou - Seamless omnichannel solutions with Magento order management
Philippe Bernou - Seamless omnichannel solutions with Magento order managementPhilippe Bernou - Seamless omnichannel solutions with Magento order management
Philippe Bernou - Seamless omnichannel solutions with Magento order management
 
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
 
Alan Rhode - GDPR: la nuova normativa privacy per l’Europa
Alan Rhode - GDPR: la nuova normativa privacy per l’EuropaAlan Rhode - GDPR: la nuova normativa privacy per l’Europa
Alan Rhode - GDPR: la nuova normativa privacy per l’Europa
 
Michele Simone - Come incrementare il tuo business con PayPal
Michele Simone - Come incrementare il tuo business con PayPalMichele Simone - Come incrementare il tuo business con PayPal
Michele Simone - Come incrementare il tuo business con PayPal
 
Lydia Schaffranek - Meet Magento Association
Lydia Schaffranek - Meet Magento AssociationLydia Schaffranek - Meet Magento Association
Lydia Schaffranek - Meet Magento Association
 

Dernier

Dernier (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Bodin - Hullin & Potencier - Magento 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 Profile Everywhere!