Benchmarking Phalcon PHP VS Slim Framework with OpCache VS Node.js
Phalcon PHP is a different kind of framework for PHP. Unlike most PHP frameworks that are just a collection of PHP files, Phalcon is a PHP module that is written in C/C++, with an API exposed to plain old PHP. This allows Phalcon, a fully featured framework, to run considerably faster than all other PHP frameworks, even micro-frameworks like Slim.
PHP 5.5 and up now includes a pretty powerful feature called OpCache. Typically any time you execute a PHP script the code you have written gets interpreted by the Zend engine into chunks of code called opcodes that are then executed by the Zend engine. This interpretation step adds some overhead to the speed at which PHP executes. However, using OpCache, the script is pre-interpreted, and the resulting opcodes are cached into memory. So when using OpCache, the execution time is limited to the time it takes the Zend engine to actually execute the opcodes.
I was curious as to how much better (if any) Phalcon performs over a traditional lightweight framework with OpCache turned on. So I decided to run some benchmark tests. I figured I’d throw Node.js into the mix as well to see it’s performance relative to high performing PHP frameworks. In this benchmark I implemented the Sequelize node ORM instead of using MongoDB in an attempt to keep DB and database abstraction parity with the PHP frameworks.
Setup Overview
Independant Variable: Scripting Framework
Dependant Variable: Mean response time
Controlled Variables: All tests run on same MySql database. All frameworks use fully featured ORM libraries for accessing MySQL. All tests use the same machine (2GB RAM 2 Core Processor digital ocean droplet). Testing was done with ApacheBench at 10000 requests with concurrency set to 10.
Results
I was surprised to see how much of a lead Phalcon maintained over even a micro PHP framework with opcache on. But Phalcon wasn’t much faster than Node’s Express framework. I’d be interested to see if Express+MongoDB could match Phalcon’s speed since Node and Mongo handle JSON output so well.
Here are the results visualized:
Raw Data
Phalcon PHP
[root@geoname ~]# ab -n 10000 -c 10 http://localhost/api/primary/4526992/ This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests
Server Software: Apache/2.4.10 Server Hostname: localhost Server Port: 80
Document Path: /api/primary/4526992/ Document Length: 357 bytes
Concurrency Level: 10 Time taken for tests: 18.919 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 5690000 bytes HTML transferred: 3570000 bytes Requests per second: 528.56 [#/sec] (mean) Time per request: 18.919 [ms] (mean) Time per request: 1.892 [ms] (mean, across all concurrent requests) Transfer rate: 293.70 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 0 Processing: 3 19 13.8 16 116 Waiting: 3 18 13.0 15 107 Total: 3 19 13.8 16 116
Percentage of the requests served within a certain time (ms) 50% 16 66% 21 75% 25 80% 28 90% 36 95% 45 98% 58 99% 67 100% 116 (longest request)
Slim Framework without OpCache (using Laravel’s Eloquent ORM)
[root@geoname conf.d]# ab -k -n 10000 -c 10 http://localhost/api/primary/4526992 This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests
Server Software: Apache/2.4.10 Server Hostname: localhost Server Port: 80
Document Path: /api/primary/4526992 Document Length: 349 bytes
Concurrency Level: 10 Time taken for tests: 147.294 seconds Complete requests: 10000 Failed requests: 0 Keep-Alive requests: 9908 Total transferred: 5815947 bytes HTML transferred: 3490000 bytes Requests per second: 67.89 [#/sec] (mean) Time per request: 147.294 [ms] (mean) Time per request: 14.729 [ms] (mean, across all concurrent requests) Transfer rate: 38.56 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 2 Processing: 25 147 51.8 144 648 Waiting: 25 147 51.8 144 648 Total: 25 147 51.8 144 649
Percentage of the requests served within a certain time (ms) 50% 144 66% 159 75% 168 80% 173 90% 194 95% 245 98% 308 99% 336 100% 649 (longest request)
Slim Framework with OpCache (using Laravel’s Eloquent ORM)
[root@geoname apache]# ab -k -n 10000 -c 10 http://localhost/api/primary/4526992 This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests
Server Software: Apache/2.4.10 Server Hostname: localhost Server Port: 80
Document Path: /api/primary/4526992 Document Length: 349 bytes
Concurrency Level: 10 Time taken for tests: 40.590 seconds Complete requests: 10000 Failed requests: 0 Keep-Alive requests: 9905 Total transferred: 5815830 bytes HTML transferred: 3490000 bytes Requests per second: 246.36 [#/sec] (mean) Time per request: 40.590 [ms] (mean) Time per request: 4.059 [ms] (mean, across all concurrent requests) Transfer rate: 139.92 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 2 Processing: 7 41 45.1 40 2584 Waiting: 7 41 45.1 40 2584 Total: 7 41 45.2 40 2586
Percentage of the requests served within a certain time (ms) 50% 40 66% 45 75% 48 80% 50 90% 54 95% 58 98% 65 99% 86 100% 2586 (longest request)
Node.js Express Framework
[root@geoname node]# ab -n 10000 -c 10 104.131.190.208:3000/api/primary/4526992 This is ApacheBench, Version 2.3 <$Revision: 1604373 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 104.131.190.208 (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests
Server Software: Server Hostname: 104.131.190.208 Server Port: 3000
Document Path: /api/primary/4526992 Document Length: 354 bytes
Concurrency Level: 10 Time taken for tests: 27.200 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 5440000 bytes HTML transferred: 3540000 bytes Requests per second: 367.65 [#/sec] (mean) Time per request: 27.200 [ms] (mean) Time per request: 2.720 [ms] (mean, across all concurrent requests) Transfer rate: 195.31 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 1 Processing: 14 27 9.6 23 113 Waiting: 14 27 9.6 23 113 Total: 14 27 9.6 23 113
Percentage of the requests served within a certain time (ms) 50% 23 66% 28 75% 31 80% 32 90% 37 95% 45 98% 57 99% 67 100% 113 (longest request)













