PHP and MySQL related performance issues can be hard to track down.
Luckily, Magento 2 comes with its own profiler to help you do this.
The built-in profiler should only be used on a Staging account since it has an impact on performance and it shows debugging information on the pages of your webshop.
Below are the steps to enable the profiler and track down issues:
- Make sure your code on Staging is in sync with production
- Make sure your database on Staging is in sync with production
- Reproduce the issue on staging, for example go to a slow page. To make sure you don't hit Varnish add
?no_cache=1to the end of the URL.
- Use SSH to go to the Magento 2 directory and execute:
bin/magento dev:profiler:enable html
- Hit the page where the problem persists again
- Scroll to the bottom of the page, there is a table with load times
- Find the element with the highest value in the 'Time' column
- You will now have a good indication where the most time is spent
- To disable the profiler: Use SSH to go to the Magento 2 directory and run: