I am working on an application (Symfony 1.4 / Doctrine) that has some pages that are pretty heavy to load. One of these pages contains a very complex form with a lot of relations (embedded forms). The page does something like this: get all objects, create the forms (with the objects), render the forms.
This is resulting in loadtimes of approximately 1.5 seconds per page. MySQL doesn’t seem to be the bottleneck, doing the queries takes about 0.01 seconds. However, hydrating the results takes a lot more time: about 0.3 seconds. Creating and embedding all the subforms also takes a lot of time (0.5s). Rest of the time spend in regular Symfony/Doctrine methods. All of these times were found with Symfony timers and/or xdebug.
I hoped that I could speed up the process on my production server by using APC for opcode caching. So I installed APC, did some configurations (cache size = 400MB; max file size = 20MB, just to be sure), and finally benchmarked the application.
Without APC:
$ ab -n 100
Requests per second: 0.72 [#/sec] (mean)
Time per request: 1392.142 [ms] (mean)
Time per request: 1392.142 [ms] (mean, across all concurrent requests)
Transfer rate: 130.62 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 5 3.6 4 32
Processing: 1301 1387 258.0 1338 3549
Waiting: 1229 1315 258.2 1267 3475
Total: 1305 1392 258.0 1342 3553
With APC:
$ ab -n 100
Requests per second: 0.86 [#/sec] (mean)
Time per request: 1160.666 [ms] (mean)
Time per request: 1160.666 [ms] (mean, across all concurrent requests)
Transfer rate: 156.67 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 4 0.7 4 9
Processing: 1071 1156 164.1 1121 2337
Waiting: 1024 1104 164.3 1065 2286
Total: 1075 1161 164.1 1125 2341
There is a bit of improvement, but the results are quite disappointing. To be sure that APC was working well, I also benchmarked a Drupal website that is running on the same server. This almost doubled the requests/second for the Drupal website (from 4 pages/sec to 8 pages/sec)! So clearly APC is working correctly.
Does anybody have a clue what could be the cause of this lack of speedup? Has anyone done some benchmarks on a Symfony application with/without APC? I can find some claims on the internet of applications that doubles their requests/seconds, but all without benchmarks.
Opcode caching only speeds up the loading of the original classes. When much of the time the code loops through a database result, creating complex objects, APC alone won’t help.
Doctrine has support for caching Queries and results, however, caching in APC needs to be configured. See this URL: http://readthedocs.org/docs/doctrine/en/latest/en/manual/caching.html
Maybe you can use
apc_addto cache the forms after they are created. This has the risk of presenting stale data to the user, but maybe it’s worth it.To get more information why it’s taking so long, you should look into profiling with XDebug.