New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Memcached and/or ElasticCache #263

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

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

This comment has been minimized.

Show comment
Hide comment
@krues8dr

krues8dr Mar 31, 2013

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.

Member

krues8dr commented Mar 31, 2013

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

This comment has been minimized.

Show comment
Hide comment
@waldoj

waldoj Mar 31, 2013

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@waldoj

waldoj Aug 22, 2013

Member

Note that ElastiCache only works for sites hosted on EC2.

Member

waldoj commented Aug 22, 2013

Note that ElastiCache only works for sites hosted on EC2.

@waldoj

This comment has been minimized.

Show comment
Hide comment
@waldoj

waldoj Sep 5, 2013

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@waldoj

waldoj Jan 28, 2014

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@waldoj

waldoj Oct 15, 2014

Member

See also #516.

Member

waldoj commented Oct 15, 2014

See also #516.

@waldoj waldoj closed this in 973215b Oct 16, 2014

@waldoj

This comment has been minimized.

Show comment
Hide comment
@waldoj

waldoj Oct 17, 2014

Member

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

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