REST API benchmark Phalcon, Lumen (PHP) vs Express (Node.js)

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.

The Specifications

  • 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

  1. Simple Json Response, an endpoint which returns a simple JSON containing a simple string.
  2. Fibonacci Numbers, an endpoint which will calculate the first 10 000 fibonacci numbers.
  3. 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.
  4. Select 1 row from a DB table, an endpoint which will select a single row from a MySQL database table, using the WHERE operator.
  5. 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

  • 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

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

Benchmark Results

Simple json response results
Fibonacci numbers computation results
Binary search computation results
Selecting one row from database table results
Selecting all rows from database table results

Conclusions

Do you have any suggestion to improve the veracity of these results? comment below, they’re more than welcome.

Software Developer, trying to learn more every day.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store