本文转自:https://magedirect.co/how-to-speed-up-magento-2-maximum-performance/

Introduction

In this article, we’ll show you how to run a Magento 2 store at maximum speed. We will review the most popular techniques that you can quickly implement today.

So, let’s imagine the situation:

  • You are preparing for big sales and the development team is making final edits in the code.
  • You are not happy with the current performance of your store on Magento 2 and want to finally get it over with, and to speed up it.
  • You have many products and categories, and the store is slow

If you find your situation with this line, then read on.

1. Preliminary preparation of the test store

Let’s create a real situation, and simulate a large store with a huge amount of products.

Thanks to the Magento 2 developers, they took care of the fact that we were able to generate a set of test products. To do this, Magento 2 has a data generator that allows you to generate a large amount of data (products, websites, categories, customers, order, etc)

More detailed instructions can be found in the official documentation:

http://devdocs.magento.com/guides/v2.2/config-guide/cli/config-cli-subcommands-perf-data.html

So we begin the fun:

Install the fresh Magento 2 on the server and load the test data into the Magento.

In this example, we will use one server for the application and the database.

We use dedicated server – DELL PowerEdge ™ R730 DX151 with the following characteristics:

CPU(s): 16

Model name: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz

CPU MHz: 1200.281

L3 cache: 20480K

Memory: 64 GB

For speeding up the highload store, we will install the following software which is recommended by Magento Team:

  • Mysql
  • Nginx
  • php7-fpm
  • Redis
  • Varnish

Next, we will configure Cache Settings:

We will use the Varnish as Caching Application

Let’s enable Varnish in Magento 2 admin panel

Stores -> Configuration -> Advanced -> System -> Full Page Cache and select next settings:

Then we will enable Redis as default cache (default array) and the full page cache.

For default settings add next records in your  app/etc/env.php

 
 
 
 
 
 

PHP

 
 array (    'frontend' =>    array (      'default' =>      array (        'backend' => 'Cm_Cache_Backend_Redis',        'backend_options' =>        array (          'server' => '127.0.0.1',          'port' => '6379',          'persistent' => '',          'database' => '0',          'force_standalone' => '0',          'connect_retries' => '1',          'read_timeout' => '10',          'automatic_cleaning_factor' => '0',          'compress_data' => '1',          'compress_tags' => '1',          'compress_threshold' => '20480',          'compression_lib' => 'gzip',        ),      ),      'page_cache' =>      array (        'backend' => 'Cm_Cache_Backend_Redis',        'backend_options' =>        array (          'server' => '127.0.0.1',          'port' => '6379',          'persistent' => '',          'database' => '1',          'force_standalone' => '0',          'connect_retries' => '1',          'read_timeout' => '10',          'automatic_cleaning_factor' => '0',          'compress_data' => '0',          'compress_tags' => '1',          'compress_threshold' => '20480',          'compression_lib' => 'gzip',        ),      ),    ),  ),
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 array (
 
   'frontend' =>
 
   array (
 
     'default' =>
 
     array (
 
       'backend' => 'Cm_Cache_Backend_Redis',
 
       'backend_options' =>
 
       array (
 
         'server' => '127.0.0.1',
 
         'port' => '6379',
 
         'persistent' => '',
 
         'database' => '0',
 
         'force_standalone' => '0',
 
         'connect_retries' => '1',
 
         'read_timeout' => '10',
 
         'automatic_cleaning_factor' => '0',
 
         'compress_data' => '1',
 
         'compress_tags' => '1',
 
         'compress_threshold' => '20480',
 
         'compression_lib' => 'gzip',
 
       ),
 
     ),
 
     'page_cache' =>
 
     array (
 
       'backend' => 'Cm_Cache_Backend_Redis',
 
       'backend_options' =>
 
       array (
 
         'server' => '127.0.0.1',
 
         'port' => '6379',
 
         'persistent' => '',
 
         'database' => '1',
 
         'force_standalone' => '0',
 
         'connect_retries' => '1',
 
         'read_timeout' => '10',
 
         'automatic_cleaning_factor' => '0',
 
         'compress_data' => '0',
 
         'compress_tags' => '1',
 
         'compress_threshold' => '20480',
 
         'compression_lib' => 'gzip',
 
       ),
 
     ),
 
   ),
 
 ),

2. Generate test data for our store

We will use generated data from Magento 2. More details you can find here:

