Разделить стенд и настройки нагрузочных экспериментов, ограничить число запросов на реплику в HAProxy и передавать X-Request-Id от балансировщика в API, сократить комментарии
This commit is contained in:
+14
-60
@@ -1,12 +1,6 @@
|
||||
# Local stand: HAProxy in front of interchangeable API replicas over shared
|
||||
# PostgreSQL (users, chats, messages, idempotency keys) and Valkey (sessions).
|
||||
# Only the balancer is published, on loopback. Credentials are files in
|
||||
# ./secrets created by `make secrets`; named volumes keep the data across
|
||||
# restarts, and only `make destroy` removes them.
|
||||
#
|
||||
# Two networks: edge joins the balancer and the API, data joins the API, the
|
||||
# migrations and the stores and has no way out. The balancer cannot reach the
|
||||
# stores, and the stores cannot reach anything outside.
|
||||
# PostgreSQL and Valkey. Only the balancer is published, on loopback; the data
|
||||
# network has no way out. The load-test knobs are in compose.bench.yaml.
|
||||
name: lab3
|
||||
|
||||
services:
|
||||
@@ -14,21 +8,13 @@ services:
|
||||
image: haproxy:3.4.7-alpine3.24@sha256:2caaf8b1a1ef67f3f1ea9b721f2821675d3ba4500fb518e23884fecb93e8dbaa
|
||||
volumes:
|
||||
- ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
environment:
|
||||
# 1 silences the log line of every successful request during load runs.
|
||||
LB_QUIET: ${LB_QUIET:-0}
|
||||
# One HAProxy thread per CPU of the limit below.
|
||||
LB_THREADS: ${LB_THREADS:-1}
|
||||
ports:
|
||||
# Loopback only; override with PUBLISH=127.0.0.1:28080 when 8080 is busy.
|
||||
- "${PUBLISH:-127.0.0.1:8080}:8080"
|
||||
# Read-only statistics page: state and checks of every replica.
|
||||
- "${STATS_PUBLISH:-127.0.0.1:8404}:8404"
|
||||
networks:
|
||||
- edge
|
||||
healthcheck:
|
||||
# Through the balancer itself: healthy once it can route to a ready
|
||||
# replica, so `compose up --wait` means "ready through the entry point".
|
||||
# Through the balancer: `up --wait` returns once a replica is reachable.
|
||||
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/health/ready"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
@@ -38,14 +24,12 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "${LB_CPUS:-0.5}"
|
||||
cpus: "0.5"
|
||||
memory: 128M
|
||||
|
||||
api:
|
||||
build: .
|
||||
image: mtusi-messenger:lab3
|
||||
# No container_name and no ports: the service scales, and clients reach
|
||||
# the replicas only through the balancer.
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
@@ -54,13 +38,8 @@ services:
|
||||
SESSION_STORE_URL_FILE: /run/secrets/session_store_url
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
# Above the balancer's detection time of 1.5 s (haproxy.cfg).
|
||||
APP_DRAIN_DELAY: ${APP_DRAIN_DELAY:-2s}
|
||||
DB_MAX_CONNS: ${DB_MAX_CONNS:-10}
|
||||
# About 90 % of the memory limit below; Go does not read the cgroup limit.
|
||||
GOMEMLIMIT: ${API_GOMEMLIMIT:-230MiB}
|
||||
# Empty disables the internal expvar listener; the benchmark sets :9090.
|
||||
APP_DEBUG_ADDR: ${APP_DEBUG_ADDR:-}
|
||||
# Go does not read the cgroup memory limit.
|
||||
GOMEMLIMIT: 230MiB
|
||||
secrets:
|
||||
- database_url
|
||||
- session_store_url
|
||||
@@ -74,16 +53,15 @@ services:
|
||||
condition: service_healthy
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
# Drain delay 2 s + shutdown timeout 8 s fit before Docker sends SIGKILL.
|
||||
# Drain delay 2 s plus shutdown timeout 8 s, before SIGKILL.
|
||||
stop_grace_period: 15s
|
||||
deploy:
|
||||
replicas: ${API_REPLICAS:-2}
|
||||
resources:
|
||||
limits:
|
||||
cpus: "${API_CPUS:-1.0}"
|
||||
memory: ${API_MEMORY:-256M}
|
||||
cpus: "1.0"
|
||||
memory: 256M
|
||||
|
||||
# One-shot: applies the schema once before the replicas start, then exits.
|
||||
migrate:
|
||||
image: mtusi-messenger:lab3
|
||||
entrypoint: ["/usr/local/bin/migrate"]
|
||||
@@ -108,8 +86,7 @@ services:
|
||||
|
||||
postgres:
|
||||
image: postgres:18.6-alpine3.24@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873
|
||||
# Ten replicas with ten connections each fit during a rolling update of
|
||||
# five, plus migrate and psql sessions.
|
||||
# 10 balancer slots x DB_MAX_CONNS 10, plus migrate and psql.
|
||||
command: ["postgres", "-c", "max_connections=150"]
|
||||
environment:
|
||||
POSTGRES_DB: messenger
|
||||
@@ -117,28 +94,24 @@ services:
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
secrets:
|
||||
- postgres_password
|
||||
# Since PostgreSQL 18 the image keeps PGDATA in a versioned directory
|
||||
# below /var/lib/postgresql, so the volume is mounted on the parent.
|
||||
# PostgreSQL 18 keeps PGDATA in a versioned directory below this one.
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql
|
||||
networks:
|
||||
- data
|
||||
healthcheck:
|
||||
# Over TCP: during first initialisation the image runs a temporary
|
||||
# server on the Unix socket only, which must not count as ready.
|
||||
# Over TCP: the first initialisation runs a temporary socket-only server.
|
||||
test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "messenger", "-d", "messenger"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 10s
|
||||
# A clean shutdown writes a checkpoint instead of leaving crash recovery
|
||||
# to the next start.
|
||||
stop_grace_period: 30s
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "${PG_CPUS:-1.0}"
|
||||
memory: ${PG_MEMORY:-512M}
|
||||
cpus: "1.0"
|
||||
memory: 512M
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:9.1.2-alpine3.24@sha256:48332870af354a799964c0012ae1194a0bf2bf894eb508f945810596dc2d8d11
|
||||
@@ -165,25 +138,6 @@ services:
|
||||
# maxmemory 256mb (valkey.conf) plus the server's own overhead.
|
||||
memory: 320M
|
||||
|
||||
# Load generator of the experiments (tools/loadgen). Only
|
||||
# `docker compose --profile bench run --rm loadgen ...` starts it; it talks to
|
||||
# the balancer and, for metrics, to the replicas' internal debug port.
|
||||
loadgen:
|
||||
profiles: ["bench"]
|
||||
build:
|
||||
context: .
|
||||
target: loadgen
|
||||
image: mtusi-messenger-loadgen:lab3
|
||||
volumes:
|
||||
- ${BENCH_OUT:-./bench-out}:/out
|
||||
networks:
|
||||
- edge
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "${LOADGEN_CPUS:-1.5}"
|
||||
memory: 512M
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
valkeydata:
|
||||
|
||||
Reference in New Issue
Block a user