A Complete Guide to Rails Caching
nateberkopec.com
nateberkopec.com
I don't agree. End users are used to shitty systems which take some time to load, but we developers should know better. We should be able to recognise performance bottlenecks during the architecture design and development, also we should be able to measure the layers where optimisation is necessary and useful. And when developing web app, caching should always be in mind as one tool to improve system performance in one way or another.
Otherwise fantastic piece of information.
I don't know exactly, but I assume this is because I know what goes on behind the scenes, and 99% of the time, the website is doing way more work than it really needs to in order to deliver the experience that I'm asking for.
No mention of HTTP caching though, which for a whole class of applications is a great way to minimise rendering time.
Rails has great support[1] for etag based content expiry.
[1] http://api.rubyonrails.org/classes/ActionController/Conditio...
What has been your experience with Rails caching + compression?
There are benchmarks on the project that illustrate the performance edge it has over Dalli as well.
Redis provides multiple databases (0-16) for just this situation. Use one db for caching, another for Sidekiq, and another for ad-hoc tasks. Redis can also be configured to evict entries with an expiration first, which means cached data will be cycled through while the important bits linger safely.
Mandatory disclaimer, I wrote the gem.
You will definitely have to flush before switching from no compression to compression or changing marshallers though.
it was based roughly on this https://gist.github.com/watsonbox/3170415
No, not really.
We use postgres and once you get to around 1m records, even COUNT is slow as it does a full table scan, even with indexes.
As far as I can tell the Rails ecosystem completely lacks a good model / data caching system. There are a few gems that do model caching but they all have major flaws. I'd love to see a good guide on Rails data caching and gems that eliminate the mess of calls to Rails.cache.fetch.
[Edit: conditional responses are probably the best way to go – save the bandwidth.]
Just because the page loads quickly on your laptop doesn't mean it loads quickly for everyone. I'm working on a tool to measure this stuff: https://rasterize.io/blog/speed-objections.html, contact me if you're interested in early access.
Contact me if you're interested in an early preview.
> The most often-used method of all Rails cache stores is fetch
It's true, but I think you should add performance tests while the app write/read because the big problem of db/cache is the write that influence also the read(fetch). Another big problem is the expiration vs garbage collection after the memory is full.
And outside the USA, add on another 200ms more. I, an Australian, visited the USA last year and was surprised, although I had expected it, at how much faster the Internet was.
I get the general feeling that people in the USA end up much more picky about performance than their Australian counterparts, because they’re used to a result which is quite a bit faster anyway.
It’s rather a pity that we as an industry don’t care more about performance, because on average we’re utterly abysmally appallingly atrocious at it. There’s simply no good reason for things to be as slow as they are.
Isn't this assuming your development mode has the same memory/cpu as your production? I can't tell you how many times I get questions from clients who ask why their 16GB dev box is running fine while their 512MB dyno is slow. The point of a docker image is to limit these resources, which `rails s production` does not do.
It's a fast-and-loose measurement, to be sure. Virtualization/dockerization is the only way to get a super-accurate measurement.
Somewhat related: How has your experience been setting up docker with Rails? I have an idea for a project that seamlessly integrate docker into one's Rails dev workflow, but so far I have found its setup (let alone working with it) to be cumbersome to say the least.
The 'time per request' that has 'mean, across all concurrent requests' behind it is the mean of every single request. All other ms values show you the response time per single request * concurrency. So the percentile table is only interesting when you take this into account.
An alternative question:
Why do we have to cache so damn much in Ruby and complicate the hell out of our infrastructure and code?
Because Ruby is slow.
What production website doesn't cache? You make it sound like it's a Ruby-only issue.
<!-- "breaking_news_1" background cached 07/16/2015 at 12:44 AM -->
So much for that theory.Just because we end up using that cached content to create a unique mix for each user doesn't mean that we don't cache. I think you misunderstand the process.
He's also mostly talking about our Elixir stack which is not our primary stack (though... we're hiring!). So it's a little bit of an edge case.
There IS less caching involved in our Elixir stack though - due to how it functions - so maybe that's where the confusion arose.
I don't think you should never do caching - just that is is non-trivial, especially once you move past a 15min-blog use case.
On the JVM, .NET, etc. statically compiled languages typically provide blazing performance, which allows you to selectively cache (i.e. where you really need it) vs. caching virtually everything because it's-just-so-damn-slow otherwise.