http://devdocs.magento.com/guides/v2.2/config-guide/cli/config-cli-subcommands-perf-data.html

We use so-called “Large profile”

It is:

 Name Value
website 5
store group 5
store views 5
simple products 300,000
configurable_products 8,000 with 24 options
categories 3000
categories_nesting_level 5
catalog_price_rules 20
catalog_target_rules 5
cart_price_rules 20
cart_price_rules_floor 2
customers 5000
tax rates 40,000
orders 100,000

Start the generation with the command:

 
 
 
 
 
 

Shell

 
bin/magento setup:perf:generate-fixtures /var/www/html/magento2/setup/performance-toolkit/profiles/ce/large.xml
1
bin/magento setup:perf:generate-fixtures /var/www/html/magento2/setup/performance-toolkit/profiles/ce/large.xml

The execution of this script takes time. If you do a similar job, we advise you to set enough memory for PHP or only personally to the given script with the help of the directive “memory_limit”. For example:

 
 
 
 
 
 

Shell

 
php -d="memory_limit=-1" setup:perf:generate-fixtures /var/www/html/magento2/setup/performance-toolkit/profiles/ce/large.xml
1
php -d="memory_limit=-1" setup:perf:generate-fixtures /var/www/html/magento2/setup/performance-toolkit/profiles/ce/large.xml

In this example, we set up unlimited memory for php processes.

After the script is executed in our store, we load all the test data we need to check the performance. Let’s open some test category.

Cool! The store is filled with test data. Check the administrative panel.

Products:

Orders:

A lot of categories:

Customers:

3. Let’s setup Magento for high-load

Now we will show you the most priority and simplest actions to speed up your store and to turn into a high-performance mode.

Step 1. Enable production mode
Let’s enable Magento 2 in the combat mode so that your Magento works in high-efficiency mode. For this, you need to enable production mode.

Magento 2 has different modes:

Run the following command:

 
 
 
 
 
 

Shell

 
magento deploy:mode:set production
1
magento deploy:mode:set production

Check:

 
 
 
 
 
 

Shell

 
magento deploy:mode:show
1
magento deploy:mode:show

You should see the next output:

Current application mode: production. (Note: Environment variables may override this value.)

Then run the command

 
 
 
 
 
 

Shell

 
php bin/magento setup:di:compile
1
php bin/magento setup:di:compile

This will then re-compile the files. Lastly:

 
 
 
 
 
 

Shell

 
php bin/magento setup:static-content:deploy
1
php bin/magento setup:static-content:deploy

If Magento has enabled maintenance mode – disable maintenance mode by the command:

 
 
 
 
 
 

Shell

 
./bin/magento maintenance:disable
1
./bin/magento maintenance:disable

Step 2. Enable Cache

We enable all cache types in the administrative panel in the section System -> Cache Management

Step 3. Flat Catalog

Let’s Enable Flat Catalog. With this setting, Magento 2 will make less complex MySQL queries in the database.

Don’t forget to clear configuration cache after this action.

Step 4. Merge & Minify CSS and JS Files

Further, we include the minification and Merge in Store -> Configuration -> Developer

Enable Merge CSS and JS Files, Minify  CSS & JS. It will speed up the loading of CSS and JS

Step 5. Tune Server Configuration

Let’s show the most needed configurations for a store with a high load:

Mysql (config file: my.cnf)

The max_allowed_packet directive is chosen empirically to avoid the error “General error: 2006 MySQL server has gone away”. By studying the MySQL logs, you will be able to determine what size of packages your database needs.

For this amount of data we will use:

 
 
 
 
 
 

PHP

 
max_allowed_packet = 32M
1
max_allowed_packet = 32M

The directives  tmp_table_size and max_heap_table_size are chosen experimentally. With the default value of Magento, many temporary tables will be created. It is defined using the command:

 
 
 
 
 
 

Shell

 
show global status LIKE 'Created_tmp_disk_tables';
1
show global status LIKE 'Created_tmp_disk_tables';

For this demo store we use:

 
 
 
 
 
 

Shell

 
tmp_table_size = 128M max_heap_table_size = 128M
1
2
tmp_table_size = 128M
max_heap_table_size = 128M

The innodb_buffer_pool_size directive is set relative to the amount of RAM. The recommended value is 70-80%.

For our server this value is:

 
 
 
 
 
 

Shell

 
innodb_buffer_pool_size = 48G
1
innodb_buffer_pool_size = 48G

