Forums / Install & configuration / Tip: Use APC filters to optimize cache usage

Tip: Use APC filters to optimize cache usage

Author Message

Jani Tarvainen

Friday 26 November 2010 11:05:09 pm

APC is a great opcode cache for PHP that provides significant performance gains for eZ Publish and other PHP applications.

If you run a large eZ Publish installation with proper caching you might end up in a situation where your APC cache keeps filling up with eZ Publish cache files. You'd rather have the kernel, etc. code in the cache than HTML snippets.

Look into APC filters to manage which files are cached by APC and which are not: http://www.php.net/manual/en/apc.configuration.php#ini.apc.filters

something along the lines works for me:

 apc.filters = "-(.*/cache_siteaccess1/.*\.php)|(.*/cache_siteaccess2/.*\.php)" 

This could probably be further optimized, but it aint' broken.

--
http://ezpublish.fi/

Bertrand Dunogier

Saturday 27 November 2010 8:32:30 am

Very good advice !

Cheap, efficient. There are other caches you might be interested in:

  • anonymous user info cache
  • translation cache
  • expiry cache
  • wildcard cache ?

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Nicolas Pastorino

Saturday 27 November 2010 1:21:06 pm

I agree excellent piece of advice !
Have you tried the before/after performance test after applying it ?

Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Doug Brethower

Monday 29 November 2010 8:57:49 am

CentOS server with multiple virtual instances of eZ Publish running on one server.

Installed APC 3.0.19, got only 15 percent cache hits with default configuration and no apc.filters set.

Added to php.ini:

apc.filters = "-cache.*\.php"

This instantly boosted cache hits to 25 percent and noticeable speed improvement versus before APC install.

Surely more tweaking to be done, but very much thanks to Jani for the heads up!

Doug Brethower
Apple Certified Technical Consultant, Southwest, MO USA
http://share.ez.no/directory/companies/lakedata.net

Gaetano Giunta

Monday 29 November 2010 9:59:52 am

@Doug excellent idea, even though I'd normally go for putting as much stuff as you can in your APC cache.

But the best thing is: if you remove from the APC cache all the files generated by eZ, you can then simply

1. tell APC not to check the staleness of its cached files vs. timestamp of original pph files on the fs (apc.stat=0 in php.ini) and get a speed boost and IO pressure decrease on your fs (great if your install is eg. on NFS)

2. remember to clear APC cache by hand after every delivery of a new site update

Could you provide us with some numbers about page load times / reqs per sec. before and after the change?

One thing to note though: you might want to tune your templates, you might have cache-blocks that keep churning (use ggsysinfo to get a graph of the number of files-added-in-the-cache-per-minute on your install), as otherwise your apc cache hits should be much higher - f.e. the php files in the template cache should never expire, and be good candidates for APC caching.

Or you have just too little of shmem given to apc. What is your usage of it's allocated memory?

Going slightly OT: a lil' while ago I experimented with the best format to be ideally used for storing those caches that are basically data structures: plain php or json or serialized php.

The goals:

- try to use a format that is not cached by APC and friend by default, as it is basically memory wasting

- have the format that is both faster to load and using less memory for deserialization

It is to be noted that right now eZP uses all of those formats for different caches - picking a single format would also help in the overall goal of cleaning up cache management mechanics.

In the end my tests where not conclusive: depending on php/os version and presence or not of an accelerator the results changed.

But I'd be happy to pick them up again if anybody else is interested...

Principal Consultant International Business
Member of the Community Project Board

Carlos Revillo

Thursday 24 March 2011 10:15:17 am

"

2. remember to clear APC cache by hand after every delivery of a new site update

"

Hi Gaetano and all. Actually we're having some randomly perfomance problems in one of our developments. hosting company has pointed me to this topic.

about your reply, for 'new site update' i suppose you are talking about code updates right? (not content updates).

thanks in advance.

Gaetano Giunta

Thursday 26 May 2011 8:03:50 am

@Carlos: yes, I do talk of code updates, not content updates. The point is that you can do this iff php code generated as part of "content caches" is not stored in the apc cache...

Principal Consultant International Business
Member of the Community Project Board

eZ debug

Timing: Jan 17 2025 21:21:09
Script start
Timing: Jan 17 2025 21:21:09
Module start 'content'
Timing: Jan 17 2025 21:21:10
Module end 'content'
Timing: Jan 17 2025 21:21:10
Script end

Main resources:

Total runtime1.0666 sec
Peak memory usage4,096.0000 KB
Database Queries214

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 596.2969180.8125
Module start 'content' 0.00610.9639 777.1094813.5859
Module end 'content' 0.97000.0966 1,590.6953344.6406
Script end 1.0666  1,935.3359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3414210.0002
Check MTime0.00130.1243210.0001
Mysql Total
Database connection0.00070.068610.0007
Mysqli_queries0.977691.65612140.0046
Looping result0.00170.16142120.0000
Template Total1.044898.020.5224
Template load0.00170.156820.0008
Template processing1.043197.797820.5216
Template load and register function0.00020.014910.0002
states
state_id_array0.00060.059710.0006
state_identifier_array0.00090.081820.0004
Override
Cache load0.00160.1490570.0000
Sytem overhead
Fetch class attribute can translate value0.00130.123870.0002
Fetch class attribute name0.00100.0979120.0001
XML
Image XML parsing0.00360.340970.0005
class_abstraction
Instantiating content class attribute0.00000.0015130.0000
General
dbfile0.00370.3491520.0001
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 29
 Number of unique templates used: 10

Time used to render debug report: 0.0002 secs