"Preheating" a cache with a full, complex compute page from my Rails application

Our initial page loading is a beast in our Rails application. The great thing about this is the lack of updated pages. This is all very Ajax-y (and our designers did it great!) There is only one problem: the initial loading of the page is a monster.

I tweaked and pushed and I got incredible speed improvements by optimizing, caching, remembering, etc. For typical users of my application, this is all very useful. However, there are edge cases where the amount of data that is crunching is significantly larger than others, and the initial page load can take up to 15-25 seconds due to the sheer amount of data that is crunching.

Our biggest problem is that we cannot cache anything on the pages. This application is very CREATE / UPDATE and users only come to it when they need to make changes, a quick analysis of our logs shows that PUTs and POSTs outnumber GETs by almost 50 to 1. Any attempt to cache a page, action, or fragment cache any part the pages would expire almost immediately, which made performance a little harder to improve now that all other layers are optimized. I am interested in the following:

Is there a way to generate the page and "preheat" the cache with it so that when the page is requested, I serve it from the cache instead of the application? What is on my mind, while the user is PUTing and POSTing using an existing page (it all happens with xhr requests), my server can expire and regenerate the page server of the page so that when the time comes, the user needs the full page again ... BAM is already generated and I am serving it. Obviously this will take up some significant system resources, but I'm lucky with my fantastic hardware and you have a finite number of users.

From a logical point of view, it seems like I should have done it before, however I can't find any examples of this on the net ... maybe just typing the wrong words. Any ideas? Examples? Tutorials, plugins or links I can follow?

Thanks in advance! I really appreciate it!

+2


source to share


2 answers


Sorry to hit the old thread, but I found this - not sure if it helps anyone with the same need: https://github.com/tommyh/preheat



+1


source


I don't know of any plugins or gems out there to handle this for you.

But when saving models, you might find a lot of time on the expiration of the cached content, and in the worst case, you may have an extra hook in your after_save that (once the cached content has expired) will end up in the url that will generate that cache internally.

pseudocode:



clear_cache
# get the page (in which the page is cached)
open("http://localhost/controller_name/#{id}").read

      

I'm not saying there is a way to do it, but it will at least technically work.

0


source







All Articles