views:

78

answers:

2

I don't think I'm at the point where I need to go through and get memcached setup for my Rails app, but I would like to do some simple caching on a few things.

Is using file_store for as the config.cache_store setting sufficient enough? Or will having to access files for data over and over kill the benefit of caching in the first place from a server load stand point?

Or maybe I'm not really understanding the difference between file_store and mem_cache_store...

A: 

The file_store will cache stuff in files in a filesystem.

If that filesystem is LOCAL to your web server, then clearly, it will only be relevant to that particular web server, therefore you'll lose cache hit rate when a cached entity exists on one server but not another.

How many web servers do you have? 2? 10? 100?

The file_store for caching does not scale properly and will reduce your hit rate over a shared store (for example the memcached one).

The purpose of using memcached is so that a pool of web servers can access a single cache (even though it can be split on multiple physical servers). Using the file_store will not (unless it's a network filesystem, and that will almost certainly be fraught with its own problems).

Always measure the cache hit rate on any cache; if you're not getting a high hit % then it's usually not worth it. Be sure to trend it over time in your monitoring.

MarkR
Right now I just have one web server and probably want need to scale to a new server anytime in the next year...so I'm thinking the filesystem stuff might be my best bet to get something up running faster until I can get a separate memcache server setup.
Shpigford
The file-based cache will still WORK in a multi-server setup, but it will get a lower and lower hit rate the more servers you have until it becomes useless; exactly when that would be I can't predict.
MarkR
+1  A: 

I don't think I'm at the point where I need to go through and get memcached setup for my Rails app, but I would like to do some simple caching on a few things

Then use your existing database to store your cached items. (You are using a database, right?)

memcached is only a fast-but-dumb database. If you don't need the ‘fast’ part(*) then don't introduce the extra complexity, inconsistency and overhead of having a separate cache layer.

memcache with file_store is a dumb-but-not-even-fast database, and thus of little use to anyone except for compatibility/testing.

(*: and really, most sites don't. Memcache should be a last resort when you can't optimise your schema, denormalise it for common queries or pre-calculate complex operations any further. It's not something the average web application should be considering as essential for scalability.)

bobince
Where are you saying store the cached items? Just using Rails file_store option for caching?
Shpigford
A table in a database — MySQL, PostgreSQL, SQL Server, whatever you're using. (You're not currently putting your app's data in the filesystem are you? If so then that's a severe performance issue you're going to want to fix by moving it to a proper database before you consider anything to do with caching.)
bobince
I'm using MySQL.SO you're saying that, performance wise, storage cached data in a table in my database is better than storing the cached data in the file system (in tmp/cache for example).
Shpigford
Oh yes, by a long way.
bobince