APC/XCACHE

49 views
Skip to first unread message

Richard Ellis-Braithwaite

unread,
May 25, 2012, 4:39:04 AM5/25/12
to agile-too...@googlegroups.com
Hi all,

I've been trying opcode caches like apc/eaccelerator/xcache/etc. for many years now but have been unsatisfied with their instability, often causing apache/fastcgi crashed under heavy load (reproducible with apache benchmark 1000 concurrent requests).

It's only the latest version of xcache and php5.4 with the setting "xcache.readonly_protection = On" in php.ini that has managed not to crash so far under heavy load, so I've investigated how much more performance I can get out of atk4 by modifying some of the core functions to store things in the variable cache.

Here are some apache benchmark results (500 requests, concurrency: 10 requests) with php5.4 on a windows pc (core2duo 2.4ghz cpu, mechanical HDD) for a page with an mvcform.

No xcache enabled: 12.54 requests per second, a mean request time of 797ms and max request time of 1861ms.
With xcache enabled I get 13.9 requests per second, a mean request time of 718ms and a max request time of 1522ms.
With xcache enabled and by caching the parsed template in the xcache memory cache (SMLite->template, not SMLite->tags) as well as the class sourcecode that pathfinder->loadclass includes I get 20.43 requests per second, a mean request time of 491ms and a max request time of 1073ms.

So, by doing just 2 small tweaks to 2 classes (SMLite and PathFinder) it is possible to nearly double the performance of atk4. When concurrency is higher and IO bottlenecks caused by class includes and template parsing get more limiting, the performance well exceeds double. I'm not checking for filemtime on the cache keys so at the moment you have to clear the xcache variable cache if you change your template or source code, but this typically doesn't happen on a production server. I will make checking if the file has been changed an option later, but for me this isn't required.

I tested with APC and I got similar results, but it's not as reliable for me on windows so I chose xcache - but have written the code to detect either opcode cache.

For future performance improvements, I looked at atk's performance with xdebug and I found that around 30% of the processing time is taken building the template tags, but since these are dynamic it's hard to cache these as simply as you can the parsed template and class files.

Do you want me to share the source code of these files?
Perhaps we could make a variable cache class in atk which is implementation agnostic and will also allow the user to store things like dsql results?

Thanks

Romans Malinovskis

unread,
May 25, 2012, 9:41:03 AM5/25/12
to agile-too...@googlegroups.com

Hi all,

I've been trying opcode caches like apc/eaccelerator/xcache/etc. for many years now but have been unsatisfied with their instability, often causing apache/fastcgi crashed under heavy load (reproducible with apache benchmark 1000 concurrent requests).

It's only the latest version of xcache and php5.4 with the setting "xcache.readonly_protection = On" in php.ini that has managed not to crash so far under heavy load, so I've investigated how much more performance I can get out of atk4 by modifying some of the core functions to store things in the variable cache.

Here are some apache benchmark results (500 requests, concurrency: 10 requests) with php5.4 on a windows pc (core2duo 2.4ghz cpu, mechanical HDD) for a page with an mvcform.

No xcache enabled: 12.54 requests per second, a mean request time of 797ms and max request time of 1861ms.
With xcache enabled I get 13.9 requests per second, a mean request time of 718ms and a max request time of 1522ms.
With xcache enabled and by caching the parsed template in the xcache memory cache (SMLite->template, not SMLite->tags) as well as the class sourcecode that pathfinder->loadclass includes I get 20.43 requests per second, a mean request time of 491ms and a max request time of 1073ms.

So, by doing just 2 small tweaks to 2 classes (SMLite and PathFinder) it is possible to nearly double the performance of atk4. When concurrency is higher and IO bottlenecks caused by class includes and template parsing get more limiting, the performance well exceeds double. I'm not checking for filemtime on the cache keys so at the moment you have to clear the xcache variable cache if you change your template or source code, but this typically doesn't happen on a production server. I will make checking if the file has been changed an option later, but for me this isn't required.
Hi Richard


That’s some awesome work. Can you also look into atk4/tools/mkbundle.sh, which is designed to collect all the ATK classes into a single file. I haven’t done much tests, but it might be better for you. Pack all the essential classes into a bundle, include it from index.php. The add() method will not attempt to load classes if they are already loaded. 


I tested with APC and I got similar results, but it's not as reliable for me on windows so I chose xcache - but have written the code to detect either opcode cache.

For future performance improvements, I looked at atk's performance with xdebug and I found that around 30% of the processing time is taken building the template tags, but since these are dynamic it's hard to cache these as simply as you can the parsed template and class files.

I was in the process of rewriting SMLite. It does manual parsing with sub-string searches. I was able to speed it up significantly with some smart regular expressions, but i didn’t manage to get it 100% compliant. You can see my work in atk4/lib/GiTemplate.php file. There was a problem with matching the closing template brackets I think, but I’ll need to get back to it. 

Possibly if we save the $template->template array (tags => chunks) and only perform re-indexing when these are loaded, it would also speed things up as no parsing would be necessary.

Do you want me to share the source code of these files?

Certainly. If you make a compatible parser class, It should be possible to “switch” default template parser of Agile Toolkit to the one you have optimized.

Perhaps we could make a variable cache class in atk which is implementation agnostic and will also allow the user to store things like dsql results?

I would prefer caching to be on a model level. Suppose you define a model which can retrieve data in 3 major ways:

 1) using dsql queries as it does now
 2) using JSON API request to another instance of Agile Toolkit
 3) load data from cache through Controller. This will bypass query creation and loads data directly into $model->data, standard behavior of Model.

Automated caching on a model level probably is a bit too dangerous, it will conflict with flexibility.

Regards,
Romans

Thanks


--
FYI: If amount of emails you receive from this group is too much - switch to "Digest" mode. You'll receive no more than 1 email per day.
 
To post to this group, send email to
agile-too...@googlegroups.com
 
To unsubscribe and view archive:
http://groups.google.com/group/agile-toolkit-devel?hl=en
 
To download Agile Toolkit, visit:
http://agiletoolkit.org/

Reply all
Reply to author
Forward
0 new messages