Caching file_get_contents output inside APC (Performance improvement).

From: Date: Mon, 26 Oct 2009 20:36:45 +0000
Subject: Caching file_get_contents output inside APC (Performance improvement).
Groups: php.pecl.dev php.apc.dev 
Request: Send a blank email to pecl-dev+get-6729@lists.php.net to get a copy of this message
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.

« previous php.pecl.dev (#6729) next »