Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.3 #43

Merged
merged 30 commits into from
Aug 26, 2023
Merged

v2.3 #43

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7bba70b
Add apache dockerfile
joanhey Jul 28, 2023
c198c7c
Check if docker is installed
joanhey Jul 29, 2023
0d04c92
Add optional port input
joanhey Jul 29, 2023
8da746f
Add optional opcache in dockerfile
joanhey Jul 29, 2023
f9c0c9d
Remove numfmt in _functions.sh
joanhey Jul 29, 2023
43351a5
Add info to stop Apache
joanhey Jul 29, 2023
3fdaadb
By pass docker gateway
joanhey Jul 29, 2023
a238747
Delete 0
myaaghubi Aug 2, 2023
98e53de
Add date to `results.log`
myaaghubi Aug 10, 2023
ed3a6cc
Fix `show-table.sh` to pick the latest file
myaaghubi Aug 10, 2023
e5a4652
Fix `index.php` to pick the latest file
myaaghubi Aug 10, 2023
6cc1cd0
Change `-c|--clean` to `-f|--fresh` & fixes
myaaghubi Aug 10, 2023
15968c9
Changed to have a dir for each benchmark
myaaghubi Aug 11, 2023
1254496
`show-table.sh` moved to `results.sh`
myaaghubi Aug 11, 2023
2b2fd24
Update README.md
myaaghubi Aug 11, 2023
91a9ae7
Add Ability to define options & Add `-l | --list`
myaaghubi Aug 11, 2023
a217f5d
Add more options
myaaghubi Aug 11, 2023
a0486a5
Add one more option `-t | --top`
myaaghubi Aug 11, 2023
b3866c2
Add comparison between last two results on table
myaaghubi Aug 11, 2023
78100b0
No longer need it
myaaghubi Aug 11, 2023
8d45efd
Add `-c|--compare` to specify target
myaaghubi Aug 11, 2023
e2c81eb
Fixes with multiple results
myaaghubi Aug 11, 2023
a9e36d5
Merge pull request #32 from joanhey/docker-apache
myaaghubi Aug 24, 2023
71babab
Rename `apache.sh`
myaaghubi Aug 24, 2023
9713999
Update README.md
myaaghubi Aug 24, 2023
e67f106
Move `benchmark.config` to `config`
myaaghubi Aug 24, 2023
a5bf053
Move `benchmark.config` to `config`
myaaghubi Aug 24, 2023
a6f8bb5
Update README.md
myaaghubi Aug 24, 2023
9d1eb06
Some fixes
myaaghubi Aug 26, 2023
49d94a7
Fix CI 4.3 fail
myaaghubi Aug 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .docker/apache.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM php:8.2-apache

RUN apt-get update \
&& apt-get install -y libicu-dev

RUN mkdir /var/www/html/PHP-Frameworks-Bench

# Need it in a lot of frameworks
RUN docker-php-ext-install intl

# Optional opcache (recommended)
#RUN docker-php-ext-install opcache

ENV PORT 80
ENTRYPOINT []
CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground
1 change: 0 additions & 1 deletion 0

This file was deleted.

