colinmollenhour / Cm_Cache_Backend_Redis

A Zend_Cache backend for Redis with full support for tags (works great with Magento)
Other
389 stars 142 forks source link

Cm_Cache_Backend_Redis as a 2nd level cache #36

Closed raptor75 closed 11 years ago

raptor75 commented 11 years ago

Hi Colin,

I have successfully used Cm_Cache_Backend_Redis as a single-level cache on Magento. Recently though there have been whitepapers that Redis is losing performance because it is single-threaded. Nexcess' recent whitepaper suggested that a better way forward is to use a 2-level cache using Memcache as first level, and Redis as second level, and of course applying the 2-level patch fix.

Now I know the latest version of Magento supports REDIS out of the box, but for those who are not going there yet, I wanted to ask you, does your extension allow it to be used as a second-level cache? Or is it like Cm_Cache_Backend_Files which does not support it? I could not identify this easily from the code.

If not supported, are there any plans to support it?

thanks, Stefan

x86fantini commented 11 years ago

+raptor75 very good question. really waiting fro dev's answer

thx Simone

colinmollenhour commented 11 years ago

First, in case you didn't notice due to Magento devs renaming the class, the Redis backend that is included in Magneto EE 1.13 and CE 1.8 is Cm_Cache_Backend_Redis (just in case you weren't already aware).

In short: The backend already does support operation as the "slow" backend for TwoLevels.

I did extensive benchmarking of various backends and combinations and presented the results at Imagine 2012: http://goo.gl/NDXan In my "Recommendations" page you will see that Memcached+Redis is exactly what I recommended for large deployments. Redis is very capable by itself and unless you have a truly large deployment I'd just stick with Redis only. Even when using just Redis it seems there are possibilities for tag data leakage, and I imagine using memcached+Redis would only make this worse. Besides, who wants to manage two servers for little to no gain?

For really really large deployments I'd look into using MongoDb as it has a blazing fast response time and due to the advanced data structures supported can support tagging with 100% reliability and no garbage collection. Only thing to watch out for is if you put it on a server with other servers like MySQL you should look out for MongoDb hogging memory.

On Cm_Cache_Backend_Files I am not even 100% sure operations as a TwoLevels isn't supported.. However, there is no good use case for it. Alas, if it isn't supported it couldn't be hard to fix, but it doesn't seem to be important enough for anyone to open a pull request so I am happy leaving it as it is. :)

raptor75 commented 11 years ago

Hi Colin,

thanks for the quick reply!!

Regarding support for Cm_Cache_Backend_Files, actually in my own experiments I tried using it as a 2nd Level cache, and Magento fell back to using the OTB files cache.

Regarding Cm_Cache_Backend_Redis, actually I have no intention of going for for Magento EE 1.13 / CE 1.8. From your presentation, yes I can see you are recommending to go for a combination Memcache/REDIS, from this I assume that your extension as it currently is, supports beings used as a second level cache.

However this is not clear from the documentation nor description on the extension itself - they all say to use it as a single-level cache. So essentially what I am after is a clear yes/no answer whether the extension in its current form supports being used as a second level cache on Magento versions previous to EE 1.13 / CE 1.8.

Sorry I won't be able to try it myself before Monday and the suspense is killing me :) Seriously though, I would like to know in case when I try it and it does not work, whether it is because of support or because I am doing something wrong.

Looking forward to your answer!

thanks, Stefan

colinmollenhour commented 11 years ago

In short: The backend already does support operation as the "slow" backend for TwoLevels.

Shorter: Yes

You can even see the benchmarks in the slides I linked to.

raptor75 commented 11 years ago

Thanks Colin.

Sorry I thought you were referring to its support in Magento 1.13.

Thanks, I look forward to trying it out on Monday!

Addenda - Thanks for the awesome work by the way!

raptor75 commented 11 years ago

Hi again, sorry for re-opening this issue.

I am setting up the 2-level cache with memcache and redis.

When using it as single level, it is as easy as this:

  <cache>
      <backend>Cm_Cache_Backend_Redis</backend>
      <backend_options>
      </backend_options>
  </cache>      

.....etc

With 2-level, would it be like this please?

    <cache>
        <backend>memcached</backend>
        <memcached>
               memcached options
        </memcached>
        <slow_backend>Cm_Cache_Backend_Redis</slow_backend>
        <slow_backend_options>
               redis options
        </slow_backend_options>
    </cache>

Sorry I could not find a sample file to follow.

Regards, Stefan

raptor75 commented 11 years ago

This seems to be working like thanks.