Tuning Redis for extra Magento performance

Tuning Redis for extra Magento performance

Using Redis is a quick & easy way to improve Magento performance. Setting it up is easy, performance benefits are great, and we never had problems with it – it’s fire and forget. Inchoo already covered that in detail: https://inchoo.net/magento/using-redis-cache-backend-and-session-storage-in-magento/.

But, come on! Are we really going to races with the stock engine? Are we tuning Magento performance or what? Redis is fast by default, but it can get a lot faster. Read on to see how.

Crunching numbers

Redis, by default, listens to TCP connections only. And Magento, by default, connects that way to Redis. But, if PHP and Redis are on the same machine, you can easily use Unix sockets instead for an impressive performance gain. Here are the numbers:

Remote TCPLocal TCPLocal socket

Remote TCP is another server. Local TCP is same server over TCP connection, and Local socket is same server over unix socket connection. Numbers are requests per second.

The numbers speak for themselves, but let’s emphasize benchmarks for two most commonly used Redis commands in Magento: SADD, where local socket serves 607.41% more requests per second than remote TCP and 116.05% more than local TCP, and GET, where local socket serves incredible 14240.00% more than remote TCP and 171.67% more requests per second than local TCP. (In fact, Magento uses HGET, but redis-benchmark does not benchmark that command, so we consider GET as a proxy here.)

If you want to reproduce the benchmark on your machines, here is the command to use:

redis-benchmark -s /var/run/redis/redis.sock -c 10 -P 10 -d 2000

(Using socket, 10 parallel clients, 10 requests pipelined, 2000 bytes data size, default 100000 requests). Settings for data should be reasonably close to how actually Magento uses Redis. And if you want to do benchmarks of your own: http://redis.io/topics/benchmarks.

The takeaway here is that Redis itself is crazy fast. Basically, it’s only limited by RAM speed. And that means that even TCP overhead reduces its performance a lot. If you add physical network overhead, you get a few orders of magnitude worse performance than you could have.

Unix sockets FTW

Setting up Redis & Magento to communicate over unix sockets is actually very easy (assuming you’ve already got Redis working over default TCP, these are the only changes needed):

1. Edit redis.conf. (On Ubuntu 16.04, Redis configuration is located in /etc/redis/redis.conf)

Under “# Specify the path for the Unix socket…” add:

unixsocket /var/run/redis/redis.sock
unixsocketperm 777

(Just remember, this is for Ubuntu, and may be different on other Linuxes, like, for example, CentOS.) Restart Redis server.

2. Edit Magentos local.xml:


(Everything else staying the same as when using Redis over TCP.) Clear Magento caches. Voila!


So, let’s face it: you are not eBay or Alibaba (yet). Before you get there, you can still run your Magento shop fine off of one server. Use that to your advantage.

Today, one server can (and should) mean plenty of CPU cores and heaps of RAM. And, we can take that big, bad engine and turbocharge it. Use unix sockets to get the maximum power out of Redis.

You made it all the way down here so you must have enjoyed this post! You may also like:

How To Connect Google Analytics 4 To Magento 2 Bojan Mareljic
Bojan Mareljic, | 36

How To Connect Google Analytics 4 To Magento 2

3 best open-source eCommerce platforms in 2021 Zrinka Antolovic
Zrinka Antolovic, | 8

3 best open-source eCommerce platforms in 2021

Using Redis cache backend and session storage in Magento Marko Martinovic
Marko Martinovic, | 43

Using Redis cache backend and session storage in Magento


  1. How would you modify the Redis cache tag cleanup script if using Unix sockets instead of TCP?

    For example, in your Magento redis cache setup tutorial you suggest a cron command such as:
    30 2 * * * /usr/bin/php /some/path/cm_redis_tools/rediscli.php -s -p 6379 -d 0,1

    Will this tool work for sockets, and if so how do you configure the cron command?


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=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.