I often use micro & router so I decided to do benchmark. This benchmark made thanks to (@kenjis) PHP-Framework-Benchmark. I changed ab to awk, added to table "type of framework" and something else...
! Benchmark with help wrk
https://github.com/wg/wrk
This project attempts to measure minimum overhead (minimum bootstrap cost) of PHP frameworks in the real world.
So I think the minimum applications to benchmark should not include:
- cost of template engine (HTML output)
- cost of database manipulation
- cost of debugging information
Components like Template engine or ORM/Database libraries are out of scope in this project.
This is master
branch.
- Install a framework according to the official documentation.
- Use the default configuration.
- Don't remove any components/configurations even if they are not used.
- With minimum changes to run this benchmark.
- Set environment production/Turn off debug mode.
- Run optimization which you normally do in your production environment, like Composer's
--optimize-autoloader
. - Use controller or action class if a framework has the functionality.
Some people may think using default configuration is not fair. But I think a framework's default configuration is an assertion of what it is. Default configuration is a good starting point to know a framework. And I can't optimize all the frameworks. Some frameworks are optimized, some are not, it is not fair. So I don't remove any components/configurations.
But if you are interested in benchmarking with optimization (removing components/configurations which are not used), See optimize branch.
If you find something wrong with my code, please feel free to send Pull Requests. But please note optimizing only for "Hello world!" is not acceptable. Building fastest "Hello world!" application is not the goal in this project.
- CentOS Linux release 7.6.1810
- PHP 7.3.1
- Apache/2.4.6
These are my benchmarks, not yours. I encourage you to run on your (production equivalent) environments. (2019/01/27)
CentOS 7.6 my server
- Apache/2.4.6
- PHP 7.3.1
framework | requests per second | relative | peak memory | relative | files | type |
---|---|---|---|---|---|---|
no-framework | 11,742.54 | 19.7 | 0.41 | 1.0 | 1 | no-framework |
AltoRouter | 3,619.92 | 6.1 | 0.50 | 1.2 | 6 | router |
PHP-Router | 3,358.57 | 5.6 | 0.52 | 1.3 | 8 | router |
FastRoute | 2,463.59 | 4.1 | 0.55 | 1.3 | 15 | router |
flight | 1,660.40 | 2.8 | 0.68 | 1.6 | 15 | micro |
tipsy | 1,617.18 | 2.7 | 0.66 | 1.6 | 16 | micro |
limonade | 1,439.16 | 2.4 | 1.02 | 2.5 | 6 | micro |
siler-1.3 | 1,397.18 | 2.3 | 0.88 | 2.1 | 22 | micro |
klein.php | 1,271.65 | 2.1 | 0.78 | 1.9 | 20 | router |
bearframework | 1,065.35 | 1.8 | 0.94 | 2.3 | 22 | micro |
fatfree | 1,049.13 | 1.8 | 1.50 | 3.6 | 6 | micro |
Slim-3.x | 595.05 | 1.0 | 1.39 | 3.4 | 56 | micro |
macOS Mojave 10.14.2 my desktop
- Apache/2.4.34
- PHP 7.3.1 with Zend OPcache v7.3.1
framework | requests per second | relative | peak memory | relative | files | type |
---|---|---|---|---|---|---|
no-framework | 4,573.15 | 7.2 | 0.37 | 1.0 | 1 | no-framework |
AltoRouter | 2,617.56 | 4.1 | 0.47 | 1.3 | 6 | router |
PHP-Router | 2,417.23 | 3.8 | 0.47 | 1.3 | 8 | router |
FastRoute | 1,947.44 | 3.1 | 0.51 | 1.4 | 15 | router |
flight | 1,545.02 | 2.4 | 0.63 | 1.7 | 15 | micro |
tipsy | 1,410.26 | 2.2 | 0.61 | 1.6 | 16 | micro |
siler-1.3 | 1,330.79 | 2.1 | 0.77 | 2.1 | 22 | micro |
klein.php | 1,246.66 | 2.0 | 0.74 | 2.0 | 20 | router |
limonade | 1,193.01 | 1.9 | 1.00 | 2.7 | 6 | micro |
bearframework | 1,108.75 | 1.8 | 0.90 | 2.4 | 22 | micro |
fatfree | 1,062.73 | 1.7 | 1.44 | 3.9 | 6 | micro |
Slim-3.x | 631.79 | 1.0 | 1.31 | 3.5 | 56 | micro |
Note(1): This benchmarks are limited by wrk
https://github.com/wg/wrk performance.
Install source code as http://localhost/php-micro-router-framework-benchmark/:
$ git clone https://github.com/dejurin/php-micro-router-framework-benchmark.git
$ cd php-micro-router-framework-benchmark
$ bash setup.sh
Run benchmarks:
$ bash benchmark.sh
See http://localhost/php-micro-router-framework-benchmark/.
If you want to benchmark some frameworks:
$ bash setup.sh PHP-Router/ flight/ lumen/
$ bash benchmark.sh PHP-Router/ flight/ lumen/
I added below in /etc/sysctl.conf
# Added
net.netfilter.nf_conntrack_max = 100000
net.nf_conntrack_max = 100000
net.ipv4.tcp_max_tw_buckets = 180000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 10
and run sudo sysctl -p
.
If you want to see current configuration, run sudo sysctl -a
.
- PHP Framework Benchmark (@kenjis)
- moneyconvert
- wrk - Modern HTTP benchmarking tool
- PHP-Router (@dannyvankooten)
- FatFree (@phpfatfree)
- Flight
- Siler
- Tipsy
- Limonade
- AltoRouter
- FastRoute (@nikic)
- Bear Framework
- Klein.php
- Slim (@slimphp)
- Ham
- yolo
- mu