-
Notifications
You must be signed in to change notification settings - Fork 505
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
no rails sql cache when reading from slaves #81
Comments
Yeah, any updates on this? It's a pretty big issue for us since we rely on the cached SQL statements often in our app |
+1 . we are using octopus for replication. using slaves is meant to scale db queries....not having rails cache seems to be counter productive. |
I forked and resolved this issue in https://github.com/snappytv/octopus. Please feel free to test it out. Once I have a bit more time, I'll do some more testing myself and work with the octopus maintainers to pull this fix in. |
bdarrow, thanks for the fork....do you have any updates on how that worked out? |
@bdarrow can you make a pull request? :) |
Hi guys, I found the issue with cache for slaves. The problem is that Rails uses a middleware (http://api.rubyonrails.org/classes/ActiveRecord/QueryCache.html) to enable/disable cache. and this middleware only enable/disable cache on the main connection. I'm working on a middleware for Octopus, in order to do SQL cache properly. |
@bdarrow, @haidersabri how did that fork end up treating y'all with respect to this issue? @tchandy any idea on timeline for an update to fix this? Just curious if I can be of help. |
FYI, I integrated @bdarrow's proposed fix (rocketmobile@8b3f203). I didn't see a change in behavior. 2 Identical read queries were made during the same request, and the 2nd didn't come from cache. @bdarrow are we missing something with how you intended this to be used? Perhaps in conjunction with |
@eprothro Sorry about the delay. I'm working on a middleware solution for Octopus, but it isn't working yet. Any update I'll ping you guys. |
No worries! Fantastic, thanks for the update. I may be authoring a dev center article soon regarding scaling via replication on the Heroku stack featuring octopus, and this is the only significant caveat remaining that I have to explain. Let me know if I can be of service in dev or testing, happy to help! |
Hi there! I have an issue related to this one, but from the opposite side. We have queries and we do NOT want them to be cached, since they otherwise would be pulling stale data. For the most part we are getting fresh data, but intermittently the data will be stale, probably due to what you had mentioned above about the "main connection" being cached. Is your in progress middleware layer going to handle disabling caching as well? Thanks. |
Hi, Thanks and Regards, |
Hi @eprothro , @vishakhasawant and all... I did a small hack on the Octopus stack, to support query cache on slaves.. and it seems to be working! Could anyone try it and see how it behaves on a real application? It's on this branch: https://github.com/tchandy/octopus/tree/new-cache-middleware Btw, I don't encourage to run it on production, before testing on a staging server (or a local). |
Hi, I have tested this on my local and it is working. However I feel it requires one round of regression cycle before putting it on production. Thank you for fixing these on priority, |
Can you fork and rebase one on the other for your testing? Thanks @tchandy, I'll give the caching patch a whirl! On Jul 16, 2013, at 4:01 AM, Vishakha [email protected] wrote:
|
A local test isn't working for me.
With a simple test on a Model marked as
I see no caching used
Whereas, when I initialize no shards:
Marking my shards.yml config as fully replicated made no difference. |
Hi @eprothro, What version of rails are you using? btw, query cache is enabled by a ActiveRecord middleware during the request. Could you force the cache before running your action? (using the following code): ActiveRecord::Base.connection.enable_query_cache! |
@tchandy 3.2.13 and yes, I tried enabling explicitly in the 1st line of the -Evan Prothro On Jul 16, 2013, at 9:19 PM, Thiago Pradi [email protected] wrote: Hi @eprothro https://github.com/eprothro, What version of rails are you using? btw, query cache is enabled by a ActiveRecord middleware during the ActiveRecord::Base.connection.enable_query_cache! — |
@eprothro, are you using any special config or tricks? I'll try to reproduce your case in the test suite. |
My config is exactly as described in the linked wiki page. As mentioned, If you think it's my issue due to the cherry pick, no worries. I'll work to -Evan Prothro On Jul 16, 2013, at 9:36 PM, Thiago Pradi [email protected] wrote: @eprothro https://github.com/eprothro, are you using any special config I'll try to reproduce your case in the test suite. — |
@tchandy Regards, |
Thanks for the feedback @vishakhasawant and @eprothro, I'll work more on this issue today. :) |
Did you get chance to look at this issue? |
@vishakhasawant, can you see my branch https://github.com/nickmarden/octopus/tree/nick/sql-cache-bugfix fixes the problem you are seeing? One of my clients was also seeing a problem in which old stale cache values were being served, so I added a patch to more aggressively clear the query cache each time enable_query_cache! is called. |
Hi @eprothro / @vishakhasawant , I merged the PR from @nickmarden on my branch (https://github.com/tchandy/octopus/tree/new-cache-middleware). It seems that the issues that you guys are having are fixed. could you confirm? Maybe I can release a new version of Octopus with query cache support :) Thanks |
Version 0.7.0 (https://github.com/tchandy/octopus/releases/tag/v0.7.0) supports query cache. Closing this issue. |
I ran into a problem this past week running with rails 4.1.0, postgres and puma on heroku. Followed the wiki guide for installation and configuration exactly and calling the I spent a few days investigating long requests making sure it was not something in the DB like poor SQL, database lock or other database issue (because we do a lot of database work in the background). I could not find anything so I removed octopus to see if that was the issue and all went back to normal. Looking through newrelic I found a few 900,000ms requests in Middleware/Rack/ActiveRecord::QueryCache#call. Here is the stack trace for one of the hung requests:
Also, none of the database queries were even calling the cache. Not sure if this is related, but any thoughts on why replication on heroku would be causing request timeouts? Thanks! |
@knightq feel free to update that, all users have edit access, I believe. |
I also have this same issue .. Is this intended to be solved? |
Rails/activerecord typically caches SQL statements if they are identical in the same request. Typically in the log it shows the query with the word 'CACHE' next to it for queries hitting the sql cache. Using octopus in a fully replicated setup, the SQL cache is not used when reading from slaves. Only read requests explicitly sent to the master ".using(:master)" provide caching (and similarly read requests in a transaction)
The text was updated successfully, but these errors were encountered: