CS-Cart speed optimization

Meta-data
20.12.2016
Add-on re-installation in CS-Cart
26.04.2017

CS-Cart speed optimization

CS-Cart Speed Optimization

Hello!

In this review, I will discuss the issues that have recently started to be of concern to a very large number of our clients. One way or another, they relate to the speed of CS-Cart.

Thus,

1. Why does CS-Cart slow down?

2. How to lead the store to green space of Google PageSpeed Insights?

3. How to select a server for CS-Cart?

These issues are closely interlinked, and in order to give an answer, I want to give you a brief overview on theory.

If someone does not want to go into the details, you can roll down to the end of the article and see the comprehensive, concise answers to the specified questions.

However, let's continue for those who want to broaden the scope of knowledge.


Why does CS-Cart slow down?

So, what affects the speed of an online store? Let's look at a simple scheme.

This scheme more simply shows what happens when the user works with the site.

Your potential customer sits down at the computer (or picks up the phone) and types address of the online store in the browser box. The browser, in turn, refers to the server where CS-Cart is installed (for those who do not know, CS-Cart is working on a stack of technologies HTML / CSS / Less, JavaScript / Jquery, Smarty, PHP, MySQL). Therefore, the server begins to process the PHP file that refers to other PHP files, connects Smarty, LESS, executes files of these libraries, sends certain requests to MySQL, receives responses, processes them, compiles the final result, and sends back to the browser. The browser processes the response and displays the result to the buyer.

The same scheme works out when a customer visits the store sections, looks at products, adds them to a cart and makes an order.

So, what affects the speed of the online store?

1. Speed of the connection. I.e. the speed with which the browser can interact with the server

2. The speed of information processing by the browser.

The speed is composed of:

2.1. JavaScript execution speed.

2.2. Volume of graphics on the website.

2.3. The amount of the information displayed on the website.

3. Information processing rate by the server.

Which, in turn, depends on:

3.1. Power of the server.

3.2. Configuration of the server’s software.

3.3. Speed of PHP files performance

3.4. Speed of Smarty files performance.

3.5. Speed of MySQL queries.

3.6. The amount of simultaneous requests on the server.

Let’s examine this question a little deeper.

Speed of the connection

Here I include the speed of the server’s work with the client. From time to time we are applied by the customers, the server of which is on the other side of the world. As usual, it does not cause any problems, but there are hosting providers, which receive a query from Russia very long, and the answer goes for a long time, too. More recently, we had a similar situation with the server, which was located just a thousand kilometers away, in Moscow. Let’s not go into details of why it has happened, just remember that you need to consider territoriality when you choose a server, territoriality of your customers, their remoteness from the server, and rate with which the server will respond to their requests.

Speed of information processing by the browser

The browser, through which you browse a website, consumes a certain amount of computer resources, and the more information it processes, the more resources are required.

Thus, if on the pages of your online store there is a lot of complex scripts, a huge amount of text or images, it can easily happen that while trying to process all this amount of information the browser consumes all resources of the computer and it will slow down.

Thus, the weaker the computer of your potential client is, the harder it will be for a computer to process information on the website.

* Common problems

Clearly bigger images

As I mentioned above, a very common cause of a website’s slow speed is the use of large images. However, there can be a more delicate situation when the problem cannot be identified immediately. That is, you will see a small image, but in fact it is huge and simply reduced by html tag properties.

In the example given the page is loaded images 3615px to 3615px.

Theme with non-optimized JavaScript

Be very careful with the theme that you are going to purchase. Before the purchase test it in Google Page Insights and check the results. If the results are not included in the green space, then think again before purchasing it. No beauty should compete with usability and performance. Remember that we live in a rapidly developing information society, where people have almost completely lost the ability to wait, at least loading the page in a browser.

The speed of information processing by the server

Let’s consider this issue deeper.

Any software works using hardware resources. If we consider the version of CS-Cart 4.4.x, the CS-Cart architects have done a great job to optimize the product and it works much faster than the predecessors. PHP, MySQL, Smarty are already perfectly optimized, and if you want to get the engine with the powerful functionality that is offered out of the box, then it will be extremely difficult to improve it, and it won’t justify the costs that will be required.

Another issue, if you need to optimize the functionality when some features can be removed due to the fact that you do not use them. Such decision is usually made in large-scale projects or when the store has worked for several years and it is clear that certain functions additionally load the server.

* Common problems

Scheduled Commands

Please note that such processes as unload of 1C, any other synchronization store with a third-party service, backup for a store on schedule, also consume server resources. During such events the download speed of the pages for users can reduce.

In addition, as a rule, after directory synchronization is required cleaning the cache, which further loads on the system.

Automatic cache cleaning

