
Preparación del entorno
Para estas pruebas se generaron tres contenedores Ubuntu Server 18.04 con LXC sobre Kubuntu Desktop 18.04
+------------+---------+----------------------+------+------------+-----------+
| NOMBRE | ESTADO | IPV4 | IPV6 | TIPO | SNAPSHOTS |
+------------+---------+----------------------+------+------------+-----------+
| ubuntu-ha | RUNNING | 10.56.142.111 (eth0) | | PERSISTENT | 0 |
+------------+---------+----------------------+------+------------+-----------+
| ubuntu-wp1 | RUNNING | 10.56.142.244 (eth0) | | PERSISTENT | 0 |
+------------+---------+----------------------+------+------------+-----------+
| ubuntu-wp2 | RUNNING | 10.56.142.34 (eth0) | | PERSISTENT | 0 |
+------------+---------+----------------------+------+------------+-----------+
HAProxy
En ubuntu-ha se instaló haproxy y modificó el archivo de configuración para que redirija el tráfico a ubuntu-wp1 o ubuntu-wp2, según la URL destino (wp1.local o wp2.local).
root@ubuntu-ha:~# apt-get install haproxy
y en /etc/haproxy/haproxy.cfg
global
daemon
maxconn 256
user haproxy
group haproxy
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
defaults
mode http
log global
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
stats enable
stats uri /haproxy?stats
frontend localnodes
bind *:8080
mode http
use_backend wp1 if { hdr(host) -i wp1.local }
use_backend wp2 if { hdr(host) -i wp2.local }
backend wp1
server wp1 10.56.142.244:80
backend wp2
server wp2 10.56.142.34:80
Los parámetros stats habilitan una página de estadisticas sobre el uso de HAProxy
Sitio wp1.local (Apache)
En ubuntu-wp1 se instaló y configuró Apache2, PHP7.2 y MySql Server con una copia de este blog para generar contenido.
root@ubuntu-wp1:~# apt-get install apache2 php libapache2-mod-php php-mysql mysql-server
Sitio wp2.local (Nginx)
En ubuntu-wp2 se instaló y configuró Nginx, PHP7.2 y Mysql Server con otra copia de este blog para generar contenido.
root@ubuntu-wp2:~# apt-get install nginx php php-fpm php-mysql mysql-server
En /etc/nginx/sites-avaible/default se modificaron las siguientes lineas:
index index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.ht {
deny all;
}
Para diferenciar los sitios se modificó el encabezado agregando el nombre del Host.
Acceso a http://wp1.local desde la notebook

Acceso a http://wp2.local desde la notebook

Test de Stress
Se realizó desde un host externo con Apache Benchmark con 1000 accesos y 100 concurrencias a cada uno de los sitios publicados.
pablo@laptop:~$ ab -k -n1000 -c100 -H 'Accept-Encoding: gzip,deflate' http://wp1.local/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking wp1.local (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Apache/2.4.29
Server Hostname: wp1.local
Server Port: 80
Document Path: /
Document Length: 9488 bytes
Concurrency Level: 100
Time taken for tests: 34.707 seconds
Complete requests: 1000
Failed requests: 920
(Connect: 0, Receive: 0, Length: 920, Exceptions: 0)
Non-2xx responses: 913
Keep-Alive requests: 1000
Total transferred: 3575219 bytes
HTML transferred: 3264024 bytes
Requests per second: 28.81 [#/sec] (mean)
Time per request: 3470.670 [ms] (mean)
Time per request: 34.707 [ms] (mean, across all concurrent requests)
Transfer rate: 100.60 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 10.9 0 40
Processing: 173 985 3175.4 282 34662
Waiting: 173 985 3175.4 281 34662
Total: 173 989 3181.0 282 34702
Percentage of the requests served within a certain time (ms)
50% 282
66% 329
75% 370
80% 390
90% 2371
95% 3145
98% 4579
99% 12671
100% 34702 (longest request)
pablo@laptop:~$ ab -k -n1000 -c100 -H 'Accept-Encoding: gzip,deflate' http://wp2.local/
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking wp2.local (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: nginx/1.14.0
Server Hostname: wp2.local
Server Port: 80
Document Path: /
Document Length: 47713 bytes
Concurrency Level: 100
Time taken for tests: 22.371 seconds
Complete requests: 1000
Failed requests: 0
Keep-Alive requests: 0
Total transferred: 48204000 bytes
HTML transferred: 47713000 bytes
Requests per second: 44.70 [#/sec] (mean)
Time per request: 2237.120 [ms] (mean)
Time per request: 22.371 [ms] (mean, across all concurrent requests)
Transfer rate: 2104.23 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 16 27 12.7 26 291
Processing: 136 2100 330.7 2174 2508
Waiting: 88 2047 331.6 2123 2431
Total: 165 2127 330.2 2201 2541
Percentage of the requests served within a certain time (ms)
50% 2201
66% 2224
75% 2237
80% 2244
90% 2262
95% 2287
98% 2370
99% 2429
100% 2541 (longest request)
Estadísticas de HAProxy
