Re: [APC-DEV] Caching file_get_contents output inside APC (Performance improvement).

[email protected] (Basant Kukreja) Mon, 26 Oct 2009 18:11:27 -0700
Newsgroups php.pecl.dev,php.apc.dev
Message-ID <[email protected]>
Hi,
    Probably it will perform close to the version I attached but my
point is that application doesn't
need to be modified and can use this feature by modifying configuration.

More options which I think of which can be used to extend the caching featu=
re :
apc.cache_max_file_size    # Maximum amount of files to be cached
apc.max_cache_use_bytes # Maximum amount of space to be occupied in cache.

Regards,
Basant.


On Mon, Oct 26, 2009 at 2:14 PM, Pierre Joye <[email protected]> wrote:
> 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 =3D my_cache_get($key))) {
> =A0$data =3D file_get_contents($path);
> =A0my_cache_add($data, $ttl);
> }
>
> Cheers,
> --
> Pierre
> On Mon, Oct 26, 2009 at 9:36 PM, Basant Kukreja
> <[email protected]> wrote:
>> Hi,
>> =A0 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 c=
ache
>> 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_c=
ontents
>> 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. I=
f 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=3D1
>> apc.user_ttl =3D 30
>>
>> apc.user_ttl will decide how long the entry will remain inside the cache=
. =A0If
>> 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. =A0 =A0 Incl. =A0 =A0 Excl. =A0 =A0 =A0 Incl. =A0 =A0 =A0 Excl. =
=A0 =A0 Incl. =A0 =A0 =A0Name
>> User CPU =A0User CPU =A0Total LWP =A0 Total LWP =A0 Sys. CPU =A0Sys. CPU
>> =A0 =A0sec. =A0 =A0 =A0sec. =A0 =A0 =A0 =A0sec. =A0 =A0 =A0 =A0sec. =A0 =
=A0 =A0sec. =A0 =A0 =A0sec.
>> No Cache :
>> =A00.831 =A0 =A028.660 =A0 =A0 =A0 1.141 =A0 =A0 540.018 =A0 =A0 0.030 =
=A0 344.311
>> zif_file_get_contents
>> With Cache :
>> =A01.481 =A0 181.537 =A0 =A0 =A0 1.821 =A0 =A0 282.758 =A0 =A0 0.140 =A0=
 =A012.449
>> zif_apc_file_get_contents
>>
>>
>> User + System time before Caching =3D 372 seconds
>> User + System time after Caching =3D 193 seconds
>> Total time reduction in file_cache_contents =3D 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 apprec=
iate
>> 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
>