After doing a lot of research about these technologies, and having found no decent/fresh benchmark with Phalcon (PHP) against Express (Node.js), I decided to do it on my own. I was also curious to see how Lumen can compete against Phalcon, so I decided to add the “micro-framework” to the competition. The purpose of this benchmark is to simulate how these stacks can compete against each other when building a real application.
I am not a real fan of benchmarking, and I am sure that Phalcon, Lumen or Express will expectedly handle any application that you will ever need to build, like 99% of the cases. However, Phalcon is known to be one of the fastest or even the fastest framework ever built in PHP, so this arouse my curiosity, how can it compete against a non blocking I/O environment, like Node.js.
- Phalcon 4.1 (Micro), PHP 7.4 + FPM, Nginx
- Express 4, Node.js 14 (LTS), PM2
- Lumen 8, PHP 8 + FPM (JIT is enabled), Nginx
Important to mention that I am using PHP 7.4 with Phalcon, because until today, there’s no compatible version with PHP 8.
The specifications of the REST API
I’ve created a simple application following the basic guidelines for each framework, that exposes 5 endpoints with different types of complexity.
- Simple Json Response, an endpoint which returns a simple JSON containing a simple string.
- Fibonacci Numbers, an endpoint which will calculate the first 10 000 fibonacci numbers.
- Binary Search, an endpoint which will create an array with 10 000 numbers, and then, will pick a random one to binary search on this array.
- Select 1 row from a DB table, an endpoint which will select a single row from a MySQL database table, using the WHERE operator.
- Select all rows from a DB table, an endpoint which will returns a complete list fetched from the database table.
I’ve used a simple table to execute these benchmarks, you can found the SQL script here. I’ve used MySQL server with the defaults configurations on each server.
The Server’s Specifications
I was also curious to see how each framework scales with higher hardware resources, so, I tested on 3 different types of server configurations created on DigitalOcean.
- 1 CPU, 2 GB of RAM, 10$ /month
- 2 CPU’s, 4 GB of RAM, 20$ /month
- 4 CPU’s, 8 GB of RAM, 40$ /month
How the tests were done
I am interested in knowing the number of requests per seconds each framework achieves on different server configurations, with 5 different types of computation that each endpoint will do, like mentioned before.
For testing, I’ve used the wrk (12 threads, 500 open connections, 30 secs) and ab (500 open connections until reach 20 000 requests) HTTP benchmark tool’s, I’ve made 3 tests for each endpoint, with wrk and ab (total of 6), and always picked the highest number, important to mention the numbers were always close with both tools, so we can assume the servers were stable.
These tests were made on a droplet created on DigitalOcean for this specific purpose. They are also on the same private network, which prevents possible problems related to latency.
The actual code of the Projects
You can find the code of every framework i’ve used to test here. I tried to maximize the performance of every framework, removing the extra code that was not necessary. I also took care of FPM configurations every time I scaled the hardware, following this article.
The results are grouped by each endpoint, and the analysis for how every framework scaled with higher hardware specifications.
Actually, I am impressed how Phalcon framework got close to Express results in some case scenarios, as you can see, the Lumen framework, which comes from his lovely parent Laravel, remains distant from Phalcon when compared to performance.
Do you have any suggestion to improve the veracity of these results? comment below, they’re more than welcome.