Re: Cache Race conditions, any solution available ?
I think you pretty much got it right there. The simplest way would be to set the timeout like you said, in the far future, and then have a cron job in the background calling the Cake console (or special URL), which does the real request and sets the cache value. That would effectively reduce the database requests to only the necessary ones every N minutes. So you would be in 'control' of populating the cache, and not the visitors On Dec 21, 9:38 pm, Adrenalin wrote: > Here is the problem > "Say you cache the latest five comments for display on a sidebar in > your application. You decide that the data only needs to be refreshed > once per minute. However, you neglect to remember that this sidebar > display is renderred 50 times per second! Thus, once 60 seconds rolls > around and the cache expires, suddenly 10+ processes are running the > same SQL query to repopulate that cache. Every time the cache expires, > a sudden burst of SQL traffic will result. " > (sourcehttp://code.google.com/p/memcached/wiki/FAQ) > > Any solution already made ? I was a bit disappointed cakephp didn't > offered a solution "by default".. Or I was unable to find it's already > there. > > Here's one proposed by the same FAQ > > "First, set the cache item expire time way out in the future. Then, > you embed the "real" timeout serialized with the value. For example > you would set the item to timeout in 24 hours, but the embedded > timeout might be five minutes in the future. > > Then, when you get from the cache and examine the timeout and find it > expired, immediately edit the embedded timeout to a time in the future > and re-store the data as is. Finally, fetch from the DB and update the > cache with the latest value. This does not eliminate, but drastically > reduces the amount of time where a stampede can occur. " > > If I would like to implement that in the existing Cache::write, what > would be the right thing to do ? > > Thank you. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Cache Race conditions, any solution available ?
On 21 dic, 22:38, Adrenalin wrote: > Here is the problem > "Say you cache the latest five comments for display on a sidebar in > your application. You decide that the data only needs to be refreshed > once per minute. However, you neglect to remember that this sidebar > display is renderred 50 times per second! Thus, once 60 seconds rolls > around and the cache expires, suddenly 10+ processes are running the > same SQL query to repopulate that cache. Every time the cache expires, > a sudden burst of SQL traffic will result. " > (sourcehttp://code.google.com/p/memcached/wiki/FAQ) > > Any solution already made ? I was a bit disappointed cakephp didn't > offered a solution "by default".. Or I was unable to find it's already > there. > > Here's one proposed by the same FAQ > > "First, set the cache item expire time way out in the future. Then, > you embed the "real" timeout serialized with the value. For example > you would set the item to timeout in 24 hours, but the embedded > timeout might be five minutes in the future. > > Then, when you get from the cache and examine the timeout and find it > expired, immediately edit the embedded timeout to a time in the future > and re-store the data as is. Finally, fetch from the DB and update the > cache with the latest value. This does not eliminate, but drastically > reduces the amount of time where a stampede can occur. " > > If I would like to implement that in the existing Cache::write, what > would be the right thing to do ? Funnily enough I was looking at this yesterday. If you implement a cache wrapper of some kind (e.g. http://bin.cakephp.org/view/129354301 see http://code.assembla.com/mi/subversion/nodes/branches/mi_plugin/vendors/mi_cache.php) Then you could modify your read method to permit restoring and returning stale data and registering (gearman? afterFilter/destruct trigger?) a call to regenerate the stale key. That was the conclusion I reached yesterday, I'd be interested in other options/opinions. AD Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Cache Race conditions, any solution available ?
Here is the problem "Say you cache the latest five comments for display on a sidebar in your application. You decide that the data only needs to be refreshed once per minute. However, you neglect to remember that this sidebar display is renderred 50 times per second! Thus, once 60 seconds rolls around and the cache expires, suddenly 10+ processes are running the same SQL query to repopulate that cache. Every time the cache expires, a sudden burst of SQL traffic will result. " (source http://code.google.com/p/memcached/wiki/FAQ) Any solution already made ? I was a bit disappointed cakephp didn't offered a solution "by default".. Or I was unable to find it's already there. Here's one proposed by the same FAQ "First, set the cache item expire time way out in the future. Then, you embed the "real" timeout serialized with the value. For example you would set the item to timeout in 24 hours, but the embedded timeout might be five minutes in the future. Then, when you get from the cache and examine the timeout and find it expired, immediately edit the embedded timeout to a time in the future and re-store the data as is. Finally, fetch from the DB and update the cache with the latest value. This does not eliminate, but drastically reduces the amount of time where a stampede can occur. " If I would like to implement that in the existing Cache::write, what would be the right thing to do ? Thank you. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en