zoukankan      html  css  js  c++  java
  • [转]How to speed up Magento 2. Maximum Performance

    本文转自: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:

    Full Page Cache

    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

    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:


    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:


    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.

    store is filled with test data

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

    Products:

    Products

    Orders:

    Orders

    A lot of categories:

    A lot of categories

    Customers:

    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:


    Check:


    You should see the next output:

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

    Then run the command


    This will then re-compile the files. Lastly:


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


    Step 2. Enable Cache

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

    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.

    Flat catalog

    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

    JavaScript settings
    CSS settings

    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:


    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:


    For this demo store we use:


    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:


    PHP (config file .php.ini)

    The RAM limit must be at least 1G


    For cron jobs we personally set at least 4GB


    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”

    update on save

    Step 6. Enable Gzip Compression

    Turn on gzip compression in the nginx config:


    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:

    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:

    Google PageSpeed Mobile
    Google PageSpeed Desktop

    Product Page:

    Configurable Product

    Product Page mobile
    Product Page Desktop

    2) Pingdom

    Location: Stockholm, Sweden

    Speed of category page:

    Speed of category page

    Speed of product page (configurable product):

    Speed of product page

    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 Kubrak

    Valentyn KubrakChief Operating Officer

  • 相关阅读:
    js布尔型
    C#函数(十一)
    JavaScript+jQuery从小工到专家学习笔记数值
    C#函数(十)
    C#函数(九)
    jquery 操作复选框 下拉框
    jquery select操作大全
    Jquery与Json实现Ajax
    如何打造创业团队
    jquery select操作大全
  • 原文地址:https://www.cnblogs.com/freeliver54/p/9133966.html
Copyright © 2011-2022 走看看