PHP (config file .php.ini)

The RAM limit must be at least 1G

 
 
 
 
 
 

Shell

 
memory_limit=1G
1
memory_limit=1G

For cron jobs we personally set at least 4GB

 
 
 
 
 
 

Shell

 
* * * * * /usr/bin/php -d=”memory_limit=”4000M” /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log * * * * * /usr/bin/php -d=”memory_limit=”4000M /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log * * * * * /usr/bin/php -d=”memory_limit=”4000M /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log
1
2
3
4
5
* * * * * /usr/bin/php -d=”memory_limit=”4000M” /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
 
* * * * * /usr/bin/php -d=”memory_limit=”4000M /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
 
* * * * * /usr/bin/php -d=”memory_limit=”4000M /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log

Note:

– Reindex requires more RAM on so many products, if 4GB is not enough for you – try using the bigger value.

– reindex on so many products is performed for a long time, so it’s better to set the reindex mode “update on save”

Step 6. Enable Gzip Compression

Turn on gzip compression in the nginx config:

 
 
 
 
 
 

Shell

 
gzip on; gzip_disable "msie6"; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_proxied any; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml; gzip_vary on;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
gzip on;
 
gzip_disable "msie6";
 
gzip_comp_level 6;
 
gzip_min_length 1100;
 
gzip_buffers 16 8k;
 
gzip_proxied any;
 
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+rss
    image/svg+xml;
 
gzip_vary on;

Step 7. Optimize Images.

There are different strategies for optimizing images. You can use third-party extensions or optimize before upload images to Magento. In this article, we use a simple script that uses open-source Linux libraries.

Just install next software:

 
 
 
 
 
 

Shell

 
apt-get install optipng apt-get install jpegoptim apt-get install gifsicle
1
2
3
apt-get install optipng
apt-get install jpegoptim
apt-get install gifsicle
 
 
 
 
 
 

Shell

 
#!/bin/bash find ./media -iname '*.gif' -exec sh -c 'gifsicle -b -O3 -o "{}.out" "{}"; mv "{}.out" "{}"' \; find ./media -iname '*.png' -exec optipng -o5 -keep -preserve '{}' \; find ./media -type f -iname '*jpg' -exec sh -c 'jpegtran -outfile "{}.out" -optimize "{}"; mv "{}.out" "{}"' \;
1
2
3
4
5
6
7
#!/bin/bash
 
find ./media -iname '*.gif' -exec sh -c 'gifsicle -b -O3 -o "{}.out" "{}"; mv "{}.out" "{}"' \;
 
find ./media -iname '*.png' -exec optipng -o5 -keep -preserve '{}' \;
 
find ./media -type f -iname '*jpg' -exec sh -c 'jpegtran -outfile "{}.out" -optimize "{}"; mv "{}.out" "{}"' \;

4. Let’s make final performance tests

Preliminary information:

1) We made a basic tuning Magento 2. It can be done even better personally under the store.

2) The pages for which we do Magento site speed test, we open in the browser before. That would get the page in the Varnish cache, it said “warmed up.” Because on this demo site we do not have a module for cache warmer and there are no more users who “warm up” the site.

3) In this article, we will not discuss the optimization of render-blocking JavaScript and CSS and JS minifications.

We think that a good mark for the store is 70+. A real store can have many different external scripts (chat rooms, analytics, marketing tools, etc). They all influence Google PageSpeed Insight.

Testing Magento speed (site load time) is necessary. Speed is an important metric in SEO, and also affects the user experience.
When a Googlebot indexes a site, it does not see the PageSpeed indicator, but only knows the speed itself.

Did you know that Google PageSpeed Insights does not measure the speed of your site? Read more detailed:

Google PageSpeed Insights does not measure the speed of the site.

To measure the download speed, you can use GTMetrix or Pingdom Tools.

From our point of view, there is no point in scrolling for Google PageSpeed indicators. The main speed of the store, as this affects the behavioral factor, it is very important for SEO.

Let’s look at the results of Google PageSpeed

1) Google PageSpeed Insight

Category page:

Product Page:

Configurable Product

2) Pingdom

Location: Stockholm, Sweden

Speed of category page:

Speed of product page (configurable product):

5. Additional steps that you can use for performance optimization.

  • CDN
  • Cache Warmer
  • Nginx professional tuning
  • Docker Container & Kubernetes
  • image optimization

