Archive for the ‘Performance’ Category

Performance check of CakePHP1.3.11 and CakePHP2beta

Wednesday, July 27th, 2011

CakePHP1.3.11 and CakePHP2beta  released today. I appreciated great work of the CakeTeam.
CakePHP 1.3.11 and 2.0.0-beta released

CakePHP2 introduces lazy loading and some great futures. I’m interested in how CakePHP2 faster than CakePHP1.3, so I compared both performance.
I know CakePHP2 still beta release, maybe it will be faster more and more until the final release.

Measurement Tool
I use the Siege(measurement tool) to measure throughput and the XHPref to measure the number of functaion calls.
Before this test, I tried apache ab tool to measure throughput, but it doesn’t work well. Because it sends the request as HTTP/1.0, Cake2 sends the response as HTTP/1.1.  The ab waits a few seconds for  connection close request.

Server Spec
Server: Dell SC440 Pentium Dual  CPU  E2180  @ 2.00GHz / 2G Memory / SATA HDD
OS: Ubuntu11 64bit
PHP 5.3.5 with APC
Apache 2.2.17

Step
I ran the Siege on same server. Siege option is “siege -b -c 10 -t 3S”, it means concurrency 10, access to the server in 3 seconds.
I know it’s better to run the Siege on another host, but it slightly difficult for me to prepare 2 hosts. This test only compare CakePHP1.3 and Cake2beta on same environment.

SampleApps
I prepare the sample apps of Cake1.3 and Cake2. It’s very simple code made by bake.
Here is the code.
https://github.com/ichikaway/CakePHP-PerformanceCheckSample


Database

I prepare the posts table which has 25,000 records.


Result

Target action is PostController/index which is using pagination.

Cake2beta & Cakephp2.0.2

 Siege:  40 trans/sec
xhpref: 50msec, 11790calls


CakePHP1.3.11

Siege: 29 trans/sec
xhpref: 66msec, 16,931calls

Conclusion
Cake2beta and 2.0.2  are  30% faster than CakePHP1.3.10 and reduces 5000 function calls. Awesome!
I guess performance gap is wider on the apps using some DB relations and models.


Extra
The result of XHpref on CakePHP2 beta. It shows CakeRoute cost is high.  I guess the sample app are using paginator helper, it calls Router class a lot to make the URLs( sort, page number, etc)
The call-graph can be clicked to see original size.

xhpref-list of Cake2 beta

callgraph-cake2beta

How to control a cakephp cache duration

Wednesday, October 7th, 2009

I’m using CakePHP1.2.5.

Cache is very powerful function for web pages using heavy SQL queries. If you use the CakePHP default Cache, you can see cache files in the app/tmp/cache directory.

I want to use the Cake Cache function at many points of my system and set different cache duration.

Firstly, check the core.php for using Cache.

//in core.php
Cache::config('default', array('engine' => 'File'));

This is a sample script using cache function, duration is 1 minute.

class PostController extends AppController {

var $uses = array('Post');

function index() {

$return_data = null;
Cache::set(array('duration' => '+60 seconds'));
if( ($return_data = Cache::read('PostController-index') ) === false ){

$return_data = $this->Post->find('all');
Cache::set(array('duration' => '+60 seconds'));
Cache::write('PostController-index' , $return_data);
}

$this->set('data',$return_data);
}
}

If there is no cache file(PostController-index),get DB data with the Post model and create cache file with its result. Array data is serialized.
You access same page within 1 minute, cake read cache file(PostController-index)
and return it insted of getting data from the Post model.

Key point is to use Cache::set() before each Cache::read and Cache::write(), we can change cache duration in each point.
http://book.cakephp.org/view/773/Cache-set

Be careful setting cache file name without overlap at each point. I recommend the rule, Class name + function name + parameter.

BTW, we can set Cache::config parameter in Cache::read() and Cache::write().
http://book.cakephp.org/view/766/Cache-read
http://book.cakephp.org/view/767/Cache-write
So, we can define multiple cache config as follow and use it each cache point.

//in core.php
Cache::config('default', array('engine' => 'File'));
Cache::config('onemin', array('engine' =>'File','duration'=> 60,));
Cache::config('onehour', array('engine' => 'File','duration'=> 3600,));
Cache::read('PostController-index', 'onemin')
Cache::write('PostController-index' , $return_data,'onemin');