Magento / Web Apps

Redis Configuration for Magento 1.9.x

by , , revisited on


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install nginx, Varnish and lots of useful modules for them, this is your one stop repository to get all performance related software.
You have to maintain an active subscription in order to be able to use the repository!

Sanity check

In case you have a single Magento server, you should not be concerned with Redis most of the time. It is more efficient to mount sessions and other caches to RAM (in most Linux`es, you can). Introducing Redis in a single-server setup brings nothing in comparison to memory-mounted caches, only additional protocol overhead.

Requirements

Naturally, you have to install Redis server first. You have to install Redis PHP extension as well.

Each Redis cache instance should use different database number to avoid naming conflicts. Take note of db parameter in the XML and increment it appropriately. In our configs below, we save PHP sessions in Redis DB with number 0, whereas storing the basic Magento cache in DB with number 1, etc.

Store Magento PHP sessions in Redis

I’ve seen it many times how disk stored sessions made websites crawl. How? A misconfigured PHP session garbage collector left millions of session files lying around. Listing the sessions directory took minutes. This would never happen if it was stored in RAM. It is much faster access-wise.

This part activates session handling by Redis.
Inside <config><global>..</global></config> section of app/etc/local.xml, put the following:

        <session_save>db</session_save>
        <redis_session>
            <host>1.2.3.4</host>
            <port>6379</port>
            <password></password>
            <timeout>2.5</timeout>
            <persistent></persistent>
            <db>0</db>
            <compression_threshold>2048</compression_threshold>
            <compression_lib>gzip</compression_lib>
            <log_level>1</log_level>
            <max_concurrency>6</max_concurrency>
            <break_after_frontend>5</break_after_frontend>
            <break_after_adminhtml>30</break_after_adminhtml>
            <bot_lifetime>7200</bot_lifetime>
        </redis_session>

Store Magento configuration cache in Redis

This activates general Magento cache (modules configuration, etc.) to be stored in Redis.

        <cache>
          <backend>Mage_Cache_Backend_Redis</backend>
          <backend_options>
            <server>1.2.3.4</server> 
            <port>6379</port>
            <persistent></persistent>
            <database>1</database>
            <password></password>
            <force_standalone>0</force_standalone> 
            <connect_retries>1</connect_retries>   
            <read_timeout>10</read_timeout>        
            <automatic_cleaning_factor>0</automatic_cleaning_factor> 
            <compress_data>1</compress_data>  
            <compress_tags>1</compress_tags>  
            <compress_threshold>20480</compress_threshold> 
            <compression_lib>gzip</compression_lib> 
          </backend_options>
        </cache>

Store Lesti FPC cache in Redis

Install Lesti FPC and put the following to app/code/etc/fpc.xml:

<?xml version="1.0"?>
<config>
    <global>
        <fpc>
            <lifetime>86400</lifetime>
            <!-- please read https://github.com/colinmollenhour/Cm_Cache_Backend_Redis for more informations -->
            <backend>Cm_Cache_Backend_Redis</backend>
            <backend_options>
                <server>1.2.3.4/server>
                <port>6379</port>
                <persistent>cache-fpc</persistent>
                <database>2</database>
                <password></password>
                <force_standalone>0</force_standalone>
                <connect_retries>1</connect_retries>
                <lifetimelimit>86400</lifetimelimit>
                <read_timeout>10</read_timeout>
                <compress_data>1</compress_data>
                <compress_tags>1</compress_tags>
                <compress_data>gzip</compress_data>
            </backend_options>
        </fpc>
    </global>
</config>

Confirm Redis is being used by running redis-cli monitor.

PotatoCommerce FPC full example

The following example demonstrate the best performance configuration, utilizing Redis cache using socket for sessions and all cache types. This uses a Redis instance on the same machine with Magento files (thus makes use of Unix sockets).

Note that putting port in the above config is still required to avoid getting ERR (3): Notice: Undefined index: port error logged to your system.log.

See the quick sanity check at the beginning – you still need another Magento server instance, otherwise you don’t need Redis after all.

  1. Lewis Seals

    Instead of config.xml I think it should be local.xml located /app/etc

    Reply
    • Danila Vershinin

      You’re absolutely right. I’ve made the correction.

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.