As you can see from the test results, pages without caching require a lot more resources than cached. And page loading time is also significantly different. The CS-Cart has a good parameter that helps to debug the store before running, however it overloads the store a lot. Therefore, always check its condition. It can be managed on the page Administration panel> Design> Themes.

Developer mode

By default, the lines of code, which are responsible for switching the mode, are arranged and commented out in config.local.php file. However, it happens that careless developers use the code in the most unpredictable places.

Favorite places for adding the developer mode:

1. Exactly the very same config.php. But it happens that the developer inserts the code in the very beginning of the file, not even bothering to slide the file down and uncomment the required line.

2. config.local.php

3. init.php

It happens that the developer mode is added cache cleaning or any additional features, such as logging. In fact, all this affects the speed of the site.

Modules, themes, third-party modifications

Always pay attention to the way in which the performance of your store has changed after the installation of a module. The more complex functionality in the module, the more likely it can lead to the brakes.

It is not just about the acquired ready-to-use modules, but also about custom development.

Simple tip: you can always disable the modules and see how the speed of the store changes with the module or without it. Note, however, that after switching on and off of the module partial cache clearing happens, and store slowdown can occur simply because of it.

Now let’s consider the issue of software capacity and configuration.

In documentation CS-Cart it is stated that for a standard online store based on CS-Cart 4.1.x with the attendance of 50 visitors per hour only a single core processor 2.4 GHz and 1024 MB of RAM is enough.

I decided to check whether this is true for 4.4.x. We acquired of a virtual server with a single core processor Intel Xeon E5620, 2.4Ghz and 1024 Mb of RAM. We installed Ubuntu 16.04 x64 on the server, used PHP7, a combination of apache + Nginx and ZendOpcache. Not for advertising, but in order to show how I further held my interaction with the hosting support team, I can say that the server has been ordered at the company Anchor Hosting (see “How to lead the store to green space of Google Page Insights?”).

Next, I have installed CS-Cart 4.4.2 international assembly on this server and made the next experiment.

I have run top command from the console and started to look how these or other processes are loaded onto a server while working with the store. Mainly we shall be interested in httpd, nginx and mysqld processes. Nginx and mysql consume a small amount of resources, so I did not accentuate attention to them and I placed the results of the httpd in the table, which mainly loaded the central processing unit.

Here are the results I got.

As we can see, our server copes reasonably well with the load when one person works with it at the current time.

What will happen with the online store, if several people use it at once? In theory, each processor thread will process requests of users one by one in turn. It can be compared with traffic lanes on the bridge where traffic lane is a processor kernel thread, and cars are the processors. In situations when there is a dense stream of cars, happens a traffic jam, and some vehicles have to wait for the moment when they will be able to enter the bridge.

To see how it works in practice, you can use the utility Apache Benchmark. This utility allows sending several simultaneous requests to the server and receiving some useful information about the results of processing. By the way, back in 2010, I wrote a detailed article on this topic. And the title is "What does Apache Benchmark talk about?". Use Google, if you are interested.

I started load testing using Apache Benchmark and checked how would our store react under this load, if I view pages as a normal user.

ab -c10 -n100 http://our-test-store.com

With this request we simulate 10 simultaneous requests to the online store's main page. And perform this simulation 10 times.

So, when I used the store through a browser with such load, the main page have been loading for approximately 2.5 seconds. According to the item card result was 3.5 seconds.

In addition to actual test, we have the data provided by Apache Benchmark. They show us that after 10 tests, in which were run 10 queries, have been successfully completed 100 simultaneously. The average request processing time was 1.496 seconds. The longest request was processed 1.713 seconds and the fastest 1.366 seconds.

When switching to the language of store visitors, one person will wait 1.366 seconds, and another one 1.733 seconds for the page to load. Do not forget that have been waiting for 2.5 seconds. Apparently, this is due to the fact that ab does not consider the speed of processing and output of information by the browser.

* Note

Apart from usual visitors, the site can also be visited by various indexing robots, which inevitably create additional load.

For clarity I have also performed similar action on our test server with a 4-core Intel Xeon D 1520 processor, 8 flows on 2.8Ghz and 32 Gb of RAM. CentOS 6.7, PHP5, Apache + Nginx and ZendOpcache are installed on server. Here are the results I got with top:

Result of ab testing:

In fact, the main page loaded for 1.09 seconds during testing:

As you can see, speed of loading pages on our corporate test server is much higher. However, this is related not only to power and type of processor, but also to the specific configuration of the server software. This is detailed below.

How to lead the store to green space of Google Page Insights?

The results of my experiments have shown that in spite of a good download speed when using a single-core processor 2.4Ghz, Google Page Insights shows the red space:

Unlike the store, installed on a 4-core server.

