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 TCP

Local TCP

Local socket

PING_INLINE

290,697.66

1,020,408.19

1,162,790.62

PING_BULK

364,963.53

1,408,450.62

1,785,714.25

SET

5,531.28

591,716.00

724,637.69

GET

5,852.06

485,436.91

833,333.38

INCR

246,913.58

763,358.81

1,315,789.50

LPUSH

5,572.58

320,512.81

487,804.88

LPOP

5,852.74

495,049.50

564,971.75

SADD

203,252.03

1,063,829.88

1,234,567.88

SPOP

362,318.84

1,219,512.12

1,538,461.62

LPUSH

5,572.27

454,545.47

500,000.00

LRANGE_100

58.56

5,753.74

7,227.00

LRANGE_300

1,535.20

1,690.93

LRANGE_500

853.21

1,031.46

LRANGE_600

619.66

749.81

MSET

65,402.22

90,090.09

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 -c10-P10-d2000

(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):

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

Comment

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>.