Re: [fw-general] Tags for the memcached and APC backends for Zend_Cache - new approach
Hi, I don't understand how this TwoLevels cache should work and I see some odd results quick tests. Is that it will use fast cache for untagged entries, and slow for tagged entries? Cuz sometimes I see both entries in APC and in SQLite Sometimes I see it only in SQLite. With the "two levels" backend, there is an adaptive algorithm depending on : - the remaining space in the fast backend - the priority (between 0 and 10) given to the cache record (optional) ===> When you save datas which the "two levels" backend : ($usage is between 0 (nothing) and 100 (full)) if (($priority > 0) && (10 * $priority >= $usage)) { => cache into the fast backend AND into the slow backend } else { => cache into the slow backend only } When saving a cache record into the fast backend, a special lifetime is used : $fastLifetime = (int) ($lifetime / (11 - $priority)); ===> When loading datas : we try the fast backend => hit => we use it => not hit => we try with the slow backend if the cache is hit and if auto_refresh_fast_cache is on, we refresh the lifetime of the fast backend (without of course making it bigger than the original lifetime) ===> When using tags : we use the slow backend (because tags are not reliable with fast backends) The whole thing is a simple algorithm but it tries to use the fast backend in the better way depending of remaining space and priority. Probably, some people will have different ideas. I'm ready to discuss them in the issue tracker. My quick testing using TwoLevels, showed that application became much slower than without the cache. I used APC-SQLite. It's possible, depending of your cache use. And sometimes it throws fatal erros when it tries to access cached data as array although it's object. Check file TwoLevels.php on line 206 (or so) Can you be more precise on this particular thing ? Are you sure to not share cache ids between different backends (because backends don't store same datas in the same way). Regards Fabien
Re: Re: [fw-general] Tags for the memcached and APC backends for Zend_Cache - new approach
So, can anyone explain, confirm or deny things I wrote in my post? ty agatone wrote: > > Hello, > > I'm sorry for replying to older post but I need to clear some things. > > I don't understand how this TwoLevels cache should work and I see some odd > results quick tests. > Is that it will use fast cache for untagged entries, and slow for tagged > entries? Cuz sometimes I see both entries in APC and in SQLite > Sometimes I see it only in SQLite. > > My quick testing using TwoLevels, showed that application became much > slower than without the cache. > I used APC-SQLite. > > And sometimes it throws fatal erros when it tries to access cached data as > array although it's object. > Check file TwoLevels.php on line 206 (or so) > > > Fabien MARTY wrote: >> >> Hi, >> >> Please have a look at the "TwoLevels" backend in 1.7 trunk (or in 1.7 >> PR), it's want you want. >> >> It does exactly this. >> >> Feedback welcome >> >> Regards, >> >> Fabien >> >> >> Fabien MARTY >> [EMAIL PROTECTED] >> >> > > -- View this message in context: http://www.nabble.com/Tags-for-the-memcached-and-APC-backends-for-Zend_Cache---new-approach-tp20109068p20536549.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: Re: [fw-general] Tags for the memcached and APC backends for Zend_Cache - new approach
Hello, I'm sorry for replying to older post but I need to clear some things. I don't understand how this TwoLevels cache should work and I see some odd results quick tests. Is that it will use fast cache for untagged entries, and slow for tagged entries? Cuz sometimes I see both entries in APC and in SQLite Sometimes I see it only in SQLite. My quick testing using TwoLevels, showed that application became much slower than without the cache. I used APC-SQLite. And sometimes it throws fatal erros when it tries to access cached data as array although it's object. Check file TwoLevels.php on line 206 (or so) Fabien MARTY wrote: > > Hi, > > Please have a look at the "TwoLevels" backend in 1.7 trunk (or in 1.7 > PR), it's want you want. > > It does exactly this. > > Feedback welcome > > Regards, > > Fabien > > > Fabien MARTY > [EMAIL PROTECTED] > > -- View this message in context: http://www.nabble.com/Tags-for-the-memcached-and-APC-backends-for-Zend_Cache---new-approach-tp20109068p20361612.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Tags for the memcached and APC backends for Zend_Cache - new approach
Oh sorry, my fault. I used Memcached as slow backend :-) Fabien MARTY wrote: > > Hi, > > Jan Pieper a écrit : >> Can you please show us an example how to realize tagged-memcache-caching >> with >> this new two-level backend? >> > > something like that (not tested) : > > > $slowBackend = 'File'; > $fastBackend = 'Memcached'; > $slowBackendOptions = array( > 'cache_dir' => '/tmp/' > ); > $fastBackendOptions = array|( > 'servers' => ||array(array('host' => 'localhost','port' => 11211, > 'persistent' => true))| > ); > > $backendOptions = array( > 'fast_backend' => $fastBackend, > 'slow_backend' => $slowBackend, > 'fast_backend_options' => $fastBackendOptions, > 'slow_backend_options' => $slowBackendOptions > ); > > $frontendOptions = array(| > 'lifetime' => 7200| > ); > > $instance = Zend_Cache::factory('Core','Two Levels', $frontendOptions, > $backendOptions); > > // [...] use $instance normaly > > ?> > > - tags will be supported throw the "slow" backend > - there is a (simple) algorithm to store cache records into the fast > backend or into the slow backend depending on the remaining space on the > fast one and the cache priority (new option you can set when you save > the cache) > > I'm very interested in feedbacks for this new special backend. > > Regards > > Fabien > >> >> Fabien MARTY wrote: >> >>> Hi, >>> >>> Please have a look at the "TwoLevels" backend in 1.7 trunk (or in 1.7 >>> PR), it's want you want. >>> >>> It does exactly this. >>> >>> Feedback welcome >>> >>> Regards, >>> >>> Fabien >>> >>> >>> >>> >>> On Wed, Oct 22, 2008 at 5:34 PM, Diabl0 <[EMAIL PROTECTED]> wrote: >>> Colin Guthrie pisze: > Diabl0 wrote: > >> Hi >> >> As i seen this topic was discussed later, but i have new idea that >> IMHO >> can throw new light. >> >> What about combining memory cache backends with file cache fallback >> for >> tags? Ofcorse optional if someone wants this. >> >> This should give us benefits from fast memory cache and tagging >> system >> with only small drawback on performance needed to update (or >> retreive) >> tags >> cache from filesystem. >> >> And what you think about this idea? >> > It's interesting but why use the filesystem? Why not use the cache > itself > but use a different key structure to track this (e.g. cache an array > of > keys > that match the tag "wibble" under the key name > "Zend_Cache-keymap-wibble"? > This approach could be implemented in a base class and those backends > not > supporting tags could simple extend it. I've not looked at the > intricacies > of this from a data integrity point of view so there could be several > reasons why this wouldn't work :) > Filesystem was my first idea, but db and any other "solid" backend is good. Memcached and other memory based backends aren't good because it's content can be deleted in any time. > Also as a related issue, would it be possible to implement a cache > invalidation queue system backed by a database? The reason I say this > is > when considering multi-server environments (let's assume there is one > database for all servers). > See my post with Mao_Cache. I didn't tested it with DB yet, but i was also thinking about clustered enviroments. -- K. >>> >>> -- >>> Fabien MARTY >>> [EMAIL PROTECTED] >>> >>> >>> >> >> > > > -- View this message in context: http://www.nabble.com/Tags-for-the-memcached-and-APC-backends-for-Zend_Cache---new-approach-tp20109068p20319029.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Tags for the memcached and APC backends for Zend_Cache - new approach
Hi, Jan Pieper a écrit : Can you please show us an example how to realize tagged-memcache-caching with this new two-level backend? something like that (not tested) : '/tmp/' ); $fastBackendOptions = array|( 'servers' => ||array(array('host' => 'localhost','port' => 11211, 'persistent' => true))| ); $backendOptions = array( 'fast_backend' => $fastBackend, 'slow_backend' => $slowBackend, 'fast_backend_options' => $fastBackendOptions, 'slow_backend_options' => $slowBackendOptions ); $frontendOptions = array(| 'lifetime' => 7200| ); $instance = Zend_Cache::factory('Core','Two Levels', $frontendOptions, $backendOptions); // [...] use $instance normaly ?> - tags will be supported throw the "slow" backend - there is a (simple) algorithm to store cache records into the fast backend or into the slow backend depending on the remaining space on the fast one and the cache priority (new option you can set when you save the cache) I'm very interested in feedbacks for this new special backend. Regards Fabien Fabien MARTY wrote: Hi, Please have a look at the "TwoLevels" backend in 1.7 trunk (or in 1.7 PR), it's want you want. It does exactly this. Feedback welcome Regards, Fabien On Wed, Oct 22, 2008 at 5:34 PM, Diabl0 <[EMAIL PROTECTED]> wrote: Colin Guthrie pisze: Diabl0 wrote: Hi As i seen this topic was discussed later, but i have new idea that IMHO can throw new light. What about combining memory cache backends with file cache fallback for tags? Ofcorse optional if someone wants this. This should give us benefits from fast memory cache and tagging system with only small drawback on performance needed to update (or retreive) tags cache from filesystem. And what you think about this idea? It's interesting but why use the filesystem? Why not use the cache itself but use a different key structure to track this (e.g. cache an array of keys that match the tag "wibble" under the key name "Zend_Cache-keymap-wibble"? This approach could be implemented in a base class and those backends not supporting tags could simple extend it. I've not looked at the intricacies of this from a data integrity point of view so there could be several reasons why this wouldn't work :) Filesystem was my first idea, but db and any other "solid" backend is good. Memcached and other memory based backends aren't good because it's content can be deleted in any time. Also as a related issue, would it be possible to implement a cache invalidation queue system backed by a database? The reason I say this is when considering multi-server environments (let's assume there is one database for all servers). See my post with Mao_Cache. I didn't tested it with DB yet, but i was also thinking about clustered enviroments. -- K. -- Fabien MARTY [EMAIL PROTECTED]
Re: Re: [fw-general] Tags for the memcached and APC backends for Zend_Cache - new approach
Can you please show us an example how to realize tagged-memcache-caching with this new two-level backend? Fabien MARTY wrote: > > Hi, > > Please have a look at the "TwoLevels" backend in 1.7 trunk (or in 1.7 > PR), it's want you want. > > It does exactly this. > > Feedback welcome > > Regards, > > Fabien > > > > > On Wed, Oct 22, 2008 at 5:34 PM, Diabl0 <[EMAIL PROTECTED]> wrote: >> Colin Guthrie pisze: >>> >>> Diabl0 wrote: Hi As i seen this topic was discussed later, but i have new idea that IMHO can throw new light. What about combining memory cache backends with file cache fallback for tags? Ofcorse optional if someone wants this. This should give us benefits from fast memory cache and tagging system with only small drawback on performance needed to update (or retreive) tags cache from filesystem. And what you think about this idea? >>> >>> It's interesting but why use the filesystem? Why not use the cache >>> itself >>> but use a different key structure to track this (e.g. cache an array of >>> keys >>> that match the tag "wibble" under the key name >>> "Zend_Cache-keymap-wibble"? >>> This approach could be implemented in a base class and those backends >>> not >>> supporting tags could simple extend it. I've not looked at the >>> intricacies >>> of this from a data integrity point of view so there could be several >>> reasons why this wouldn't work :) >> >> Filesystem was my first idea, but db and any other "solid" backend is >> good. >> Memcached and other memory based backends aren't good because it's >> content >> can be deleted in any time. >> >>> Also as a related issue, would it be possible to implement a cache >>> invalidation queue system backed by a database? The reason I say this is >>> when considering multi-server environments (let's assume there is one >>> database for all servers). >> >> See my post with Mao_Cache. I didn't tested it with DB yet, but i was >> also >> thinking about clustered enviroments. >> >> -- >> K. >> >> > > > > -- > Fabien MARTY > [EMAIL PROTECTED] > > -- View this message in context: http://www.nabble.com/Tags-for-the-memcached-and-APC-backends-for-Zend_Cache---new-approach-tp20109068p20305351.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Tags for the memcached and APC backends for Zend_Cache - new approach
Diabl0 pisze: Ok, here you can download and test my fast implementation. It's only example, so it still need some testing and probably improvements. Unfortutnenty, trying to implement Mao_Cache::CLEANING_MODE_MATCHING_ANY_TAG (in my opinion very useful and i will submit it as suggestion for ZF team) i was forced to create own copy of Zend_Cache and Zend_Cache_Core, but there are only few changes - rest is oryginal ZF 1.6.1 file. Example of use: $frontendOptions = array ('automatic_serialization' => true ); $memcachedMetadataFileBackendOptions = array ('cache_dir' => APPLICATION_PATH . 'temp/memcached' ); $memcachedOptions = array( 'metadatabackend' => array( 'backend' => 'File', 'options' => $memcachedMetadataFileBackendOptions ), 'servers' => array(array('host' => 'localhost','port' => 11211, 'persistent' => true)) ); $cache = Zend_Cache::factory ( 'Mao_Cache_Core', 'Mao_Cache_Backend_Memcached', $frontendOptions, $memcachedOptions, true, true ); $cache->save( 'test2', 'test2', array('tags', 'tag2'), 9090); $cache->save( 'test1', 'test1', array('tags', 'tag1'), 9090); $cache->clean(Mao_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('tag1')); echo 'T1: '; var_dump( $cache->load('test1') ); echo ''; echo 'T2: '; var_dump( $cache->load('test2') ); echo ''; All files are here: http://www.gazeta.ie/xxx/Mao_Cache.zip -- Krzysztof Szatanik