
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 balancee el tráfico http://pablo.sarubbi.com.ar entre los servidores web implementados en ubuntu-wp1 y ubuntu-wp2.
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
default_backend nodes
backend nodes
mode http
balance roundrobin
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
option httpchk HEAD / HTTP/1.1\r\nHost:localhost
server wp1 10.56.142.244:80 check
server wp2 10.56.142.34:80 check
Los parámetros stats habilitan una página de estadisticas sobre el uso de HAProxy
Sitio pablosarubbi.com.ar en ubuntu-wp1 (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 pablosarubbi.com.ar en ubuntu-wp2 (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.
Pruebas de balanceo
Primer acceso a http://pablo.sarubbi.com.ar reenvía al sitio en ubuntu-wp1

El segundo acceso a http://pablo.sarubbi.com.ar reenvía al sitio en ubuntu-wp2

Test de Stress
Se realizó desde un host externo con Apache Benchmark con 1000 accesos con 100 concurrencias.
pablo@laptop:~$ ab -k -n1000 -c100 -H 'Accept-Encoding: gzip,deflate' http://pablo.sarubbi.com.ar/
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 pablo.sarubbi.com.ar (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: pablo.sarubbi.com.ar
Server Port: 80
Document Path: /
Document Length: 47713 bytes
Concurrency Level: 100
Time taken for tests: 37.221 seconds
Complete requests: 1000
Failed requests: 300
(Connect: 0, Receive: 0, Length: 300, Exceptions: 0)
Non-2xx responses: 235
Keep-Alive requests: 300
Total transferred: 35093415 bytes
HTML transferred: 34643711 bytes
Requests per second: 26.87 [#/sec] (mean)
Time per request: 3722.117 [ms] (mean)
Time per request: 37.221 [ms] (mean, across all concurrent requests)
Transfer rate: 920.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 18 12.6 23 46
Processing: 37 1883 2420.1 1592 36583
Waiting: 37 1842 2424.7 1538 36583
Total: 41 1902 2421.3 1612 36602
Percentage of the requests served within a certain time (ms)
50% 1612
66% 2129
75% 2236
80% 2364
90% 2853
95% 3824
98% 9170
99% 9721
100% 36602 (longest request)
Estadísticas de HAProxy

Conclusiones
Se evidencia que HAProxy ejecuta correctamente el balanceo de carga, aunque en este entorno de pruebas se pudo evidenciar que con la configuración por default, y contenedores con 512MB de RAM, el Nginx mantiene un comportamiento mucho mas estable que el Apache.