Loading...
Close
Warning
Cookies are used on this site to provide the best user experience. If you continue, we assume that you agree to receive cookies from this site. OK

How to speed up CS-Cart. Server details

August 16th, 2019

Dear Friends,

There is a tradition of sharing the experiences in our office. There was a really interesting report about CS-Cart speed problem from one of our leading developer Evgeny Shakhin in August 2019.

How to make CS-Cart faster?

Evgeny has been working with CS-Cart for 7 years. Every year he passes the CS-Cart official test for developers with a high score. So, we can trust his recommends in CS-Cart performance issues.

CS-Cart certificated developers

So, the report was so useful that we decided to share with you the most important aspects of CS-Cart speed optimization theme. 

 

First of all, we won't tell about the results in Google Page Speed Insights service. This resource shows the layout problems. We will talk only about code and server issues. 


cs-cart performance test

What influences on CS-Cart performance?


  1. The hosting features
  2. The web server (Apache, Nginx)
  3. PHP
  4. MySQL
  5. Cache
  6. Extra software

 

Usually, we met 3 variants of web servers:

  • Apache+mod_php (the old and the widespread type)
  • Nginx + php-fpm
  • Nginx + Apache + mod_php

According to W3Tech.com, as of January 14, 2019, Apache (44.4%) is just slightly ahead of Nginx (40.9%) in terms of websites using their servers. Between them, they dominate nearly 85% of the web server market.

The popularity of Apache and Nginx

Let's talk about the differences between Apache and Nginx. How do you think what is faster in work? Yes, Nginx is faster in certain circumstances. Apache uses up server memory while Nginx (best used for static files) need the help of php-fpm to process dynamic content.

Taking into account all aspects of 3 variants of web servers and our experience, we came to the conclusion that Nginx + php-fpm works faster of all, but it requires to set up the config files. 

 You can use Nginx + Apache + mod_php, it will be a bit slower, but it supports .htaccess file. 

 

In case you have Apache+mod_php and you want to raise the CS-Cart performance, should you move to Nginx server? To say the truth, you are supposed to see the results only if:

  • you have a frequently used store (more than 5 people simultaneously)
  • there is much static contents on pages
  • you are not happy with Google Page Speed Insights results

In case the CS-Cart store has few visitors a day, you won't see any results at all.

 

So, our advice is to use Nginx + php-fpm on CS-Cart projects.


What about PHP?php vertions to use

In short, use PHP 7 + module OPCache!

By default, it uses OPCache module, but sometimes it can be disabled! Check it. 

OPCache improves PHP speed by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request. In other words, a PHP script when it is executed, is compiled into opcode, code that is understandable by the machine.


Attention!Only CS-Cart 4.9. and higher supports PHP 7.3. 

 

You should be aware that PHP is not in itself a critical place with CS-Cart page load speed issues. Yes, PHP 7 is faster than PHP 5, but it has not got so impact on the CS-Cart performance as MySQL queries. 

So, we get close to the most important part in theme How to speed up CS-Cart — MySQL queries!

Usually. the CS-Cart store works very fast right after the installation. The first problems with the page loading speed occur when the admin uploads the products on store. Over time, the CS-Cart speed of page loading decreases dramatically and you have to find a way to fix it.

 

Why the CS-Cart speed falls down when you use the system?


  1. Too complex finish query.To say the truth, it is a very bad query! Indexes are not used in every part of the query. Look at FIND IN SET part and OR operator! You should use OR very carefully. It can create several queries. So you can't create index in this query. 
  2. The function SQL_CALC_FOUND_ROWS are used here. The query executed, ignoring the LIMIT.
  3. It leads to locks in certain circumstances. There are two types of locks: read locks and write locks.

 

 

So, how to speed up CS-Cart  by fixing the MySQL queries and blocks?

CS-Cart otimization

MySQL queries.

The treatment of root causes.

  1. The most quality solution is Product Indexing. The same method presented in the Magento platform. So the storefront data retrieval goes with the help of accumulating data into special tables using indexers. 
  2. The compromise variant - facilitate the final query. It can help to make CS-Cart a bit faster.

The treatment of symptoms.

  1. The increases of buffer size in MySQL configuration (join_buffer_size and etc.) in conjunction with RAM upgrade.
  2. The product blocks caching and on-page cache.

 

MySQL blocks.

Blocks are divided into two types: read lock and write lock.

CS-Cart mysql locks

1. If user A reads the data, other users can read data, but they can not write data until user A finished the reading process (read lock). 2. If user A writes data, other users can not read and write data, until user A finishes writing process (write lock). The locks can be on tables level (the whole table in database is blocked) or on rows level (certain rows in database are blocked).

How to use InnoDB for CS-Cart

By default, all CS-Cart uses MyISAM storage engine for the MySQL tables. This storage engine is old, has stable work, but it has one great disadvantage — it uses the blockage of the whole table. To fix this problem, another storage engine was invented: InnoDB. InnoDB uses a more advanced algorithm of locking. It blocks only used rows in the table, not the whole table. 


The main CS-Cart problem — it uses MyISAM by default and CS-Cart suffers from the locks very often.


The samples of table locks in CS-Cart.

  1. The first client opens the category with sorting by popularity. So the table Product Popularity is locked on reading. Another client wants to open the product page, but he has to wait for the first customer.
  2. Clients always block the tables on sessions, logs, orders and statistics in the database on write lock.
  3. The backup process leads to longstanding read lock of tables.
  4. The synchronization with third-party systems creates write lock on products tables.

 

cs-cart slow page loading

The treatment of root causes.

1. Convert the MyISAM tables into InnoDB or ExtraDB (a fork InnoDB by Percona). The fork is better to use on multi-server projects. Usually InnoDB is enough for the work. Don't forget to edit the config files MySQL due to RAM.

The treatment of symptoms.

1. Any caching process can help the situation, but it's not the remedy.

 

 

My SQL config file.


What can be changed?

  1. Adapt the settings due to RAM. This is particularly true for buffer values. By default, MySQL config file in CS-Cart is intended to use the only 800Mb of random access memory. But, if you use expensive hosting plan, definitely you will have more of random access memory on your server. So, you need to enter the necessary settings into config files to use the most of random access memory.
  2. You can activate the cache of queries, but you should be very careful in this. We don't recommend to do it.

 

How to change the config file?

  1. Pay attention to the utility MySQLtuner  https://github.com/major/MySQLTuner-perl
  2. It's a great program. You launch it, and the utility gives you full information about your server problems due to statistical data it gathers.
  3. Watch the main aspects of config file settings by Percona slides https://www.percona.com/resources/technical-presentations/optimizing-mysql-configuration-mysql-56-percona-technical-webinars

 

When you should change MySQL config file?

  1.  When you have a powerful server and you haven't done any settings yet.
  2. In case you moved to InnoDB.

 

 

About the caching!

cs-cart cache

 

Extra software

  • Use Redis for cache and sessions. Redis is data caching technology. It caches data into RAM, so it's quickly accessed.
  • You may use Sphinx for search optimization on the website, but full-text search MySQL not worse for the majority of products. 
  • Use Varnish cache for the Full page cache.

 

How can we test CS-Cart on speed issues?

  • Use admin.php&?debug
  • loaddy.com

 

Get a quote

 

In case, you need some help with CS-Cart performance, please, click GET A QUOTE button. We can make you store faster.

 

Comments

No posts found

New post

Up