Support Memcached and/or ElasticCache #263

Open
waldoj opened this Issue Mar 29, 2013 · 7 comments

Projects

None yet

2 participants

@waldoj
Member
waldoj commented Mar 29, 2013

If we're going to move to a consuming-our-own-API model, then that's going to benefit from an object caching system. Inevitably, that means Memcached or/or ElastiCache. ElastiCache has the advantage of being a turn-key setup, although Memcached seems awfully easy to install.

This ought to be pretty easy to interface with. The method to retrieve each type of content—say, a law—would take the file off the filesystem, unless Memcached is installed, in which case it pulls it out of Memcached.

@krues8dr
Member

The only issue here is that you need as much memory as you've got data. Considering how large our dataset is we're only going to get a benefit from pure in-memory caches on things like the laws list (which is not resource intensive) and possibly a few of the more popular pages - on an "average" server, everything else will page-out too quickly to be useful. This might be a premature optimization as a result.

Honestly, if we're using static json files that have been pre-generated to respond to api requests, we'll get a much bigger benefit since it's just disk IO - which is relatively fast (though not as fast as in-memory ops) and very cheap compared to memory.

@waldoj
Member
waldoj commented Mar 31, 2013

Memcached is a "least recently used" cache—it will happily optimize in the memory available to it. (Unlike APC, which has the annoying habit of deleting everything when the cache fills up.) So if it just caches the 500 laws requested the most frequently, that's pretty good. I don't see why it has to contain the whole legal code.

Separately, though, it's entirely possible that this is premature optimization. Alternately, it may well be that this is something that APC can handle quite nicely. If Virginia Decoded is any indicator, the long tail is very, very long—only a couple of dozen laws are regularly requested. Storing those in APC might provide a strong benefit to the largest percentage of the traffic (admittedly a low percentage), making it unnecessary to use an object caching system.

@waldoj
Member
waldoj commented Aug 22, 2013

Note that ElastiCache only works for sites hosted on EC2.

@waldoj
Member
waldoj commented Sep 5, 2013

Now that we're keeping JSON as static files, I think that this is premature optimization. This could be a useful feature for some high-traffic sites, though, so I've moved it past v1.0.

@waldoj
Member
waldoj commented Jan 28, 2014

I recently added Memcached support to another project. It's absurdly easy, and the payoff is pretty big. This will be a simple addition.

@waldoj
Member
waldoj commented Oct 15, 2014

See also #516.

@waldoj waldoj added a commit that closed this issue Oct 16, 2014
@waldoj waldoj Add Memcached / Redis support
Closes #263.
973215b
@waldoj waldoj closed this in 973215b Oct 16, 2014
@waldoj
Member
waldoj commented Oct 17, 2014

There remains one more thing to do: serialize and unserialize material when it goes in and out of the cache.

@waldoj waldoj reopened this Oct 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment