Re: Using Redis as a Cache Backend in Magento
The fine folks at the Magento ECG have published a nice article on using Redis as a cache backend in Magento. It provides some nice benchmarks and setup tips but there is one pretty major point where I disagree with their advice: using a single Redis instance. Here is why:
- Redis is single-threaded so it’s performance peaks when it uses one full CPU core. On a multi-core machine (every machine these days) your peak performance with Redis will be higher if you can use multiple cores. Also, there will be no waiting between different processes. E.g. while one process may be fetching the config, another would be waiting to load a session and another would be waiting to load a FPC record. By having each on a separate core you have much higher peak performance and less contention.
- Redis allows you to set maxmemory but this applies to the entire process so when using multiple databases with maxmemory of say 1GB, there is no way to prevent the session backend from using 999MB and leave only 1MB for the FPC or vice-versa. So having separate instances of Redis means you can allocate maxmemory separately as appropriate.
- Driver bugs.. AFAIK the Cm_Cache_Backend_Redis plays well with db numbers besides 0 but the phpredis driver is actually pretty buggy and especially old versions have problems where if the connection is lost the driver will reconnect but when it reconnects it will not select the last used database and just default to 0. So for example if your FPC is 0 and the sessions are in 1 and the connection reconnects you may end up with sessions in your FPC database. These are silly bugs to have but the safest thing to do is run a separate process for each and always use db 0.
- Stats. Redis stores stats globally so to see for example number of evictions or peak size or something these stats would be useless if you have multiple dbs in one instance.
- Configuration. You cannot configure Redis settings like eviction policy, disk flushing, etc. per-database but it may make sense to use different settings for different purposes. E.g. I probably wouldn’t bother persisting FPC records to disk at all, or perhaps very infrequently, but I would definitely persist sessions.
- Redis processes are extremely lightweight, around 1MB of memory when empty so there is really no reason not to configure multiple instances. Just copy the init/upstart script and tweak it as many times as needed.
I think it is also worth mentioning that the README.md file is worth a read; those poor Enterprise Edition folks didn’t get a copy of that with their shiny new 1.13. ;-)