This project is archived and is in readonly mode.
Per-request in memory cache for all communication with the MemCache server(s)
Reported by Nahum Wild | December 28th, 2008 @ 07:28 AM
In November I released a plugin (http://tinyurl.com/7q5fqh) that enhances MemCacheStore by using a per-request local cache to buffer duplicate memcache reads which can result in halving the number of read requests made. I've been asked to add that functionality to Edge and this is that work.
The description linked to essentially describes two changes, the first to MemCacheStore which this patch applies directly to that class instead of creating a new Store class. And secondly tidy ups to the MemCache Session Store which this patch does not implement. I need to follow up about Joshua's comment on ticket #949 to see if I can help there.
Comments and changes to this ticket
-
Jeffrey Hardy January 6th, 2009 @ 05:56 PM
I totally dig the idea of this. It's similar to what Nick Kallen's cache_money plugin does:
http://github.com/nkallen/cache-...
The main thing that bothers me about the implementation in this patch is that it knows about Action Controller. The cache store shouldn't know Action Controller even exists. I'd much rather there be a facility to tell the cache store to use the local cache or not, such that we could declare the setting from AC's side.
-
Nahum Wild January 8th, 2009 @ 09:19 PM
Jeffrey, I totally agree with you on the subject of the class knowing about ActionController. In fact my delay in updating this ticket with a thread safe version is because I've been trying to solve that problem nicely.
I like simply going:
config.action_controller.session_store = :mem_cache_store
to setup memcache in rails. I don't really want people to have to do extra things to get it going when it should just work seamlessly without any effort. At the moment it still depends on AC.
Doing the local caching actually solves a bug in rails, something I've not directly said above. It stops the problem of entries in memcache changing in between the execution of the action and view code. I've had this happen a number of times, pain in the butt to track down. I probably should have tagged this with bug too maybe...
Anyway, I've attached an updated patch with my changes being thread safe now plus a minor fix to the 'exist?' method.
-
Nahum Wild January 8th, 2009 @ 09:27 PM
Just to clariy for those reading, the dependency on ActionController is because MemCacheStore hooks into the Dispatcher before_dispatch callback to clear the local cache before each request is processed.
-
DHH January 12th, 2009 @ 01:49 PM
- Assigned user changed from DHH to josh
Josh, where should we best put this reset call?
-
josh January 12th, 2009 @ 02:58 PM
- Milestone cleared.
- State changed from new to open
I think a middleware hook would be most appropriate.
use ActiveSupport::Cache::MemCacheStore::LocalCache # or Buffering
You could have the middleware initialize and reset the local cache as well. Otherwise the cache store could function standalone without the local buffer.
-
Repository January 16th, 2009 @ 03:25 AM
- State changed from open to resolved
(from [a53ad5bba37199047ba20194933e122bf6b0252f]) Added in a local per request cache to MemCacheStore. It acts as a buffer to stop unneccessary requests being sent through to memcache [#1653 state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
-
josh January 16th, 2009 @ 03:26 AM
Hey, I just commit it.
I made some changes, it uses a thread local instead of a lock. Should be much less overhead.
Please review and make sure it still functions how you want.
-
Nahum Wild January 16th, 2009 @ 04:09 AM
Will do thanks for doing that. I'll look at it right now. (Clients discovered I had spare time :-(
-
josh January 16th, 2009 @ 02:40 PM
Interesting comments on github:
http://github.com/rails/rails/co...
Maybe it should be a subclass or extension module?
-
Lourens Naudé January 17th, 2009 @ 03:23 AM
Josh,
Initial backend agnostic local cache strategy attached.Introduced an ActiveSupport::Cache::Strategy::* namespace, which may be frowned upon, but may be useful for similar optimizations.
Original test cases passes.
-
josh January 17th, 2009 @ 03:52 AM
- State changed from resolved to open
@Lourens Thanks
I think it can be implemented cleaner with extend and super. I'll take care of that though.
Thanks for the patch, will commit soon.
-
Repository January 18th, 2009 @ 12:01 AM
- State changed from open to resolved
(from [b08c96887538cf53670bb882e79996582375e6c9]) Decouple the local cache strategy from MemCacheStore for reuse with other remote stores [#1653 state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
-
Lourens Naudé January 28th, 2009 @ 05:25 PM
@ Josh,
Am aware of two apps where the immutable snippet in #read raises with TypeError when the value being dup'ed is a special case constant eg. Fixnum, TrueClass etc.
Here's the reference to the MRI implementation of Object#clone, Object#dup ( object.c ) && the special constant declaration ( ruby.h ) from a 187 checkout :
Attached is a patch that implements Object#dup? to better handle such cases.
Thoughts ?
- Lourens
-
Lourens Naudé January 28th, 2009 @ 08:12 PM
@ Josh,
Interesting, but isn't it dodgy practice to mask the TypeError in non-framework code VS being able to conditionally guard against it in specific framework areas, like the local cache, to not blow up the whole process when that happens ?
-
Lourens Naudé January 29th, 2009 @ 02:38 AM
Josh,
Nevermind, references :
"* object.duplicable? returns true if object.dup is safe. False for nil, true, false, symbols, and numbers; true otherwise. #9333 [sur]"
Patch that piggy backs on that attached.
-
Repository January 29th, 2009 @ 03:18 AM
(from [2e69db18ce2815c25eee64fc2978e7f6b57f6e1f]) Only dup local cache values if duplicable [#1653 state:resolved] http://github.com/rails/rails/co...
-
Ryan Bigg October 9th, 2010 @ 09:54 PM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1653 Per-request in memory cache for all communication with the MemCache server(s) (from [a53ad5bba37199047ba20194933e122bf6b0252f]) Added i...
- 1653 Per-request in memory cache for all communication with the MemCache server(s) (from [b08c96887538cf53670bb882e79996582375e6c9]) Decoupl...
- 1653 Per-request in memory cache for all communication with the MemCache server(s) (from [2e69db18ce2815c25eee64fc2978e7f6b57f6e1f]) Only du...