101 changes: 69 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PHP Frameworks Bench
[![Test PHP benchmark](https://github.com/myaaghubi/PHP-Frameworks-Bench/actions/workflows/test.yml/badge.svg)](https://github.com/myaaghubi/PHP-Frameworks-Bench/actions/workflows/test.yml) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/myaaghubi/PHP-Frameworks-Bench?color=purpol) ![GitHub](https://img.shields.io/github/license/myaaghubi/PHP-Frameworks-Bench?color=green)


This project attempts to measure the minimum overhead (minimum bootstrap cost) of PHP frameworks in the real world.

So I think the minimum should not include:
Expand All @@ -16,9 +17,11 @@ Benchmarking on components like template engines or ORM/Database libraries is ou
- [Benchmarks](#benchmarks)
- [Latest](#latest)
- [OPCache On/Off](#opcache-on)
- [Benchmarking Policy](#benchmarking-policy)
- [How to Benchmark](#how-to-benchmark)
- [Docker](#docker)
- [Commands](#commands)
- [Benchmarking Policy](#benchmarking-policy)
- [Add Your Framework](#add-your-framework)
- [Donate](#-donate)
- [References](#references)
- [License](#license)
Expand All @@ -41,12 +44,12 @@ Benchmarking on components like template engines or ORM/Database libraries is ou

#### Results (2023/5/15)

These are my benchmarks, not yours. **I encourage you to run on your (production equivalent) environments.**
These are my benchmarks, not yours. **I encourage you to run on your -production equivalent- environments.**

![Benchmark Results Graph Throughput](screenshots/php-frameworks-bench-throughput.png)
![Benchmark Results Graph Memory](screenshots/php-frameworks-bench-memory.png)
![Benchmark Results Graph Execution Time](screenshots/php-frameworks-bench-exectime.png)
![Benchmark Results Graph Included Files](screenshots/php-frameworks-bench-includedfiles.png)
![Frameworks Benchmark Results Graph Throughput](screenshots/php-frameworks-bench-throughput.png)
![Frameworks Benchmark Results Graph Memory](screenshots/php-frameworks-bench-memory.png)
![Frameworks Benchmark Results Graph Execution Time](screenshots/php-frameworks-bench-exectime.png)
![Frameworks Benchmark Results Graph Included Files](screenshots/php-frameworks-bench-includedfiles.png)

|framework |requests per second (rps)|relative (rps)|peak memory|relative (mem)|
|-------------------|------------------------:|-------------:|----------:|-------------:|
Expand All @@ -71,29 +74,13 @@ These are my benchmarks, not yours. **I encourage you to run on your (production


#### OPCache On
Check out the video for more information.
[![Results with OPCache On/Off & How to add your framework](http://img.youtube.com/vi/Dk8YHQZ6jfY/0.jpg)](http://www.youtube.com/watch?v=Dk8YHQZ6jfY)


## Benchmarking Policy

This is for the `main` branch.

* Frameworks installed via `composer` according to their official documentation.
* Used the default configuration.
* Considering the minimum changes on frameworks to run the benchmark.
* Didn't remove any components/configurations even if there is no use for them.
* We have a `controller` class to get the `Hello World` for each, based on the default template of each framework.
* Turned off the `debug` mode and set the environment to `production` mode.
* Considered general optimization for the production environment, like `--optimize-autoloader` for the composer.

Some frameworks are optimized more than others, so some people may think using default configuration is not fair. The dept of optimizing a framework depends on the experiences of the developer too, so it's the rabbit hole and there is no point in it. I think the default configuration of frameworks is a good starting point to get ranking.

If you find something wrong in my code, feel free to send a PR. But please note optimizing for the "Hello World" is not acceptable! Building the fastest `Hello World` application is not the goal of this project.


## How to Benchmark

If you want to have benchmarks on `PHP extension frameworks` like `Phalcon`, you need to install the extension first based on its own documentation.
If you want to have benchmarks on `PHP extension frameworks` like `Phalcon`, you need to install the extension first, based on its own documentation.

1- Download & Setup:

Expand All @@ -104,7 +91,7 @@ $ git clone https://github.com/myaaghubi/PHP-Frameworks-Bench.git
$ cd PHP-Frameworks-Bench

# optional
$ nano benchmark.config
$ nano config

# run the setup & follow the progress
$ yes | bash setup.sh
Expand All @@ -115,29 +102,59 @@ $ yes | bash setup.sh
```bash
$ bash check.sh
# bash check.sh -t pure-php
# /------- pure-php: checking... done.
# pure-php
```

3- Run benchmarks:

```bash
# bash benchmark.sh --help
$ bash benchmark.sh
```

4- Check the results:
- web:

<http://localhost/PHP-Frameworks-Bench/>
<http://127.0.0.1/PHP-Frameworks-Bench/>

- terminal:
```bash
# bash results.sh --help
bash results.sh
```
bash show-table.sh
```


## Docker

Results with docker may not be reliable but in a situation you can use it like:

1- Change the `base` in `config` on the right port(`8080` considered):

```ini
base="http://127.0.0.1:8080/PHP-Frameworks-Bench"
...
```

2- Run/download the docker:

```bash
$ bash docker-apache.sh
```

3- Run the benchmark:

```bash
# run it in another terminal
$ bash benchmark.sh
```


## Commands

```bash
# use bash benchmark.sh --help
$ bash benchmark.sh -f -rapache -t pure-php

# run composer update for frameworks
$ bash update.sh

Expand All @@ -149,27 +166,47 @@ $ bash clean.sh
# clear the cache of frameworks
$ bash clear-cache.sh

# show the results of the last benchmark
$ bash show-table.sh
# show the results table
$ bash results.sh
```

To specify frameworks, put them with `-t ...` after each command:

```bash
# supported for `setup.sh`, `benchmark.sh`, `update.sh`, `clean.sh`, and `clear-cache.sh`
# bash benchmarks.sh --help -h
# bash benchmarks.sh --help
$ bash benchmark.sh -t laravel-10.0/ slim-4.11/ ...
...
```


## Add Your Framework
Check out the [Benchmarking Policy](#benchmarking-policy), to get more information watch the video [OPCache On/Off](#opcache-on).


## Benchmarking Policy

* Use `composer` to install frameworks according to their official documentation.
* Use the default configuration.
* Minimum changes on frameworks to have benchmarks.
* Don't remove any components/configurations even if there is no use for them.
* Include a `controller` class to get the `Hello World!` for each, based on the default template of each framework for `controllers`.
* Turn off the `debug` mode and set the environment to `production` mode.
* General optimization for the production environment, like `--optimize-autoloader` for the `composer`.

Some frameworks are optimized more than others, so some developers may think using default configuration is not fair. The dept of optimizing a framework depends on the skills/experiences of the developer too, so it's the rabbit hole and nonsense for ranking. Please **note** optimizing for the `Hello World` is not acceptable! Building the fastest `Hello World` application is not the goal of this project. I think the default configuration of frameworks is a good starting point to have a ranking.

If you find something wrong in my code, feel free to send a `PR`.


## 🍔 Donate
Don't forget to donate if you find it useful ☕ 🍺 🍸 🍔

ETH: 0x0ADd51D6855d2DF11BB5F331A3fa345c67a863b2

![Ethereum](screenshots/ethereum.jpg?raw=true "Ethereum")


## References
Note: This project is based on
[php-framework-benchmark](https://github.com/kenjis/php-framework-benchmark), thanks to [Kenjis](https://github.com/kenjis). It is very old and abandoned, so I decided to split it from the origin and update it separately.
Expand Down
7 changes: 3 additions & 4 deletions base/_functions.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
benchmark () {
fw="$1"
url="$2"
output_wrk="output/$fw.wrk.log"
output="output/$fw.output"
output_wrk="output/$dir_datetime/$fw.wrk.log"
output="output/$dir_datetime/$fw.output"

# check out the appropriate response is reachable
url_status=$(bash check.sh -t "$fw")
Expand Down Expand Up @@ -40,8 +40,7 @@ benchmark () {

rps=`grep "Requests/sec:" "$output_wrk" | tr -cd '0-9.'`

echo "rps: "
numfmt --g "$rps"
echo "rps: $rps"

# to make a small gap between the WRK and CURL
sleep 1
Expand Down
35 changes: 10 additions & 25 deletions base/hello_world.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,21 @@

cd `dirname $0`
. ./_functions.sh
. ../benchmark.config
. ../config

bm_name=`basename $0 .sh`

results_file="output/results.$bm_name.log"
check_file="output/check.$bm_name.log"
error_file="output/error.$bm_name.log"
url_file="output/urls.log"
bn_name=`basename $0 .sh`

cd ..

if [ -f "$results_file" ]; then
echo "moving $results_file to $results_file.old"
mv "$results_file" "$results_file.old"
fi

if [ -f "$check_file" ]; then
echo "moving $check_file to $check_file.old"
mv "$check_file" "$check_file.old"
fi
mkdir -p output

if [ -f "$error_file" ]; then
echo "moving $error_file to $error_file.old"
mv "$error_file" "$error_file.old"
fi
export dir_datetime=`date +%y-%m-%dT%H-%M-%S`
mkdir output/$dir_datetime

if [ -f "$url_file" ]; then
echo "moving $url_file to $url_file.old"
mv "$url_file" "$url_file.old"
fi
results_file="output/$dir_datetime/results.log"
check_file="output/$dir_datetime/check.log"
error_file="output/$dir_datetime/error.log"
url_file="output/$dir_datetime/urls.log"

phpc=`curl -s "$base/libs/php_config.php"`
echo "/------- PHP Config -------/"
Expand All @@ -52,7 +37,7 @@ do
# continue
# fi

if [ "$param_clean" = true ]; then
if [ "$param_fresh" = true ]; then
bash clean.sh
bash setup.sh -t "$fw"
fi
Expand Down
11 changes: 9 additions & 2 deletions base/option_target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function showHelp()
{
cat << HEREDOC

Usage: bash check.sh [-t pure-php/ slim-*]
Usage: bash check.sh [-t pure-php slim-*]

Optional Arguments:
-h, --help Show this help message and exit
Expand All @@ -30,6 +30,7 @@ IFS=';'
params=(`php ./libs/strreplace.php " -" ";-" " ${paramsin}"`)
IFS=$oldIFS

init_benchmark=true
for option in "${params[@]}"
do
case "$option" in
Expand All @@ -41,13 +42,19 @@ do
fi
;;
-h|--help)
init_benchmark=false
showHelp;
;;
""|" ")
;;
*)
init_benchmark=false
echo "\"${option}\" not available"
exit 1
;;
esac
done
done

if [ "$init_benchmark" = false ]; then
exit 1
fi
2 changes: 1 addition & 1 deletion base/show_fw_array.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cd `dirname $0`
cd ..

. ../benchmark.config
. ../config

# include framework list
targets="$frameworks_list"
Expand Down
Loading