Re: [APC-DEV] Caching file_get_contents output inside APC (Performance improvement).
| From: | Pierre Joye | Date: | Mon, 26 Oct 2009 21:14:05 +0000 |
| Subject: | Re: [APC-DEV] Caching file_get_contents output inside APC (Performance improvement). | ||
| References: | 1 | Groups: | php.pecl.dev php.apc.dev |
| Request: | Send a blank email to pecl-dev+get-6730@lists.php.net to get a copy of this message | ||
hi,
As caching everything obviously helps, I wonder if it makes sense to
do it inside an opcode cache. What performence improvement does it
bring vs:
(pseudo code where my_cache* could be either APC user cache, memcached
or other caching lib like Cache_Lite)
if (!($cached = my_cache_get($key))) {
$data = file_get_contents($path);
my_cache_add($data, $ttl);
}
Cheers,
--
Pierre
On Mon, Oct 26, 2009 at 9:36 PM, Basant Kukreja
<basant.kukreja@gmail.com> wrote:
> Hi,
> APC creates a mmap which is used for caching compiled php response. Besides
> this APC provides API to cache user data into this mmap. There are many php
> apps which uses file_get_contents to read the static files. If APC can cache
> these files in it's mmap, it will improve file_get_contents performance.
>
> Based on the above idea, I developed a patch which stores the file_get_contents
> output in APC's cache. In this patch, APC intercepts the calls of
> file_get_contents and replaces it with apc_file_get_contents function. If file
> is a full path and entire file is requested then APC caches the content.
>
> To enable the caching use the following in php.ini :
> apc.cache_static_contents=1
> apc.user_ttl = 30
>
> apc.user_ttl will decide how long the entry will remain inside the cache. If
> apc.user_ttl is set to 0 then the entry will never be removed from cache.
>
> Here is the performance data collected using Studio 12 on Solaris sparc for
> ecommerce php benchmark. (3500 simultaneous users)
>
> Excl. Incl. Excl. Incl. Excl. Incl. Name
> User CPU User CPU Total LWP Total LWP Sys. CPU Sys. CPU
> sec. sec. sec. sec. sec. sec.
> No Cache :
> 0.831 28.660 1.141 540.018 0.030 344.311
> zif_file_get_contents
> With Cache :
> 1.481 181.537 1.821 282.758 0.140 12.449
> zif_apc_file_get_contents
>
>
> User + System time before Caching = 372 seconds
> User + System time after Caching = 193 seconds
> Total time reduction in file_cache_contents = 48%
>
> Here is my blog :
>
> http://blogs.sun.com/basant/entry/caching_file_get_contents_output
> Here is the link to the patch :
>
> http://blogs.sun.com/basant/resource/apc_file_cache_trunk_patch.txt
>
> There are many other enhancements possible in this patch. I would appreciate
> any comments.
>
> Regards,
> Basant.
>
> --
> APC Development Mailing List (http://pecl.php.net/APC)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Pierre
http://blog.thepimp.net | http://www.libgd.org