First determine if it's front end rendering or the actual script execution that is slow. Check with the developer console in your browser for the Time To First Byte. This is how long the script take to process on the server
In the screenshot you can see it's quite low (200ms) so in this case the problem wouldn't be on the server but on front end. Now if it's over, let's say, a second you might want to optimize.
Before you slap on some boosters and extra caching which isn't a fix just a patch or band aid to hide the real issue try to figure out what exactly is slow. You can use several tools also for that.
Slow queries
Magento can be quite heavy on the database so turning on the Slow Query Log might be a good place to start. Check out this post on how to turn it on. The log will show you any query that takes longer than X seconds.
Profilers
Profilers help you gain insight into whats going on in your code. For Magento I would recommend starting with Aoe_Profiler. Just install it and turn it on. On the front end it'll give you an output like this:
Expand the results and check for large red blocks. Those are the actual times it took a certain part of the code to process. Look out for any 3rd party modules that are taking up a lot of time or memory.
Another great tool is Black fire. Since Aoe_Profiler is a module in Magento it doesn't show the underlying php processes and can crash on large installations with a lot of modules. Black fire runs on the server.
With a hackathon we set up a Vagrant box with black fire you can use. Just put your project on there and fire it up. Check the Black fire site for more info how to use it.
Last one is probably my favorite: New Relic.
Unfortunately it's a paid service although they provide a free trial for pro accounts. After installing it on your server and connecting the profile wait a couple of hours for data to come in. Make sure there is some traffic on the shop tho.
New Relic also has a blog post on how to debug Magento which I can recommend. Also check out the ProxiBlue New Relic module for extra Magento data in New Relic.
Basically this will show you all of the above described features like slow queries, the processes in PHP etc and display it in easy graphs and tables. This should give you great insight in what is the issue in your installation.
And from here
Now that you know what is causing the low performance you can move on to solving it. Check forums like this one or Google for the part or module of Magento that is slow. A lot of issues are well known and others have solved it before. Or, if you can't find a solution post your question here and include your findings in the question
Reason for Slow
- It is in developer mode with CSS/JS merge/bundle/minify enabled.
- It is running on slow hardware.
- Some 3rd party extension breaks performance.
- SSD not used.
- Full page cache and other caches are turned off.
PS: Here is how to find out what M2 mode you are in:
cd magento_main_folder
php bin/magento deploy:mode:show
When you are in Developer Mode
This mode is needed when you are just getting your site ready for production. But wait time of 30s could be very frustrating and annoying.Here is 3 simple fixes you could try to speed up magento2:
1. Disable CSS & JS merge / bundle / minify
That trick alone helped me reduce speed from 50s down to 2s.
Go to Stores > Configuration > Advanced > Developer > Javascript Settings and CSS Settings
2. Move to PHP7 While magento 2 works great on php 5.6 a move to php7 alone can improve performance by 25%.
3. Server resources Magento 2 is a complex system. Especially in developer mode it requires powerful hardware.Avoid virtualization. Make sure you allocate at least 2G of RAM to M2.
When you are in production mode
1. Audit your 3rd party extensions Magento 2 is greatly extendable with plugins and modules. But unlike core functionality that was coded by Magento Core Team and experts 3rd party extensions are developed ( in most cases ) by average programmers. With average skills. One poorly written module could slow magento down big time.Get a list of all plugins you installed and disable them one by one. See if it affects performance in any way. Identify a bottleneck and contact vendor for assistance.Go ahead and install a fresh Magento 2 with sample data on the same server. Compare its speed to your production site. If a default M2 is as slow as your customized magento store then go to step 2. If it is significantly faster then you know you have an extension that slows you down.
2. Server hardware makes magento 2 slow You can simply find it out if you install a fresh M2 on the same server and compare its performance to your production site. If you don't see a difference then obviously your hosting plan is not suitable for magento2. Sign up for better hosting and secure more CPU/RAM power. Don't be cheap here!
3. Make sure full page cache is on
System > Cache Management
Best Answer
I see you tagged LiteSpeed, are you using LiteSpeed web server? If yes, you can take advantage of LiteMage cache to replace Magento built-in cache. The LiteMage starter option has no extra cost. Many LiteSpeed users are using this solution for their Magento 2 stores and are very happy with the results.