nginx, php, apache and spelix
DESCRIPTION
Spelix is a webapplication using PHP on the server, HTML5 and JS on the client. PHP is running as a FastCGI process serving requests via Nginx. This presentations describes some of the key-takeaways that I've learned with that project, the essentials of running Nginx with PHP, starting from the basics, but also covering techniques like Memcached or leveraging the FastCGI cache. It contains several examples and performance comparison charts.TRANSCRIPT
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 1 #Dynatrace
Harald Zeitlhofer October 2014
Nginx, PHP, Apache and Spelix
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 2 #Dynatrace
• Technology Strategist at Dynatrace • PHP for more than 15 years
• Married, 2 kids
• Love to discover new things
Harald Zeitlhofer
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 3 #Dynatrace
Austria
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 4 #Dynatrace
Where I’m from…
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 5 #Dynatrace
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 6 #Dynatrace
• MoNvaNon
• Nginx • PHP-‐FPM
• IntegraNon • Caching • Load balancing • How this runs in Spelix
Agenda
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 7 #Dynatrace
Nginx
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 8 #Dynatrace
• Lightweight HTTP server • Fast especially at high load
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 9 #Dynatrace
Leading among top 10.000 websites
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 10 #Dynatrace
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 11 #Dynatrace
• /etc/nginx/nginx.conf
Nginx SeTngs
# max_clients = worker_processes * worker_connections worker_processes [number of CPUs]; worker_connections 1024;
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 12 #Dynatrace
• /etc/sysctl.conf
• /etc/security/limits.conf
• /etc/pam.d/su
• /etc/default/nginx
Nginx High Load
fs.file-max = 80000
www-data soft nofile 40000 www-data hard nofile 70000
ULIMIT="-n 40000"
session required pam_limits.so
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 13 #Dynatrace
• 32768 concurrent requests
Nginx High Load
worker_processes 8; worker_rlimit_nofile 40000; events { worker_connections 4096; multi_accept on; }
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 14 #Dynatrace
PHP FastCGI Process Manager
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 15 #Dynatrace
• FastCGI Process Manager
• Available since 5.3.3, stable since 5.4.1 • Run mulNple PHP worker processes to serve CGI requests
• MulNple connecNon pools
• Different php.ini files possible • Very helpful: fastcgi_finish_request()
PHP-‐FPM
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 16 #Dynatrace
• InstallaNon
• Pool configuraNon /etc/php5/fpm/pool.d/www.conf
PHP-‐FPM
[www] user = www-data group = www-data listen = 127.0.0.1:9000 # for Unix socket: unix:/var/run/php5-fpm.sock;
root@hzvm01:/etc/nginx/sites-enabled# ps -ef | grep php root 6435 1 0 14:39 ? 00:00:32 php-fpm: master process (/etc/php5/fpm/php-fpm.conf) spelix 6439 6435 0 14:39 ? 00:00:00 php-fpm: pool batch spelix 6440 6435 0 14:39 ? 00:00:00 php-fpm: pool batch www-data 10576 6435 1 18:45 ? 00:00:48 php-fpm: pool www www-data 10920 6435 1 18:47 ? 00:00:47 php-fpm: pool www www-data 10927 6435 1 18:47 ? 00:00:46 php-fpm: pool www
sudo apt-get install php5-fpm
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 17 #Dynatrace
• Process Manager
pm.max_children
= total available memory / memory used by 1 PHP process
PHP-‐FPM
[pool_name] ... pm = [dynamic/static] pm.max_children = 5 ; only used for dynamic: pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 18 #Dynatrace
• Security /etc/php5/fpm/php.ini
• Use mulNple configuraNons
PHP-‐FPM
/etc/init.d/php-fpm start or php-fpm -y /path/to/your/php-fpm.conf -c /path/to/your/php.ini
expose_php = Off
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 19 #Dynatrace
Nginx and PHP / IntegraNon
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 20 #Dynatrace
• CommunicaNon via sockets • TCP vs Unix
• Unix slightly faster when used on localhost
• Use TCP for high load
Nginx and PHP
location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }
fastcgi_pass unix:/var/run/php5-fpm.sock;
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 21 #Dynatrace
• StaNc content to be served by Nginx • Dynamic requests to be sent to PHP-‐FPM
IntegraNon
server { listen 80; root /var/www/test; index index.php index.html index.htm; server_name test.whateveryourdomain.is; location / { try_files $uri $uri/ @notfound; } location ~ \.(html|js|css|gif|jpg|jpe|jpeg|png|bmp|tif|pdf|ico)$ { try_files $uri @notfound; } location ~* \.php$ {
fastcgi_index index.php; fastcgi_pass php; include fastcgi_params; } locaation @notfound { ... }
}
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 22 #Dynatrace
Nginx – PHP transacNon flow
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 23 #Dynatrace
• Easy way to deploy your applicaNon • All source files packed into one *.phar file
PHAR – PHP Archives
location ~* \.(php|phar)$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 24 #Dynatrace
PHAR example root@hzvm01:/var/www/app/src# ls -lrtR .: total 8 drwxrwxr-x 2 root root 4096 Oct 10 16:27 lib -rw-r--r-- 1 root root 27 Oct 10 16:27 index.php ./lib: total 4 -rw-r--r-- 1 root root 87 Oct 10 16:27 App.php
root@hzvm01:/var/www/app/src# cat index.php <?php $app = new App(); ?>
root@hzvm01:/var/www/app/src# cat lib/App.php <?php class App { function __construct() { echo "Starting Application\n"; }
}
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 25 #Dynatrace
PHAR Example
location /myapp { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/myapp.phar; }
root@hzvm01:/var/www/app# phar pack -f myapp.phar src lib/App.php index.php root@hzvm01:/var/www/app# l myapp.phar -rw-r--r-- 1 root root 6923 Oct 10 19:51 myapp.phar
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 26 #Dynatrace
PHAR execuNon
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 27 #Dynatrace
Performance
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 28 #Dynatrace
• Nginx running with default seTngs
• Apache • AllowOverride None
• MulN-‐process mode to allow usage of mod_php
Benchmarking Nginx vs Apache
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 29 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 10 Time taken for tests: 6.848 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2660000 bytes HTML transferred: 210000 bytes Requests per second: 1460.25 [#/sec] (mean) Time per request: 6.848 [ms] (mean) Time per request: 0.685 [ms] (mean, across all concurrent requests) Transfer rate: 379.32 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 0.9 2 24 Processing: 1 4 1.5 4 26 Waiting: 0 3 1.3 3 24 Total: 2 7 1.7 6 32 Percentage of the requests served within a certain time (ms) 50% 6 66% 7 75% 7 80% 7 90% 8 95% 9 98% 10 99% 12 100% 32 (longest request)
Server Software: nginx/1.4.6 Server Hostname: test.hzvm01 Server Port: 80 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 10 Time taken for tests: 4.991 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2600000 bytes HTML transferred: 210000 bytes Requests per second: 2003.41 [#/sec] (mean) Time per request: 4.991 [ms] (mean) Time per request: 0.499 [ms] (mean, across all concurrent requests) Transfer rate: 508.68 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 1.1 2 31 Processing: 1 3 2.0 3 38 Waiting: 0 2 1.7 2 34 Total: 1 5 2.2 5 41 Percentage of the requests served within a certain time (ms) 50% 5 66% 5 75% 5 80% 6 90% 6 95% 7 98% 9 99% 12 100% 41 (longest request)
StaNc HTML, 10k requests, concurrency 10
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 30 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 100 Time taken for tests: 5.329 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2660000 bytes HTML transferred: 210000 bytes Requests per second: 1876.35 [#/sec] (mean) Time per request: 53.295 [ms] (mean) Time per request: 0.533 [ms] (mean, across all concurrent requests) Transfer rate: 487.41 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 8 4.5 8 54 Processing: 15 45 18.5 51 120 Waiting: 12 42 18.7 49 108 Total: 26 53 18.2 58 132 Percentage of the requests served within a certain time (ms) 50% 58 66% 60 75% 62 80% 64 90% 69 95% 87 98% 99 99% 105 100% 132 (longest request)
Server Software: nginx/1.4.6 Server Hostname: test.hzvm01 Server Port: 80 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 100 Time taken for tests: 4.908 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2600000 bytes HTML transferred: 210000 bytes Requests per second: 2037.64 [#/sec] (mean) Time per request: 49.076 [ms] (mean) Time per request: 0.491 [ms] (mean, across all concurrent requests) Transfer rate: 517.37 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 9 23 4.4 23 40 Processing: 8 25 5.1 25 48 Waiting: 2 19 4.6 18 41 Total: 22 49 6.4 47 75 Percentage of the requests served within a certain time (ms) 50% 47 66% 50 75% 52 80% 54 90% 58 95% 61 98% 64 99% 65 100% 75 (longest request)
StaNc HTML, 10k requests, concurrency 100
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 31 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 500 Time taken for tests: 7.628 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2660000 bytes HTML transferred: 210000 bytes Requests per second: 1310.89 [#/sec] (mean) Time per request: 381.421 [ms] (mean) Time per request: 0.763 [ms] (mean, across all concurrent requests) Transfer rate: 340.52 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 2 67 263.3 16 3050 Processing: 28 246 814.5 95 6605 Waiting: 21 240 814.9 90 6599 Total: 70 312 870.2 113 7556 Percentage of the requests served within a certain time (ms) 50% 113 66% 130 75% 147 80% 158 90% 364 95% 1111 98% 3100 99% 6637 100% 7556 (longest request)
Server Software: nginx/1.4.6 Server Hostname: test.hzvm01 Server Port: 80 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 500 Time taken for tests: 4.306 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2600000 bytes HTML transferred: 210000 bytes Requests per second: 2322.27 [#/sec] (mean) Time per request: 215.307 [ms] (mean) Time per request: 0.431 [ms] (mean, across all concurrent requests) Transfer rate: 589.64 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 47 100 32.0 97 185 Processing: 50 110 36.1 108 231 Waiting: 20 82 30.3 76 188 Total: 119 210 57.8 220 334 Percentage of the requests served within a certain time (ms) 50% 220 66% 248 75% 265 80% 271 90% 285 95% 293 98% 303 99% 306 100% 334 (longest request)
StaNc HTML, 10k requests, concurrency 500
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 32 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 1000 Time taken for tests: 9.778 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2660000 bytes HTML transferred: 210000 bytes Requests per second: 1022.74 [#/sec] (mean) Time per request: 977.769 [ms] (mean) Time per request: 0.978 [ms] (mean, across all concurrent requests) Transfer rate: 265.67 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 28 179 403.5 69 3106 Processing: 39 452 1262.7 117 6677 Waiting: 22 427 1267.6 91 6672 Total: 107 631 1447.3 182 9619 Percentage of the requests served within a certain time (ms) 50% 182 66% 203 75% 258 80% 422 90% 1178 95% 3190 98% 7622 99% 7643 100% 9619 (longest request)
Server Software: nginx/1.4.6 Server Hostname: test.hzvm01 Server Port: 80 Document Path: /index.html Document Length: 21 bytes Concurrency Level: 1000 Time taken for tests: 5.302 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 2600000 bytes HTML transferred: 210000 bytes Requests per second: 1886.22 [#/sec] (mean) Time per request: 530.160 [ms] (mean) Time per request: 0.530 [ms] (mean, across all concurrent requests) Transfer rate: 478.92 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 138 238 50.5 229 370 Processing: 72 269 59.7 257 514 Waiting: 62 195 58.3 184 377 Total: 338 507 56.0 518 651 Percentage of the requests served within a certain time (ms) 50% 518 66% 541 75% 547 80% 551 90% 573 95% 580 98% 623 99% 638 100% 651 (longest request)
StaNc HTML, 10k requests, concurrency 1k
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 33 #Dynatrace
Apache vs Nginx (StaNc HTML)
0
2
4
6
8
10
12
10 100 500 1000
Apache/2.4.7
nginx/1.4.6
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 34 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /images/plus.gif Document Length: 841 bytes Concurrency Level: 500 Time taken for tests: 8.036 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 10880000 bytes HTML transferred: 8410000 bytes Requests per second: 1244.35 [#/sec] (mean) Time per request: 401.817 [ms] (mean) Time per request: 0.804 [ms] (mean, across all concurrent requests) Transfer rate: 1322.12 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 63 273.3 7 3046 Processing: 19 229 815.9 80 6596 Waiting: 16 227 816.0 78 6596 Total: 54 293 881.4 88 7561 Percentage of the requests served within a certain time (ms) 50% 88 66% 95 75% 104 80% 109 90% 318 95% 1094 98% 3289 99% 6623 100% 7561 (longest request)
Server Software: nginx/1.4.6 Server Hostname: test.hzvm01 Server Port: 80 Document Path: /images/plus.gif Document Length: 841 bytes Concurrency Level: 500 Time taken for tests: 5.239 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 10820000 bytes HTML transferred: 8410000 bytes Requests per second: 1908.76 [#/sec] (mean) Time per request: 261.950 [ms] (mean) Time per request: 0.524 [ms] (mean, across all concurrent requests) Transfer rate: 2016.87 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 55 119 22.0 118 183 Processing: 32 137 27.8 132 260 Waiting: 29 101 25.4 96 202 Total: 156 255 28.1 258 351 Percentage of the requests served within a certain time (ms) 50% 258 66% 268 75% 275 80% 281 90% 288 95% 298 98% 310 99% 317 100% 351 (longest request)
Image 841 bytes, 10k requests, concurrency 500
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 35 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /index.php Document Length: 12 bytes Concurrency Level: 500 Time taken for tests: 13.298 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 199000 bytes HTML transferred: 12000 bytes Requests per second: 75.20 [#/sec] (mean) Time per request: 6649.092 [ms] (mean) Time per request: 13.298 [ms] (mean, across all concurrent requests) Transfer rate: 14.61 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 25 30.0 1 68 Processing: 70 2344 4333.5 167 13205 Waiting: 69 2343 4333.4 165 13204 Total: 124 2369 4352.0 171 13264 Percentage of the requests served within a certain time (ms) 50% 171 66% 211 75% 415 80% 7240 90% 13156 95% 13208 98% 13249 99% 13257 100% 13264 (longest request)
Server Software: nginx/1.4.6 Server Hostname: test.hzvm01 Server Port: 80 Document Path: /index.php Document Length: 12 bytes Concurrency Level: 500 Time taken for tests: 3.230 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 178000 bytes HTML transferred: 12000 bytes Requests per second: 309.56 [#/sec] (mean) Time per request: 1615.213 [ms] (mean) Time per request: 3.230 [ms] (mean, across all concurrent requests) Transfer rate: 53.81 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 45 44.7 71 106 Processing: 72 643 708.7 204 3057 Waiting: 69 643 708.8 203 3057 Total: 163 688 732.1 227 3133 Percentage of the requests served within a certain time (ms) 50% 227 66% 1147 75% 1215 80% 1249 90% 1380 95% 1433 98% 3128 99% 3131 100% 3133 (longest request)
PHP, 1k requests, concurrency 500
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 36 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /index.php Document Length: 12 bytes Concurrency Level: 100 Time taken for tests: 1.233 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 199000 bytes HTML transferred: 12000 bytes Requests per second: 810.72 [#/sec] (mean) Time per request: 123.348 [ms] (mean) Time per request: 1.233 [ms] (mean, across all concurrent requests) Transfer rate: 157.55 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 3 7.4 1 34 Processing: 34 112 23.2 107 250 Waiting: 29 111 22.8 106 249 Total: 49 116 22.6 109 250 Percentage of the requests served within a certain time (ms) 50% 109 66% 115 75% 126 80% 133 90% 151 95% 157 98% 171 99% 192 100% 250 (longest request)
Server Software: nginx/1.4.6 Server Hostname: test.hzvm01 Server Port: 80 Document Path: /index.php Document Length: 12 bytes Concurrency Level: 100 Time taken for tests: 1.628 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 178000 bytes HTML transferred: 12000 bytes Requests per second: 614.15 [#/sec] (mean) Time per request: 162.826 [ms] (mean) Time per request: 1.628 [ms] (mean, across all concurrent requests) Transfer rate: 106.76 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 5 10.3 1 76 Processing: 15 149 35.4 158 210 Waiting: 15 147 34.7 157 208 Total: 39 154 29.0 160 211 Percentage of the requests served within a certain time (ms) 50% 160 66% 168 75% 173 80% 177 90% 185 95% 193 98% 200 99% 204 100% 211 (longest request)
PHP, 1k requests, concurrency 100
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 37 #Dynatrace
• Nginx faster for serving staNc files • Apache is faster for serving PHP only (low load)
Apache vs Nginx -‐ conclusion
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 38 #Dynatrace
Nginx, Apache and PHP
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 39 #Dynatrace
Nginx, Apache and PHP
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 40 #Dynatrace
• Setup caching and disable access logging
• Change Nmeouts
Nginx – more performance tweaks
location ~ \.(html|js|css|gif|jpg|jpe|jpeg|png|bmp|tif|pdf|ico)$ { expires 30d; access_log off; error_log off; try_files $uri $uri/ =404; }
http { keepalive_timeout 15; client_body_timeout 12; client_header_timeout 12; send_timeout 10;
}
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 41 #Dynatrace
Caching
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 42 #Dynatrace
• Server Side • Opcode cache
• Full page cache
• Pagelet cache
• Data cache
• Client Side • Browser cache
• HTML5 applicaNon cache
• HTML5 data storage (LocalStorage, SessionStorage)
Caching
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 43 #Dynatrace
• Integrated Zend OpCache in PHP 5.5 • Other technologies available
hjp://en.wikipedia.org/wiki/List_of_PHP_accelerators
PHP Opcode Cache
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 44 #Dynatrace
PHP OpCache example
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 45 #Dynatrace
PHP OpCache disabled
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 46 #Dynatrace
PHP OpCache enabled
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 47 #Dynatrace
• ngx_hjp_memcached_module
Full page cache with Nginx and Memcached
server { location / { set $memcached_key "$uri"; memcached_pass host:11211; error_page 404 502 504 = @fallback; } location @fallback { proxy_pass http://backend; } }
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 48 #Dynatrace
• PHP
Full page cache with Nginx and Memcached
$ sudo apt-get install php5-memcached
<?php … function cachePage($content) { $c = new Memcached(); $c->addServer('localhost',11211); $c->set($_SERVER[”REQUEST_URI"], $content);
} ... $content = $this->renderPage(); $this->cachePage($content); ... ?>
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 49 #Dynatrace
Server Software: Nginx + PHP Server Hostname: test.hzvm01 Server Port: 80 Document Path: /index.php Document Length: 10 bytes Concurrency Level: 100 Time taken for tests: 4.514 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 625000 bytes HTML transferred: 50000 bytes Requests per second: 1107.62 [#/sec] (mean) Time per request: 90.284 [ms] (mean) Time per request: 0.903 [ms] (mean, across all concurrent requests) Transfer rate: 135.21 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 3.2 1 38 Processing: 22 88 13.1 87 148 Waiting: 21 87 13.1 86 148 Total: 42 89 12.5 88 148 Percentage of the requests served within a certain time (ms) 50% 88 66% 94 75% 97 80% 98 90% 104 95% 109 98% 125 99% 132 100% 148 (longest request)
PHP, 5k requests, concurrency 100
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 50 #Dynatrace
Server Software: Nginx + Apache + PHP Server Hostname: test.hzvm01 Server Port: 81 Document Path: /index.php Document Length: 10 bytes Concurrency Level: 100 Time taken for tests: 9.207 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 905000 bytes HTML transferred: 50000 bytes Requests per second: 543.05 [#/sec] (mean) Time per request: 184.146 [ms] (mean) Time per request: 1.841 [ms] (mean, across all concurrent requests) Transfer rate: 95.99 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 10 17.0 2 138 Processing: 20 173 73.7 156 1254 Waiting: 19 168 72.3 152 1239 Total: 55 182 72.4 168 1254 Percentage of the requests served within a certain time (ms) 50% 168 66% 197 75% 214 80% 224 90% 256 95% 287 98% 337 99% 427 100% 1254 (longest request)
PHP, 5k requests, concurrency 100
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 51 #Dynatrace
Server Software: Apache/2.4.7 Server Hostname: test.hzvm01 Server Port: 88 Document Path: /index.php Document Length: 10 bytes Concurrency Level: 100 Time taken for tests: 7.296 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 985000 bytes HTML transferred: 50000 bytes Requests per second: 685.31 [#/sec] (mean) Time per request: 145.920 [ms] (mean) Time per request: 1.459 [ms] (mean, across all concurrent requests) Transfer rate: 131.84 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 6 6.5 4 56 Processing: 30 138 57.2 120 938 Waiting: 30 135 56.4 117 937 Total: 55 144 55.8 126 938 Percentage of the requests served within a certain time (ms) 50% 126 66% 151 75% 168 80% 178 90% 218 95% 239 98% 267 99% 299 100% 938 (longest request)
PHP, 5k requests, concurrency 100
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 52 #Dynatrace
Server Software: nginx + Memcached Server Hostname: test.hzvm01 Server Port: 82 Document Path: /index.php Document Length: 23 bytes Concurrency Level: 100 Time taken for tests: 3.058 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 865000 bytes HTML transferred: 115000 bytes Requests per second: 1634.92 [#/sec] (mean) Time per request: 61.165 [ms] (mean) Time per request: 0.612 [ms] (mean, across all concurrent requests) Transfer rate: 276.21 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 7 24 6.0 24 59 Processing: 8 36 7.8 36 75 Waiting: 6 28 7.4 29 69 Total: 32 60 9.3 60 101 Percentage of the requests served within a certain time (ms) 50% 60 66% 63 75% 64 80% 66 90% 71 95% 80 98% 87 99% 92 100% 101 (longest request)
PHP, 5k requests, concurrency 100
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 53 #Dynatrace
• Part of the Nginx FastCGI module
Nginx FastCGI cache
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=APPKEY:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri";
location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_cache APPKEY; fastcgi_cache_valid 200 60m; }
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 54 #Dynatrace
TesNng FastCGI cache
<?php echo time()."\n"; ?>
root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229911 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229912 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229915 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229917 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229919 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229921 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229923 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229925 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229927 root@hzvm01:/var/www/test# curl http://test.hzvm01/index.php 1413229929
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 55 #Dynatrace
TesNng FastCGI cache
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 56 #Dynatrace
• Config for cached requests running on port 83
TesNng FastCGI cache
root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226 root@hzvm01:/var/www/test# curl http://test.hzvm01:83/index.php 1413230226
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 57 #Dynatrace
TesNng FastCGI cache
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 58 #Dynatrace
TesNng FastCGI cache
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 59 #Dynatrace
• Served by webserver or applicaNon • Technologies
• Memcached
• FastCGI cache
• APC (alternaNve PHP cache)
• Redis
Pagelet / Data cache
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 60 #Dynatrace
• HTML5 • applicaNon cache
• LocalStorage
• SessionStorage
Client Side Caching location ~ \.(html|js|css|gif|jpg|jpe|jpeg|png|bmp|tif|pdf|ico)$ { expires 30d; access_log off; error_log off; try_files $uri $uri/ =404; }
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 61 #Dynatrace
Server Software: Nginx + FastCGI cache Server Hostname: test.hzvm01 Server Port: 83 Document Path: /index.php Document Length: 32 bytes Concurrency Level: 100 Time taken for tests: 2.545 seconds Complete requests: 5000 Failed requests: 0 Total transferred: 735000 bytes HTML transferred: 160000 bytes Requests per second: 1964.62 [#/sec] (mean) Time per request: 50.900 [ms] (mean) Time per request: 0.509 [ms] (mean, across all concurrent requests) Transfer rate: 282.03 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 11 23 5.3 22 46 Processing: 8 27 6.7 25 59 Waiting: 6 20 6.0 18 56 Total: 29 50 7.6 50 85 Percentage of the requests served within a certain time (ms) 50% 50 66% 53 75% 55 80% 56 90% 61 95% 64 98% 67 99% 71 100% 85 (longest request)
PHP, 5k requests, concurrency 100
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 62 #Dynatrace
• ngx_hjp_upstream_module
Load balancing
upstream php_loadbalancer { server unix:/var/run/php5-fpm.sock weight=5; server 192.168.56.12:7777 weight=2; server 192.168.56.13:7777; } server { listen 80; root /home/www/test; server_name test.hzvm01; location / { try_files $uri =405; } location ~ \.php$ { fastcgi_pass php_loadbalancer; fastcgi_index index.php; include fastcgi_params; } }
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 63 #Dynatrace
Load balancing
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 64 #Dynatrace
Nginx and other technologies
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 65 #Dynatrace
Nginx security server_tokens off; location ~ /\. { access_log off; log_not_found off; deny all; }
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 66 #Dynatrace
Spelix
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 67 #Dynatrace
Spelix
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 68 #Dynatrace
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 69 #Dynatrace
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 70 #Dynatrace
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 71 #Dynatrace
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 72 #Dynatrace
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 73 #Dynatrace
• PHP ApplicaNon • MySQL
• CouchDB • Memcached
• Nginx + PHP-‐FPM
• HTML5 (LocalStorage, Canvas, ApplicaNon Cache)
• JavaScript (jQuery, Leaflet API)
Spelix Technology
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 74 #Dynatrace
Spelix
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 75 #Dynatrace
Nginx and other technologies
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 76 #Dynatrace
Nginx and other technologies server { server_name services.zitco.net; listen 80;
location / {
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://localhost:8080; }
}
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 77 #Dynatrace
IntegraNon
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 78 #Dynatrace
IntegraNon
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 79 #Dynatrace
• Apache Benchmark
• Dynatrace ApplicaNon Monitoring • Free Trial for 30 days
• Free for developers on local machine
• hjp://www.dynatrace.com
Used Tools
hjp://bitly.com/djrial
COMPANY CONFIDENTIAL – DO NOT DISTRIBUTE 80 #Dynatrace
[email protected] @HZeitlhofer