whitewashing.de

Benchmark and Optimize Zend Framework Performance

28. August 2008

In the fall of Rasmus presentation (Simple is Hard) on FrOSCon I tried to optimize Zend Frameworks performance a little bit. There has also been a little discussion on the Zend Framework Mailing List on this topic.

I haven't changed great parts of the code or anything, I just benchmarked how different global include strategies affect the overall performance of my blog software written with help of the ZF. The following include strategies were tested (I've used the Zend Framework 1.6 RC2 package for all of them):

  1. Zend_Loader Autoload, Default PHP Include Path
  2. Zend_Loader Autoload, Swapped Include Path
  3. ZF 1.6 RC2 stripped from all "require_once" dependancies, Zend_Loader Autoload, Swapped Include Path
  4. ZF 1.6 RC2 stripped from all "require_once" dependancies, no autoload, used inclued to find file dependancies and require (not _once) them all on startup.

To strip all the require_once from the Zend Framework source code, i built a little script to do that for me. For the last test I wrote a little script that used the inclued_get_data() function to built a correct dependancy tree for all includes. I have put each configuration of my Zend Framework install 30 seconds under siege with 5 concurrent requests. I have rerun all tests with APC and without APC.

Results without APC

Include Strategy Response time Trans/sec Performance %
Autoload, default include path 0.20 24.65 100%
Autoload, swapped include path 0.19 26.83 95%
Autoload, ZF w/o require_once 0.17 29.27 85%
No-Autoload, require up front 0.16 31.82 80%

You can see that each step makes a ZF application run faster and that the full optimization with requiring all scripts up front is about 20% faster than the default configuration.

Results with APC

Include Strategy Response time Trans/sec Performance %
Autoload, default include path 0.11 45.76 100%
Autoload, swapped include path 0.09 53.05 81,81%
Autoload, ZF w/o require_once 0.08 60.90 72,72%
No-Autoload, require up front 0.07 73.99 63,63%

Turning APC on gives a boost of about 50% to your application no matter what include strategy you are following (so there is excuse not using APC). But switching between different include strategies still makes a huge difference in performance. Percentage-wise this is a larger difference than without APC. Requiring all dependend scripts up front takes only about 63% of the default configuration time, which can make a major difference on any production server.

In an application knowing which includes of the Zend Framework will be needed on each request is difficult, since different helpers and classes might be needed based on which url is requested. It maybe a good practice to just include all the classes that might be needed. If this is a job to hard to do you can still get lots of performance gain out of your application by fixing the include path, using Zend Loaders Autoload and stripping all require_once calls from all of the Zend Framework files.

:: Category: PHP, Comments (4)

Tags for this Article

Comments (4)

We were recently comparing the performance of two internal projects; one that required most (if not all) files up front while the other required_once'd them as needed. Interestingly, we saw worse performance when requiring up front -- but it turned out that we were running out of shared memory in XCache. So, perhaps a word of advice: if you include/require everything you might possibly need up front, make sure you have enough memory for it all! :) User: andrew - Date: 2008/09/08 23:33
I think you should do a s/inclued/include/gi on this article... =)

Anyways, this seems quite interesting. I wonder if ZF should remove all the require_once's inside the files and move to just autoload based including? It would seem that would be the second fastest version, based on your tests. User: jani - Date: 2008/09/09 09:08
"inclued" is the name of the PECL extension that remembers all the file dependancies. User: beberlei - Date: 2008/09/11 12:55
I find it really interesting that you managed to gain as much as 7 requests per second stripping the require_once calls.

I have made changes to my include path and I am using APC, stripping all the require_once calls in my ZF 1.6.1 library I gained absolutely nothing.

What version of PHP are you running?

My tests were made on CentOS with PHP 5.2.6 and latest APC (3.0.19). User: goran juric - Date: 2008/10/11 11:47

Post A Comment

 
 
 
 
::Back To The Top