How to use MySql Query Cache for Magento

Improving Magento Speed and it’s performance is necessary for good  business.You can improving  Magento performance if your Magento installation is to properly configure your MySQL database server.

A proper MySQL configuration requires a low level understanding of your underlying hardware and, primarily, the memory (RAM) available.

There is one specific MySQL configuration parameter above all others that will produce significant performance improvements and takes very little understanding to implement.

 

Query Caching : 

The query cache can be useful in an environment where you have tables that do not change very often and for which the server receives many identical queries. This is a typical situation for many Web servers that generate many dynamic pages based on database content.

Magento Commerce is a database application, and as such, requires a great deal of database access and read operations. However, Magento also makes many identical queries each time a page is viewed with relatively little changes in these queries over time.
Each time a Magento page is loaded, a series of database queries are made and the database server must go to work.

Each query is first parsed and the execution of the query is initiated. Then the data must be retrieved from the disk or storage media, sorted and manipulated, and then ultimately returned to the client. This results in performance slow downs because of, among other things, slower disk access.

MySQL offers a built in configuration parameter known as query_cache_size. This configuration directive tells the MySQL server to store the result of the query in memory—much faster than accessing from disk.

The actual size of this cache and number of query result sets cached is dependent on the amount of memory available to your MySQL database server.

In a hosting environment with 1 GB RAM, such as our Split-Dedicated containers, this allows for a query cache size of 64 MB or larger depending on other memory use factors, such as other services running on the server.

How To Check If Query Caching Is Enabled:

To check if your host has query caching enabled in the MySQL server, you can issue the following command from your MySQL command prompt:

 

mysql> SHOW VARIABLES LIKE 'have_query_cache';
+------------------+----------+
| Variable_name    | Value    |
+------------------+----------+
| have_query_cache | YES      |
+------------------+----------+

If you are using a standard MySQL binary this value is always YES, even if query caching is disabled so it’s not time for great joy, yet.

To verify that query cache is actually operational, you can issue the following command to the MySQL server:

mysql> SHOW VARIABLES LIKE 'query_cache_size';
+------------------+----------+
| Variable_name    | Value    |
+------------------+----------+
| query_cache_size | 67108864 | 
+------------------+----------+
1 row in set (0.00 sec)

 

This shows that we have 64 MB available to our query cache size, a very respectable amount of memory.

The following demonstrates a server that has MySQL query cache disabled by setting the value to zero:

mysql> SHOW VARIABLES LIKE 'query_cache_size';
+------------------+----------+
| Variable_name    | Value    |
+------------------+----------+
| query_cache_size | 0        | 
+------------------+----------+
1 row in set (0.00 sec)

 

If you have root access, making a change to this value is trivial. Simply add the following line to your my.conf file in the [mysqld] section and restart your MySQL server:

query_cache_size=32M

Query caching is an extremely effective and simple method that can use to improve your Magento performance in minutes. Query caching offers several other configuration parameters that should also be carefully considered when configuring your MySQL server, including:

query_cache_type
query_cache_min_res_unit
query_cache_limit

 

I highly recommend that you review these additional configuration parameters prior to implementing your query cache configuration.

Not only will this provide you with even better performance, but you’ll also have a deeper understanding of how your MySQL configuration can enhance the performance and increase the speed of Magento.

 

 

 

 

 

 

 

 

Leave a Reply

Your email address will not be published.