ЛР3: HAProxy, реплики API, идемпотентность, отказы и rolling update, исследование масштабирования

This commit is contained in:
kolya5544
2026-10-03 05:10:45 +03:00
parent 0ab3a341aa
commit 7e6f66c3db
51 changed files with 6943 additions and 21 deletions
+9
View File
@@ -0,0 +1,9 @@
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: application/json
Retry-After: 1
X-Request-Id: lb-unavailable
Content-Length: 117
{"error":{"code":"unavailable","message":"Нет доступных реплик API","request_id":"lb-unavailable"}}
+54
View File
@@ -0,0 +1,54 @@
# Балансировщик lab3: HAProxy 3.0. Единственная публичная точка входа; API-реплики наружу не опубликованы.
global
log stdout format raw local0 notice
maxconn 4096
defaults
mode http
log global
option dontlognull
option forwardfor
# connect короткий: недоступная реплика быстро заменяется другой (redispatch)
timeout connect 1s
timeout client 30s
timeout server 30s
timeout http-request 10s
timeout http-keep-alive 5s
timeout queue 5s
retries 3
option redispatch 1
retry-on conn-failure empty-response response-timeout 0rtt-rejected
# Ошибки, созданные самим LB, отдаются в контрактном формате (JSON + Retry-After + X-Request-Id).
errorfile 502 /usr/local/etc/haproxy/errors/503.http
errorfile 503 /usr/local/etc/haproxy/errors/503.http
errorfile 504 /usr/local/etc/haproxy/errors/503.http
# Docker DNS (127.0.0.11): адреса реплик API обновляются без перезапуска LB (scale up/down, пересоздание контейнеров).
resolvers docker
nameserver dns 127.0.0.11:53
accepted_payload_size 8192
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold valid 2s
hold nx 2s
hold other 2s
hold obsolete 2s
frontend public
bind :8080
default_backend api
# Внутренний healthcheck самого LB (контейнерный HEALTHCHECK); наружу не публикуется.
frontend lb_health
bind :8081
monitor-uri /healthz
backend api
balance roundrobin
# Проверка готовности каждые 1 с; 2 неудачи подряд -> сервер исключён (обнаружение отказа <= ~3 с), 2 успеха -> возвращён.
option httpchk
http-check send meth GET uri /health/ready
http-check expect status 200
default-server check inter 1s fall 2 rise 2 resolvers docker init-addr none
server-template api 1-8 api:8080