#011049: Using other storage engines beyond file-based storage.

Description:

http://www.php.net/manual/en/ref.apc.phpurl
http://www.php.net/manual/en/ref.memcache.phpurl

We have been using the cache classes extensively in our application as a way to relieve database pressure. We were actually very successful in this venture and we have moved the bottleneck to the hard drive instead. There are compelling reason to utilize memory-based caching systems that are now becoming standard in PHP5.

APC is a PECL extension that is romored to be integrated into future versions of PHP. It would be fantastic if APC were supported as an alternative to storing caches on the file system. In a system that already contained APC, this could offer a huge speed enhancement.

Memcache is similar to APC but it is extremely useful for a load balanced enterprise environment. This relies on memcached which is the most reliable and trusted method of sharing large volumes of cacheable data between many different servers.

These two extensions would offer an incredible scalability enhancement to any system built using ezComponents for an enterprice class application.

I will likely be writing an APC extension in the upcoming days. Any direction would be appreciated.


Environment:

PHP Version: 5.2.3


- Attachments
Cache.zip (36 kb)
[Download] [Permanent Link]
Patches to cache classes to allow for APC caching and speed optimizations for file-based cache
Cache_2.zip (51.9 kb)
[Download] [Permanent Link]
Most recent Cache classes used by Grady

- Comments

Hello Grady,

this definitely seems like a good addition. We actually have been thinking of implementing this from the start, but sort of forgot about it. In order to implement a new backend, you basically have to extend the ezcCacheStorage abstract class (Cache/src/storage.php). Perhaps the trickiest thing would be to implement the search support with attributes (Example on how this is used: http://ez.no/doc/components/view/latest/(file)/introduction_Cache.html#complex-cachingurl), an implementation example is in Cache/src/file.php, line 283.

In case you want more hints, I suggest you contact the components mailinglist (http://lists.ez.no/mailman/listinfo/componentsurl). We'd be glad to help you with this contribution.

regards,
Derick

#252980 by Derick Rethans on June 29th, 2007 [Permanent Link]

I've uploaded a file with a working prototype for the Caching with APC.

1) There is a straight APC cache ezcCacheStorageApcPlain
2) There is a hybrid filesystem/APC cache ezcCacheStorageFileApcArray

The purpose of the hybrid is for charing cache between multiple servers. We have been mounting the filebased cache with NFS between 4 webservers to keep their caches in sync (mostly for deleting). The NFS was heavily strained so we try to keep the cache in the APC memory as much as possible and check the NFS periodically as a "reality check." That way if a cache gets deleted or updated on server 4, server 1 will see that change right away. That way we can set our cache TTL really high.

There are also some significant changes to the core of the filesystem caching to add in a "registry" pattern. Some caches that get checked regularly (sometimes 100+ times in a given page load) were causing undue strain on the filesystem. By keeping the "already seen" caches in a static array, you can alleviate that strain and gain an order of magnitude speed improvement.

That same "registry pattern" is implemented on the APC cache as well.

Please forgive the annoying fact that I used tabs instead of spaces. A simple search and replace can fix it if it is too bothersome.

#253115 by Grady Kuhnline on July 26th, 2007 [Permanent Link]

Cache_2.zip

I just uploaded an updated version of the cache classes I've been using. These are modified from the most recet 2007.1.1 cache class.

ezcCacheStorageFileArray
I've modified this to be more efficient under high stress.
1) Uses a static array to keep track of caches we've seen before in the same page load. This can dramatically increase the speed of a repeated read cache.

2) Covers the edge cases where the file is reported to exist but is still unavailable. This happens frequently on a busy NFS mount. This affect store, restore and delete.

3) Covers the case where a huge amount of files need to be deleted in the delete function. When there is a large set of files to delete, instead of unlinking the file, it touches it and sets its mtime to 1969. This is at least 100% faster.

ezcCacheStorageFileApcArray
This is an extension of the ezcCacheStorageFileArray except it keeps cache in APC and in the file system. The filesystem is seen as the authority but the cache is read from APC as much as possible. This reduces reads to the filesystem and speeds up the cache dramatically.

ezcCacheStorageApcPlain
This stores cache directly in the APC cache. It keeps a registry of all known caches to aid searching.

ezcCacheStorageMemcachePlain
This stores the cache directly in memcache. This is extremely fast. It also keeps a registry of all known caches to aid searching.

#253613 by Grady Kuhnline on September 7th, 2007 [Permanent Link]

Implemented in rev. 6369. It will be available in Cache 1.3alpha1.

#254010 by Alexandru Stanoi on October 5th, 2007 [Permanent Link]

- History
Properties
Type Enhancement
Priority Medium
Component Components » Cache
Affects Unknown
Fix Versions 1.3alpha1 - Cache 1.3alpha1
2007.2alpha1 - eZ components 2007.2alpha1
Reporter Grady Kuhnline
Responsible Alexandru Stanoi
Status 0 Closed
Resolution Implemented
Created June 29th, 2007
Updated October 5th, 2007
Resolved October 5th, 2007
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #015537
  Graph shows to small and truncated rotated axis labels