All these methods we will consider in our next articles and we will reveal each method of Magento Speed Optimization in more details.

Thank you for your attention. Hope that now you understand how to speed up Magento site. Keep up with our new performance workshops!

Valentyn KubrakChief Operating Officer

[转]How to speed up Magento 2. Maximum Performance的更多相关文章

  1. Website Speed Optimization Guide for Google PageSpeed Rules

    原链接地址:http://www.artzstudio.com/2016/07/website-speed-optimization-guide-for-google-pagespeed-rules/ ...

  2. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  3. DotNet 资源大全中文版(Awesome最新版)

    Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...

  4. sysbench 压力测试

    200 ? "200px" : this.width)!important;} --> 介绍 sysbench是一个模块化.跨平台.多线程基准测试工具,主要用于测试不同系统参 ...

  5. sysbench的安装与使用(with MySQL)

    sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试. 项目主页: http://sysbench.sourceforge.net/ 安装文档htt ...

  6. sysbench压力测试工具简介和使用(一)

    sysbench压力测试工具安装和参数介绍 一.sysbench压力测试工具简介: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据 ...

  7. nginx调优

    Nginx is an open-source Web Server. It is a high-performance HTTP server that uses very low server r ...

  8. Temporary Segments: What Happens When a Sort Occurs (文档 ID 102339.1)

    APPLIES TO: Oracle Database - Enterprise Edition - Version 8.1.7.4 to 11.2.0.1 [Release 8.1.7 to 11. ...

  9. 【MySQL】Sysbench性能测试

    两台MySQL配置不一样,要测试下性能差别 [m1] long_query_time = 0.1 log_slave_updates innodb_flush_log_at_trx_commit [m ...

随机推荐

  1. HMAILSERVER集成WEB邮件系统(ROUNDCUBE WEBMAIL)

    hMailServer集成web邮件系统(Roundcube Webmail) 文/玄魂 前言 在上篇文章(使用hMailServer搭建邮件服务器)中,介绍了hMailServer的安装和简单配置. ...

  2. 【WEB前端】CSS书写规范

    古语有云:不以规矩,不成方圆.不管是国还是家还是...都得有规矩加以约束.同样,在我们程序猿的代码中也有一定的规矩——W3C标准,但是我今天不会讲那么高深的道理,我只想说说,我近些日子在开发中所总结出 ...

  3. 使用C#写MVC框架(一:核心原理)

    目录: 一.MVC原理解析 二.HttpHandler 1.HttpHandler,IHttpHandler,MvcHandler的说明 2.IHttpHandler解析 3.MvcHandler解析 ...

  4. solr 下载 有dist目录的(6需要8)

    http://archive.apache.org/dist/lucene/solr/ solr6 需要java8

  5. is和 == 的区别以及编码.解码

    一.is和==的区别 1,id( ) id( )是python的一个内置函数,通过id( )我们可以查看到一个变量表的值在内存中的地址: s = 2 print(id(s)) # 1514368064 ...

  6. sublime text 文件打开时回调一些函数

    需求:公司服务端脚本以 .s 结尾的文件,也按 js 语法识别,方便查看函数定义. 每次都 ss:js 比较麻烦,所以写个插件. import sublime, sublime_plugin clas ...

  7. Liferay-Activiti 功能介绍 (新版Liferay7基本特性)

    一句话简介 Liferay是世界领先的开源企业门户(也可作为综合门户),是最强大(没有之一)的JAVA开源门户,在Gartner和Forrester和评价非常高,近几年已经超越了微软门户Sharepo ...

  8. postgresql和redis

    redis 和postgresql区别以及其优缺点 一刹那者为一念,二十念为一瞬,二十瞬为一弹指,二十弹指为一罗预,二十罗预为一须臾,一日一夜有三十须臾. 那么,经过周密的计算,一瞬间为0.36 秒, ...

  9. Jmeter保存时,完美解决提示的“拒绝访问”

    使用Jmeter时,想保存测试计划,提示"拒绝访问“,这是为啥? 因为给Jmeter的权限不够,也就是说,在打开它的时候,直接双击打开,没有选择”以管理员身份运行“,就会导致”拒绝访问“ ! ...

  10. webstorm无法显示左边文件夹目录的解决方法

    webstorm无法显示左边文件夹目录的解决方法 方法一 view-->Tool Windows-->Project 就可以显示或者关闭 方法二 1.删除webstorm的配置文件夹 2. ...