But how to get the shop to the green space with a single core 2.4Ghz server?

Being surprised by the results, I began to view Google recommendations.

Therefore, I wrote to the support service of Anchor Hosting with a request to fulfill Google recommendations. Having charged off 1,000 rubles, they wrote that the server optimization is completed. I decided to immediately check the result and received the green space:

As a result, we received the following server configuration:

  • Ubuntu 16.04
  • PHP7 (ZendOpcache, Memcache, Memcached)
  • Apache (mod_deflate)>
  • Nginx (HttpGzipModule)
  • MySQL

For more detailed configuration, go to the link.


How to select a server?

To select a server the following information is required:

1. Forecast of website traffic.

2. The number of simultaneous users in the peak of activity.

3. The number of simultaneous actions, such as, for example, making an order.

4. How often and to what extent will change the catalog of an online store.

5. How often will synchronization with any services happen.

6. How often will the creation of backup copies occur.

In addition, you must have a ready-made online store with all installed modules and the theme, and with the amount of goods that has to be presented in the online store.

Before selecting a server, you must have the above-mentioned information and already based on it, and on data received in the course of the experiment with Apache Benchmark, select the server that will withstand the load.

At the early stage mostly it will be enough to run the store on the server, which is indicated in the documentation of CS-Cart and already in process of development to increase capacity.

In conclusion, let me tell you a story that happened in 2016. One of our regular customers complained about the slow speed of the online store. After analysis it became clear that resources for the server are not enough: CPU power and disk space. It's a wholesale store and the orders are made with about 100-200 goods. And there can be up to 50 users at a time. In addition, the store operates virtually without cache because every hour there are new items being unloaded and residues being updated. The customer was offered a thorough optimization of the store and the website transfer to other more powerful server, even two servers. One for the database, and the other for applications. The procedure is expensive and the customer each time postponed a decision and just asked to remove unnecessary files, to restart the service, and to perform other actions that put off the inevitable. A few months later there was nothing to delete, services' reload and other temporary solutions, which have been helpful previously, stopped working. The store has just hung up. Of course, this time the customer has agreed to pay any money just to make the store active and to bring it in order for the future. The optimization procedure of the online store took at least a month of incessant work for careful review of the entire code and consideration of new algorithms of its faster work. We were able to revive the customer's store, and to keep it semi-working state during this time, and ultimately it ended well. After optimization the client was more than satisfied.

However, this situation very well shows how ignoring the problems and impending dangers may end up.

The larger your project becomes, the more complex system shall be built for its performance. And like any other system, it requires constant monitoring, adjustments and improvement. Keep it in mind, take care of your online store and the server whereon it operates.

So, let's sum it up and formulate concise answers to all the questions that were announced in the beginning.


Why does CS-Cart slow down?

  • The server is not powerful enough.
  • Poor configuration of the server.
  • Low data flow rate between clients and the server.
  • A large number / poorly written JavaScript code (theme, modules, third-party modifications).
  • A large number of graphics / graphics of large than the required size.
  • A large number of data supplied on the page.
  • PHP code, MySQL queries, Smarty code (theme, modules, third-party modifications).

How to lead the store to green space of Google Page Insights?

1. Transfer the store on the server with the recommended parameters. For CS-Cart 4.4.x - CPU 2.4Ghz, RAM 1024MB.

2. Request the recommended server configuration: Linux, PHP7 (ZendOpcache, Memcache, Memcached), Apache (mod_deflate), Nginx (HttpGzipModule), MySQL.

3. Reduce the number of graphics on pages.

4. Reduce the amount of information displayed on the page.

5. Turn off / change the theme, if it uses a "bad JavaScript", or request its optimization.

6. Disconnect the modules that are loaded server, or ask for their optimization.

7. Turn off the modules, which overload the server, or ask for their optimization.


How to select a server?

1. Determine the maximum number of users being simultaneously on your website.

2. Determine the maximum number of concurrent actions, such as, for example, making an order.

3. Determine how often and to what extent will the catalog of an online store change.

4. Determine how often does synchronization with any services happen.

5. Determine how often are the backup copies being created.

6. You need to have a ready-made online store to understand how its work loads the server.

With these data and results of experiments with Apache Benchmark the we have obtained above, there may be approximately chosen a server. If it is still difficult for you, you should better transfer the said data to a developer and ask him to advise you.

When it comes to the standard CS-Cart 4.4.x, and browsing a page for 2-3 seconds is a satisfactory result, then:

for 12 at the same time staying online users a single core server 2.4 Ghz, 1024 Mb of core memory is enough;

for 45 concurrent users on the server is required a server of 4 cores with 2.8 Ghz. 8 Gb of core memory is more than enough;

I hope you find this information useful. I wish you high profits and all the best.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>