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

Multiple stacks #35

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
88ce5eb
Added initial docker stacks to be able to share benchmarking environm…
motin Dec 9, 2015
f069974
Storing results separately for each stack
motin Dec 9, 2015
93028ee
Framework changes necessary for all listed frameworks to run and outp…
motin Dec 9, 2015
a988715
Ability to check results stack by stack
motin Dec 9, 2015
8d10688
Include error log on results page
motin Dec 9, 2015
72fece1
Do not bail if error log happens to be empty after a run
motin Dec 9, 2015
be9c180
Results for the frameworks that actually run in the various stacks
motin Dec 9, 2015
df036ff
Re-enabled "no-framework" so that relative results can be compared ac…
motin Dec 9, 2015
79c2e76
Synced $output_dir usage
motin Dec 9, 2015
10178e5
Graphs across stacks are now comparable
motin Dec 9, 2015
0b93772
Removed comment proven to be wrong + non-altering code
motin Dec 10, 2015
8316f27
Reversed output_data require-refactoring
motin Dec 10, 2015
51c2493
Requiring libs/output_data based on env var
motin Dec 10, 2015
9907bbf
A single framework list to maintain
motin Dec 10, 2015
eb5ecbf
Using headers to output benchmark data (solved Content-Length curl is…
motin Dec 10, 2015
4a64560
Only calculate output data if specifically requested (fixes https://g…
motin Dec 10, 2015
b3b63ff
Restored list as it was before this pr
motin Dec 10, 2015
57dcaa7
Only exit on failure during development
motin Dec 10, 2015
4c5bb54
Restored parse results
motin Dec 10, 2015
7afc5c0
Preventing division by zero when calculating relative results
motin Dec 10, 2015
c74eeb8
Not using getallheaders() since it is not available in PHP 7 when usi…
motin Dec 10, 2015
8083565
Updated results
motin Dec 10, 2015
599856d
HTML-escaping error log on results page
motin Dec 10, 2015
5517da4
Docker-related parts of readme to separate file
motin Dec 10, 2015
5611c2b
Added placeholder for other results
motin Dec 10, 2015
8f75cbc
Activated opcode cache
motin Dec 10, 2015
54f5768
Including all frameworks despite stack (so that the resulting graphs …
motin Dec 10, 2015
9720d47
Updated results, including also in readme
motin Dec 10, 2015
d8abdcf
Added script to run all benchmarks against all docker stacks
motin Dec 10, 2015
c342017
Added note about source files for the used docker images
motin Dec 10, 2015
0ddaf5a
Adjusted working directories for docker stack services
motin Dec 10, 2015
19d8bd7
Docker stacks use /php-framework-benchmark/ sub-directory as well
motin Dec 10, 2015
b4d0e02
Reversed changes that were made to support requests without the php-f…
motin Dec 10, 2015
0f210a6
Added docker results export script
motin Dec 10, 2015
c41f14c
Zero out incomplete results and only allow valid results for enabled …
motin Dec 10, 2015
22a0569
Updated docker stack results
motin Dec 10, 2015
84842c3
Moved parameters for cross-stack graph consistency to query string
motin Dec 10, 2015
e720dd1
Including graphs to current results (including "no-framework")
motin Dec 10, 2015
e171242
Moved docker-related shell scripts to docker/bin/
motin Dec 11, 2015
4e137a5
Reversed usage of php_framework_benchmark_path
motin Dec 11, 2015
9861949
Added docker-compose build command to readme to ensure that all depen…
motin Dec 11, 2015
d9af4ae
Removed docker stack info from main readme
motin Dec 11, 2015
1ebe534
Updated show_fw_array.sh to use list.php directly
motin Dec 11, 2015
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/nbproject/
/output/
vendor/
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,70 @@ If you want to see current configuration, run `sudo sysctl -a`.
</VirtualHost>
~~~

## Benchmarking using the supplied Docker Stack

Use the supplied Docker Stack in order to automatically set up the following benchmarking environments:

* Ubuntu 15.04 64bit (Docker)
* Nginx 1.7.12
* PHP-FPM 5.6.4
* Zend OPcache 7.0.4-dev
* PhalconPHP 2.0.9
* PHP-FPM 7.0.0
* Zend OPcache 7.0.6-dev
* PhalconPHP 2.0.9
* HHVM 3.10.1

By sharing underlying software stacks, the benchmark results vary only according to the host machine's hardware specs and differing code implementations.

### Getting Started

If running locally, install [Docker Toolbox](https://www.docker.com/docker-toolbox).

Clone the source code:
~~~
git clone https://github.com/kenjis/php-framework-benchmark.git
cd php-framework-benchmark
~~~

Cd into the docker directory of this repo and make sure that docker toolbox is available:
~~~
cd docker
eval "$(docker-machine env default)"
~~~

Start the Nginx/PHP server stacks:
~~~
docker-compose up -d
~~~

Start the supplied docker shell from within this repository's `docker` folder:
~~~
docker-compose run shell
~~~

Run the set-up script:
~~~
sh setup.sh
~~~

Run benchmarks against each stack:
~~~
stack=docker_nginx_php_5_6_4 sh benchmark.sh
stack=docker_nginx_hhvm_3_10_1 sh benchmark.sh
stack=docker_nginx_php_7_0_0 sh benchmark.sh
~~~

### Check the results

To see the results graph, run the following script from outside the docker shell, from the repository root:

~~~
bin/docker-urls.sh
~~~

It echoes URLs, which you should open up in your browser.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this. I don't need it. I don't maintain the results of Docker.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not primarily for you :) It is for everyone that easily wants to run their own benchmarks. Instead of having to set-up several server environments, compile php extensions and configure their own server software to run all the different framework, they can instead simply install docker toolbox and be running within minutes.

I will remove the change from this PR in hope that you will consider this approach in the future: #41

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark results in Docker do not matter unless you or someone deploy using it.

Is your production environment Docker on Mac OS X? If not, the benchmark results might mislead you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My production environment is Docker in AWS instances and it is trivial to run the benchmarks as well when dealing with Docker stacks. Let's discuss in #41

## References

* [Aura](http://auraphp.com/) ([@auraphp](https://twitter.com/auraphp))
Expand Down
2 changes: 1 addition & 1 deletion aura-2.0/web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
);
$kernel();

require $_SERVER['DOCUMENT_ROOT'].'/php-framework-benchmark/libs/output_data.php';
echo require dirname(__FILE__).'/../../libs/output_data.php';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to echo? And why do you have to remove $_SERVER['DOCUMENT_ROOT']?

I hope the code exactly the same for all frameworks.

2 changes: 1 addition & 1 deletion bear-0.10/bootstrap/contexts/prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//
OK: {
$app->response->setResource($app->page)->render()->send();
require $_SERVER['DOCUMENT_ROOT'].'/php-framework-benchmark/libs/output_data.php';
echo require dirname(__FILE__).'/../../libs/output_data.php';
exit(0);
}

Expand Down
2 changes: 1 addition & 1 deletion bear-1.0/bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

// representation transfer
$page()->transfer($app->responder, $_SERVER);
require $_SERVER['DOCUMENT_ROOT'].'/php-framework-benchmark/libs/output_data.php';
echo require dirname(__FILE__).'/../../libs/output_data.php';
exit(0);
} catch (\Exception $e) {
$app->error->handle($e, $request)->transfer();
Expand Down
2 changes: 2 additions & 0 deletions bear-1.0/var/log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 1 addition & 1 deletion bear-1.0/var/www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Adhoc fix for benchmarking
// Remove sub directories from URI
$_SERVER['REQUEST_URI'] = preg_replace(
'!/php-framework-benchmark/bear-1.0/var/www/index.php!',
['!/php-framework-benchmark/bear-1.0/var/www/index.php!', '!/bear-1.0/var/www/index.php!'],
'',
$_SERVER['REQUEST_URI']
);
Expand Down
10 changes: 8 additions & 2 deletions benchmark.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/sh

base="http://127.0.0.1/php-framework-benchmark"
# exit on failure
set -e

if [ "$stack" = "" ]; then
stack="local"
fi
export stack;

cd `dirname $0`

Expand All @@ -14,6 +20,6 @@ fi

cd benchmarks

sh hello_world.sh "$base"
sh hello_world.sh "$stack"

php ../bin/show_results_table.php
14 changes: 10 additions & 4 deletions benchmarks/_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ benchmark ()
{
fw="$1"
url="$2"
ab_log="output/$fw.ab.log"
output="output/$fw.output"
ab_log="$output_dir/$fw.ab.log"
output="$output_dir/$fw.output"

echo "ab -c 10 -t 3 $url"
ab -c 10 -t 3 "$url" > "$ab_log"
Expand All @@ -19,17 +19,23 @@ benchmark ()
grep "Document Length:" "$ab_log" >> "$check_file"
grep "Failed requests:" "$ab_log" >> "$check_file"
grep 'Hello World!' "$output" >> "$check_file"
grep ':' "$output" >> "$check_file"
echo "---" >> "$check_file"

# check errors
touch "$error_file"
error=''
x=`grep 'Failed requests: 0' "$ab_log"`
x=`grep 'Failed requests: 0' "$ab_log" || true`
if [ "$x" = "" ]; then
tmp=`grep "Failed requests:" "$ab_log"`
error="$error$tmp"
fi
x=`grep 'Hello World!' "$output"`
x=`grep 'Hello World!' "$output" || true`
if [ "$x" = "" ]; then
tmp=`cat "$output"`
error="$error$tmp"
fi
x=`grep ':' "$output" || true`
if [ "$x" = "" ]; then
tmp=`cat "$output"`
error="$error$tmp"
Expand Down
40 changes: 30 additions & 10 deletions benchmarks/hello_world.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
#!/bin/sh

# exit on failure
set -e

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

base="$1"
stack="$1"
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"
if [ "$stack" = "local" ]; then
base="http://127.0.0.1/php-framework-benchmark"
fi
if [ "$stack" = "docker_nginx_php_5_6_4" ]; then
base="http://nginx_php_5_6_4"
fi
if [ "$stack" = "docker_nginx_hhvm_3_10_1" ]; then
base="http://nginx_hhvm_3_10_1"
fi
if [ "$stack" = "docker_nginx_php_7_0_0" ]; then
base="http://nginx_php_7_0_0"
fi

output_dir="output/$stack"

results_file="$output_dir/results.$bm_name.log"
check_file="$output_dir/check.$bm_name.log"
error_file="$output_dir/error.$bm_name.log"
url_file="$output_dir/urls.log"

cd ..

mv "$results_file" "$results_file.old"
mv "$check_file" "$check_file.old"
mv "$error_file" "$error_file.old"
mv "$url_file" "$url_file.old"
mkdir -p "$output_dir"

mv "$results_file" "$results_file.old" || true
mv "$check_file" "$check_file.old" || true
mv "$error_file" "$error_file.old" || true
mv "$url_file" "$url_file.old" || true

for fw in `echo $targets`
do
Expand All @@ -27,4 +47,4 @@ do
fi
done

cat "$error_file"
cat "$error_file" || true
12 changes: 12 additions & 0 deletions bin/docker-urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

DIR=`dirname $0`;

echo "PHP 5.6.4 Stack:";
echo "http://"$(docker-machine ip default)":"$(docker-compose -f $DIR/../docker/docker-compose.yml port nginx_php_5_6_4 80 | sed 's/[0-9.]*://')
echo "HHVM 3.10.1 Stack:";
echo "http://"$(docker-machine ip default)":"$(docker-compose -f $DIR/../docker/docker-compose.yml port nginx_hhvm_3_10_1 80 | sed 's/[0-9.]*://')
echo "PHP 7.0.0 Stack:";
echo "http://"$(docker-machine ip default)":"$(docker-compose -f $DIR/../docker/docker-compose.yml port nginx_php_7_0_0 80 | sed 's/[0-9.]*://')

exit 0
7 changes: 5 additions & 2 deletions bin/show_comparison_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
require __DIR__ . '/../libs/build_table.php';
require __DIR__ . '/../libs/recalc_relative.php';

$stack = getenv('stack') ? getenv('stack') : 'local';
$output_dir = __DIR__ . '/../output/' . $stack;

$list = [
'cake-3.0',
'symfony-2.6',
'zf-2.4',
];

system('git checkout master');
$results_master = parse_results(__DIR__ . '/../output/results.hello_world.log');
$results_master = parse_results($output_dir . '/results.hello_world.log');
system('git checkout optimize');
$results_optimize = parse_results(__DIR__ . '/../output/results.hello_world.log');
$results_optimize = parse_results($output_dir . '/results.hello_world.log');
//var_dump($results_master, $results_optimize);

$is_fisrt = true;
Expand Down
5 changes: 4 additions & 1 deletion bin/show_results_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
require __DIR__ . '/../libs/parse_results.php';
require __DIR__ . '/../libs/build_table.php';

$results = parse_results(__DIR__ . '/../output/results.hello_world.log');
$stack = getenv('stack') ? getenv('stack') : 'local';
$output_dir = __DIR__ . '/../output/' . $stack;

$results = parse_results($output_dir . '/results.hello_world.log');
//var_dump($results);

echo build_table($results);
2 changes: 1 addition & 1 deletion cake-3.0/webroot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
new Response()
);

require $_SERVER['DOCUMENT_ROOT'].'/php-framework-benchmark/libs/output_data.php';
echo require dirname(__FILE__).'/../../libs/output_data.php';
2 changes: 1 addition & 1 deletion cake-3.1/src/Controller/HelloController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HelloController extends AppController

public function index()
{
$this->response->body('Hello World!');
$this->response->body('Hello World!' . require dirname(__FILE__).'/../../../libs/output_data.php');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't accept this change. It exclude shutdown process of the framework.

return $this->response;
}
}
2 changes: 0 additions & 2 deletions cake-3.1/webroot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@
Request::createFromGlobals(),
new Response()
);

require $_SERVER['DOCUMENT_ROOT'].'/php-framework-benchmark/libs/output_data.php';
2 changes: 1 addition & 1 deletion ci-3.0/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,4 @@
*/
require_once BASEPATH.'core/CodeIgniter.php';

require $_SERVER['DOCUMENT_ROOT'].'/php-framework-benchmark/libs/output_data.php';
echo require dirname(__FILE__).'/../libs/output_data.php';
2 changes: 1 addition & 1 deletion cygnite-1.3/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
*/
require_once CF_BOOTSTRAP.DS.'start'.EXT;

require $_SERVER['DOCUMENT_ROOT'].'/php-framework-benchmark/libs/output_data.php';
echo require dirname(__FILE__).'/../libs/output_data.php';
89 changes: 89 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Shell to run benchmarks within
shell:
build: ./stack/php/shell
links:
- nginx_php_5_6_4
- nginx_hhvm_3_10_1
- nginx_php_7_0_0
volumes:
- ..:/repo:rw
working_dir: '/repo'
command: "/bin/bash"

# PHP 5.6.4
php_5_6_4:
image: neam/php-benchmark:ubuntu-15.04-fpm-5.6.4-hhvm-3.10.1-phalcon-2.0.9
volumes:
- ..:/public:rw
- ./stack/php/:/stack/php:rw
ports:
- "9000"
environment:
stack: 'docker_nginx_php_5_6_4'
working_dir: '/repo'
command: "/stack/php/run-php-fpm.sh"

# HHVM 3.10.1
hhvm_3_10_1:
image: neam/php-benchmark:ubuntu-15.04-fpm-5.6.4-hhvm-3.10.1-phalcon-2.0.9
volumes:
- ..:/public:rw
- ./stack/php/:/stack/php:rw
ports:
- "9000"
environment:
stack: 'docker_nginx_hhvm_3_10_1'
working_dir: '/repo'
command: "/stack/php/run-hhvm.sh"

# PHP 7.0.0
php_7_0_0:
image: neam/php-benchmark:ubuntu-15.04-fpm-7.0.0-hhvm-3.10.1-phalcon-2.0.9
volumes:
- ..:/public:rw
- ./stack/php/:/stack/php:rw
ports:
- "9000"
environment:
stack: 'docker_nginx_php_7_0_0'
working_dir: '/repo'
command: "/stack/php/run-php-fpm-7.sh"

# Nginx configured to serve PHP 5.6.4
nginx_php_5_6_4:
image: nginx:1.7
links:
- php_5_6_4:php
volumes:
- ..:/public:rw
- ./stack/nginx/:/stack/nginx:rw
ports:
- "80"
working_dir: '/app'
command: "/stack/nginx/run.sh"

# Nginx configured to serve HHVM 3.10.1
nginx_hhvm_3_10_1:
image: nginx:1.7
links:
- hhvm_3_10_1:php
volumes:
- ..:/public:rw
- ./stack/nginx/:/stack/nginx:rw
ports:
- "80"
working_dir: '/app'
command: "/stack/nginx/run.sh"

# Nginx configured to serve PHP 7.0.0
nginx_php_7_0_0:
image: nginx:1.7
links:
- php_7_0_0:php
volumes:
- ..:/public:rw
- ./stack/nginx/:/stack/nginx:rw
ports:
- "80"
working_dir: '/app'
command: "/stack/nginx/run.sh"
Empty file.
Loading