Re: [APC-DEV] Caching file_get_contents output inside APC (Performance improvement).
[email protected] (Pierre Joye) Mon, 26 Oct 2009 22:14:05 +0100
| Newsgroups | php.pecl.dev,php.apc.dev |
|---|---|
| Message-ID | <[email protected]> |
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))) {
$data =3D file_get_contents($path);
my_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. B=
esides
> this APC provides API to cache user data into this mmap. There are many p=
hp
> apps which uses file_get_contents to read the static files. If APC can ca=
che
> 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_co=
ntents
> 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=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 f=
or
> 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 appreci=
ate
> any comments.
>
> Regards,
> Basant.
>
> --
> APC Development Mailing List (http://pecl.php.net/APC)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--=20
Pierre
http://blog.thepimp.net | http://www.libgd.org