Benchmarking Magento Part 3 - Reddis Cache

Redis is an in-memory caching application that we will use to cache session information and as a full page cache. This post is Part 3 of the Magento benchmarking series of posts. The server I am benchmarking here is the standard server used in Part 1 with PHP-FPM installed and configured from Part 2. You can see those posts here:

Installing Redis

Redis is available from the default Debian repositories. Install it with the following commands:

apt update
apt upgrade
apt install redis

This will start a Redis server that is listening on 127.0.0.1:6379. The redis-cli tool was also installed and can be used to check that the Redis server is running and listening of connections:

redis-cli ping
PONG

Configuring Magento to use Redis

Magento 2.3 provides a management tool that I will use to create the Redis configuration. The tool is located at /path/to/magento/root/bin/magento. Invoking it without any options will give you a list of the commands it takes. I will use it to configure Magento to use the Redis server for both session and full page caching.

This is the command to configure Magento to use Redis as a full page cache:

bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0

And this is the command to use Redis as the session cache:

bin/magento setup:config:set --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-log-level=3 --session-save-redis-db=2

You can configure Magento to use Redis to cache either or both sessions and full pages. You will get the best results if you enable both.

If you have run this command as root instead of the user you may need to reset the permissions on the Magento directory after running these commands.

Check configuration is set to use Redis:

less app/etc/env.php

Look for this section that lists Cm_Cache_Backend_Redis as the caching backend:

    'cache' => [
        'frontend' => [
            'default' => [
                'id_prefix' => '7cd_',
                'backend' => 'Cm_Cache_Backend_Redis',
                'backend_options' => [
                    'server' => '127.0.0.1',
                    'database' => '0',
                    'port' => '6379',
                    'password' => '',
                    'compress_data' => '1',
                    'compression_lib' => ''
                ]
            ],
            'page_cache' => [
                'id_prefix' => '7cd_'
            ]
        ]
    ],

The redis-cli tool will also print out any requests that is processes in real time. Run this command:

redis-cli monitor **TODO "monitor" is wordy or unneeded**

and request a page from the site with your browser. You should see quite a lot of information about the requests that Magento is making to Redis if everything is set up and working.

Benchmarks Results

The following tables shows the results of adding a Redis cache to the basic server also running PHP-FPM:

HTTP HTTPS
Stock server 147 trans/sec 111 trans/sec
PHP-FPM 165 trans/sec (12%) 116 trans/sec (5%)
Redis & PHP-FPM 187 trans/sec (27%) 142 trans/sec (28%)

The Redis server has provided an ~30% improvement over the stock when deployed with PHP-FPM, which, given the quick and easy installation and configuration, is a worthwhile investment of time.

Next Benchmark

In the next post I will install and benchmark a Varnish cache.

Magento Benchmark Part 4