Magento 2.1 – Resolve Performance Issues

magento-2.1pagespeedslowbackend

I am testing my website on "https://developers.google.com/speed/pagespeed/insights/" and have only low ratings (9-12/100).

My Setup:

Virtual Server (CentOS) with 16 GB RAM, 6 cores (Intel Xeon), SSD
Storage Magento 2.1.7 Apache 2.4.6
MariaDB 10.1

I made sure to have 14GB RAM in my php.ini (memory_limit = 14000M).

Also edited .htaccess and .user.ini in magento root directory and pub directory (all have 14 GB RAM).

My configuration file for MariaDB (/etc/my.cnf) looks like this:

[client] port = 3306 socket =
/var/lib/mysql/mysql.sock

[mysqld] port = 3306 socket =
/var/lib/mysql/mysql.sock skip-external-locking key_buffer_size =
384M max_allowed_packet = 10M
table_open_cache = 4096 sort_buffer_size = 16M
read_buffer_size = 4M read_rnd_buffer_size = 14M
myisam_sort_buffer_size = 64M thread_cache_size = 256

query_cache_type = 1 query_cache_limit = 4M

query_cache_size = 512M thread_concurrency = 8

log-bin=mysql-bin server-id = 1 innodb_buffer_pool_size = 3000M
innodb_additional_mem_pool_size = 80M

[mysqldump] quick max_allowed_packet = 512M

[mysql] no-auto-rehash

[myisamchk] key_buffer_size = 256M
sort_buffer_size = 256M read_buffer = 4M
write_buffer = 4M

[mysqlhotcopy] interactive-timeout

I don't know why my website is still so slow (server response is always 1-2.5 seconds according to google pagespeed), even though my hardware is good enough (enough RAM).

PS: My magento mode is developer and all css js minify and merge options are off.

Best Answer

Reason for Slow

  1. It is in developer mode with CSS/JS merge/bundle/minify enabled.
  2. It is running on slow hardware.
  3. Some 3rd party extension breaks performance.
  4. SSD not used.
  5. 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
Related Topic