Skip to content

Commit 88ce5eb

Browse files
committed
Added initial docker stacks to be able to share benchmarking environments and easily benchmark against php 5.6, hhvm and php 7
1 parent 963f129 commit 88ce5eb

File tree

20 files changed

+2416
-0
lines changed

20 files changed

+2416
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,60 @@ If you want to see current configuration, run `sudo sysctl -a`.
150150
</VirtualHost>
151151
~~~
152152

153+
## Benchmarking using the supplied Docker Stack
154+
155+
Use the supplied Docker Stack in order to automatically set up the following benchmarking environments:
156+
157+
* Ubuntu 15.04 64bit (Docker)
158+
* Nginx 1.7.12
159+
* PHP-FPM 5.6.4
160+
* Zend OPcache 7.0.4-dev
161+
* PhalconPHP 2.0.9
162+
* PHP-FPM 7.0.0
163+
* Zend OPcache 7.0.6-dev
164+
* PhalconPHP 2.0.9
165+
* HHVM 3.10.1
166+
167+
By sharing underlying software stacks, the benchmark results vary only according to the host machine's hardware specs and differing code implementations.
168+
169+
### Getting Started
170+
171+
If running locally, install [Docker Toolbox](https://www.docker.com/docker-toolbox).
172+
173+
Clone the source code:
174+
~~~
175+
git clone https://github.com/kenjis/php-framework-benchmark.git
176+
cd php-framework-benchmark
177+
~~~
178+
179+
Cd into the docker directory of this repo and make sure that docker toolbox is available:
180+
~~~
181+
cd docker
182+
eval "$(docker-machine env default)"
183+
~~~
184+
185+
Start the Nginx/PHP server stacks:
186+
~~~
187+
docker-compose up -d
188+
~~~
189+
190+
Start the supplied docker shell from within this repository's `docker` folder:
191+
~~~
192+
docker-compose run shell
193+
~~~
194+
195+
Run the set-up script:
196+
~~~
197+
sh setup.sh
198+
~~~
199+
200+
Run benchmarks against each stack:
201+
~~~
202+
stack=docker_nginx_php_5_6_4 sh benchmark.sh
203+
stack=docker_nginx_hhvm_3_10_1 sh benchmark.sh
204+
stack=docker_nginx_php_7_0_0 sh benchmark.sh
205+
~~~
206+
153207
## References
154208

155209
* [Aura](http://auraphp.com/) ([@auraphp](https://twitter.com/auraphp))

docker/docker-compose.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Shell to run benchmarks within
2+
shell:
3+
build: ./stack/php/shell
4+
links:
5+
- nginx_php_5_6_4
6+
- nginx_hhvm_3_10_1
7+
- nginx_php_7_0_0
8+
volumes:
9+
- ..:/repo:rw
10+
working_dir: '/repo'
11+
command: "/bin/bash"
12+
13+
# PHP 5.6.4
14+
php_5_6_4:
15+
image: neam/php-benchmark:ubuntu-15.04-fpm-5.6.4-hhvm-3.10.1-phalcon-2.0.9
16+
volumes:
17+
- ..:/public:rw
18+
- ./stack/php/:/stack/php:rw
19+
ports:
20+
- "9000"
21+
working_dir: '/repo'
22+
command: "/stack/php/run-php-fpm.sh"
23+
24+
# HHVM 3.10.1
25+
hhvm_3_10_1:
26+
image: neam/php-benchmark:ubuntu-15.04-fpm-5.6.4-hhvm-3.10.1-phalcon-2.0.9
27+
volumes:
28+
- ..:/public:rw
29+
- ./stack/php/:/stack/php:rw
30+
ports:
31+
- "9000"
32+
working_dir: '/repo'
33+
command: "/stack/php/run-hhvm.sh"
34+
35+
# PHP 7.0.0
36+
php_7_0_0:
37+
image: neam/php-benchmark:ubuntu-15.04-fpm-7.0.0-hhvm-3.10.1-phalcon-2.0.9
38+
volumes:
39+
- ..:/public:rw
40+
- ./stack/php/:/stack/php:rw
41+
ports:
42+
- "9000"
43+
working_dir: '/repo'
44+
command: "/stack/php/run-php-fpm-7.sh"
45+
46+
# Nginx configured to serve PHP 5.6.4
47+
nginx_php_5_6_4:
48+
image: nginx:1.7
49+
links:
50+
- php_5_6_4:php
51+
volumes:
52+
- ..:/public:rw
53+
- ./stack/nginx/:/stack/nginx:rw
54+
ports:
55+
- "80"
56+
working_dir: '/app'
57+
command: "/stack/nginx/run.sh"
58+
59+
# Nginx configured to serve HHVM 3.10.1
60+
nginx_hhvm_3_10_1:
61+
image: nginx:1.7
62+
links:
63+
- hhvm_3_10_1:php
64+
volumes:
65+
- ..:/public:rw
66+
- ./stack/nginx/:/stack/nginx:rw
67+
ports:
68+
- "80"
69+
working_dir: '/app'
70+
command: "/stack/nginx/run.sh"
71+
72+
# Nginx configured to serve PHP 7.0.0
73+
nginx_php_7_0_0:
74+
image: nginx:1.7
75+
links:
76+
- php_7_0_0:php
77+
volumes:
78+
- ..:/public:rw
79+
- ./stack/nginx/:/stack/nginx:rw
80+
ports:
81+
- "80"
82+
working_dir: '/app'
83+
command: "/stack/nginx/run.sh"

docker/stack/nginx/conf.d/.gitkeep

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
# Hide nginx version information.
3+
server_tokens off;
4+
5+
tcp_nopush on;
6+
tcp_nodelay off;
7+
8+
client_max_body_size 100m;
9+
client_body_timeout 600s;
10+
11+
# define the $proxied_https variable based on the forwarded proto as Nginx is not the SSL endpoint
12+
# The name $https cannot be used as the variable is already defined in Nginx core
13+
map $http_x_forwarded_proto $proxied_https {
14+
default off;
15+
https on;
16+
}
17+
18+
# Enable Gzip compression.
19+
gzip on;
20+
gzip_http_version 1.0;
21+
gzip_comp_level 5;
22+
gzip_min_length 256;
23+
gzip_proxied any;
24+
gzip_vary on;
25+
gzip_types
26+
application/atom+xml
27+
application/javascript
28+
application/x-javascript
29+
application/json
30+
application/rss+xml
31+
application/vnd.ms-fontobject
32+
application/x-font-ttf
33+
application/x-web-app-manifest+json
34+
application/xhtml+xml
35+
application/xml
36+
font/opentype
37+
image/svg+xml
38+
image/x-icon
39+
text/css
40+
text/plain
41+
text/x-component;
42+
# text/html is always compressed by HttpGzipModule
43+

docker/stack/nginx/conf.d/app.conf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
index index.php;
3+
4+
server {
5+
server_name localhost;
6+
listen 80;
7+
8+
# Specify a charset
9+
charset utf-8;
10+
11+
# Document root
12+
root /public;
13+
14+
# Attempt the uri, uri+/, then fall back to index.php with args included
15+
location / {
16+
try_files $uri $uri/ /index.php?$args;
17+
}
18+
19+
# PHP
20+
location ~ \.(hh|php) {
21+
include fastcgi_params;
22+
fastcgi_buffers 256 4k;
23+
fastcgi_param HTTPS $proxied_https;
24+
25+
# support urls like /$fw/index.php/foo/bar - http://stackoverflow.com/a/24243627/682317
26+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
27+
fastcgi_param PATH_INFO $fastcgi_path_info;
28+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
29+
30+
# for hhvm
31+
fastcgi_keep_conn on;
32+
fastcgi_param NGINX_SCRIPT_NAME $fastcgi_script_name;
33+
fastcgi_param NGINX_DOCUMENT_ROOT $document_root;
34+
35+
fastcgi_pass php;
36+
}
37+
38+
}

docker/stack/nginx/nginx.conf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
user nginx;
3+
worker_processes 1;
4+
5+
error_log /proc/self/fd/2 notice;
6+
pid /var/run/nginx.pid;
7+
8+
9+
# Tweaked according to max_clients = (worker_processes * worker_connections ) / (X * 2)
10+
# X is however many concurrent connections these clients make to you
11+
# 2 is because you open a connection to what you are proxying
12+
# --> max_clients * X * 2 = worker_connections
13+
14+
events {
15+
worker_connections 30000; # Key to high performance - have a lot of connections available
16+
}
17+
18+
# --> worker_rlimit_nofile = worker_connections*2 + some margin
19+
20+
worker_rlimit_nofile 65000; # Each connection needs a filehandle (or 2 if you are proxying)
21+
22+
23+
http {
24+
include /etc/nginx/mime.types;
25+
default_type application/octet-stream;
26+
27+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
28+
'$status $body_bytes_sent "$http_referer" '
29+
'"$http_user_agent" "$http_x_forwarded_for"';
30+
31+
access_log /proc/self/fd/2 main;
32+
33+
sendfile on;
34+
#tcp_nopush on;
35+
36+
keepalive_timeout 65;
37+
38+
#gzip on;
39+
40+
upstream php {
41+
server php:9000 max_fails=3 fail_timeout=3s;
42+
keepalive 16;
43+
}
44+
45+
include /etc/nginx/conf.d/*.conf;
46+
}

docker/stack/nginx/run.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# This script is run within the nginx:1.7-based container on start
4+
5+
# Fail on any error
6+
set -o errexit
7+
8+
# Copy nginx configuration from app directory to nginx container
9+
10+
# Remove existing config files
11+
if [ "$(ls /etc/nginx/conf.d/)" ]; then
12+
rm /etc/nginx/conf.d/*.conf
13+
fi
14+
15+
# Copy custom project include files
16+
if [ "$(ls /stack/nginx/conf.d/)" ]; then
17+
cp -r /stack/nginx/conf.d/* /etc/nginx/conf.d/
18+
fi
19+
cp /stack/nginx/nginx.conf /etc/nginx/nginx.conf
20+
21+
# Run nginx
22+
nginx -g 'daemon off;'

docker/stack/php/conf.d/.gitkeep

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; Logging
2+
display_errors=on
3+
log_errors=on
4+
error_reporting=E_ALL | E_STRICT
5+
6+
; Required timezone
7+
date.timezone = UTC
8+
9+
; Security
10+
expose_php=off
11+
cgi.fix_pathinfo=0
12+
13+
memory_limit=128M
14+
15+
; Opcache
16+
opcache.memory_consumption=128
17+
opcache.interned_strings_buffer=8
18+
opcache.max_accelerated_files=4000
19+
opcache.validate_timestamps=off
20+
opcache.fast_shutdown=0
21+
opcache.enable_cli=1
22+
23+
; Omit warning NOTICE: PHP message: PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead.
24+
always_populate_raw_post_data=-1

docker/stack/php/conf.d/app.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
max_execution_time=300
3+
error_reporting=E_ALL
4+
html_errors=on
5+
short_open_tag=on
6+
7+
; Uncomment during development
8+
opcache.validate_timestamps=on ;

0 commit comments

Comments
 (0)