feat: implement estim 4

This commit is contained in:
2026-11-06 05:12:28 +03:00
parent ec111aadfb
commit b48e71f433
29 changed files with 504 additions and 194 deletions
+8
View File
@@ -0,0 +1,8 @@
$ row counts after all runs (date 2026-11-06T02:07:36Z)
chats 84
users 292
messages 294274
message_idempotency 294274
$ database size
167 MB
+13
View File
@@ -0,0 +1,13 @@
$ date -u; podman stop -t 10 messenger-lab3_api_1; date -u
02:07:18.261
02:07:21.454
$ podman logs messenger-lab3_api_1 (shutdown sequence, UTC)
02:07:18.345 shutdown signal received, draining 3s 5s
02:07:21.345 server stopped
$ TZ=UTC podman logs -t messenger-lab3_lb_1 (backend state, UTC)
02:07:20.346 Server api/api2 is DOWN, reason: Layer7 wrong status, code: 503, info: "Service Unavailable", check duration: 0ms. 1 active and 0 backup
SIGTERM 02:07:18.345 -> LB marks DOWN by 503 readiness 02:07:20.346 (2.0 s, <= inter 1s x fall 2) -> listener closed 02:07:21.345 (drain 3 s); hook returned in 3.2 s.
HAProxy slot names (api1..api4 from server-template) are assigned by DNS order and do not match container numbers.
+12
View File
@@ -0,0 +1,12 @@
date: 2026-11-06T01:54:08Z
host: i5-11400H, 12 threads, 15Gi RAM, Linux 7.1.8-arch1-3
podman version 6.1.0
podman-compose version 1.6.0
go version go1.27.1 linux/amd64
images:
image: docker.io/library/postgres:18.6-alpine3.24
image: docker.io/library/redis:8.10.3-alpine3.23
image: docker.io/migrate/migrate:v4.20.1
image: localhost/messenger-api:lab3
image: docker.io/library/haproxy:3.4.7-alpine
limits: see evidence/limits.txt
+38 -5
View File
@@ -1,14 +1,47 @@
$ api replicas before
messenger-lab3_api_1 hostname=0405cf8a4a54 Up 10 seconds
messenger-lab3_api_2 hostname=2751ae93e6d1 Up 10 seconds
messenger-lab3_api_2 hostname=5a9ffe83734a Up About a minute (healthy)
messenger-lab3_api_1 hostname=ab01920585fe Up About a minute (healthy)
$ python3 tests/load.py --duration 30 --concurrency 4 --output evidence/failover-load-1.json & (background load during the test)
$ podman stats --no-stream (during load, before failure)
messenger-lab3_api_1 cpu=3.87% mem=88.06MB / 268.4MB
messenger-lab3_api_2 cpu=4.17% mem=92.08MB / 268.4MB
messenger-lab3_lb_1 cpu=2.81% mem=28.44MB / 67.11MB
messenger-lab3_postgres_1 cpu=12.21% mem=135.6MB / 536.9MB
messenger-lab3_redis_1 cpu=0.58% mem=6.857MB / 134.2MB
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 87, "failed_attempts": 1, "first_recovery_seconds": 2.52}
{"observed_instances_before": 2, "successful_writes": 131, "failed_attempts": 0, "first_recovery_seconds": 3.339}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
$ podman stats --no-stream (during load, one replica stopped)
messenger-lab3_api_2 cpu=5.01% mem=27.76MB / 268.4MB
messenger-lab3_lb_1 cpu=3.77% mem=29.78MB / 67.11MB
messenger-lab3_postgres_1 cpu=12.32% mem=133.1MB / 536.9MB
messenger-lab3_redis_1 cpu=0.59% mem=7.111MB / 134.2MB
$ background tests/load.py result
{
"lab": 3,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 30.0,
"elapsed_seconds": 30.008,
"concurrency": 4,
"successful_requests": 8712,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 290.322,
"successful_latency_ms": {
"p50": 13.117,
"p95": 17.627,
"p99": 23.947
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
$ api replicas after (stopped one = TARGET_INSTANCE_ID)
messenger-lab3_api_1 hostname=0405cf8a4a54 Up 26 seconds
messenger-lab3_api_2 hostname=2751ae93e6d1 Exited (0) 15 seconds ago
messenger-lab3_api_2 hostname=5a9ffe83734a Up 2 minutes (healthy)
messenger-lab3_api_1 hostname=ab01920585fe Exited (0) 22 seconds ago (healthy)
+38 -9
View File
@@ -1,18 +1,47 @@
$ api replicas before (api_2 restored with: podman compose start api)
messenger-lab3_api_1 hostname=0405cf8a4a54 Up 2 minutes
messenger-lab3_api_2 hostname=2751ae93e6d1 Up 19 seconds
$ curl -s localhost:8080/health/live (shift round-robin so the test write lands on the other replica)
{"status":"ok"}
$ api replicas before
messenger-lab3_api_2 hostname=5a9ffe83734a Up 2 minutes (healthy)
messenger-lab3_api_1 hostname=ab01920585fe Up 4 seconds (healthy)
$ python3 tests/load.py --duration 30 --concurrency 4 --output evidence/failover-load-2.json & (background load during the test)
$ podman stats --no-stream (during load, before failure)
messenger-lab3_api_1 cpu=4.21% mem=47.89MB / 268.4MB
messenger-lab3_api_2 cpu=5.90% mem=92.86MB / 268.4MB
messenger-lab3_lb_1 cpu=4.60% mem=31.47MB / 67.11MB
messenger-lab3_postgres_1 cpu=12.45% mem=148.5MB / 536.9MB
messenger-lab3_redis_1 cpu=0.59% mem=6.611MB / 134.2MB
$ make test-failover ACTION_SCRIPT=scripts/stop-one.sh
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 81, "failed_attempts": 1, "first_recovery_seconds": 2.424}
{"observed_instances_before": 2, "successful_writes": 132, "failed_attempts": 0, "first_recovery_seconds": 3.37}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
$ podman stats --no-stream (during load, one replica stopped)
messenger-lab3_api_1 cpu=7.73% mem=33.08MB / 268.4MB
messenger-lab3_lb_1 cpu=4.84% mem=32.26MB / 67.11MB
messenger-lab3_postgres_1 cpu=12.54% mem=146.1MB / 536.9MB
messenger-lab3_redis_1 cpu=0.59% mem=7.373MB / 134.2MB
$ background tests/load.py result
{
"lab": 3,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 30.0,
"elapsed_seconds": 30.013,
"concurrency": 4,
"successful_requests": 9508,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 316.791,
"successful_latency_ms": {
"p50": 12.105,
"p95": 16.14,
"p99": 22.351
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
$ api replicas after (stopped one = TARGET_INSTANCE_ID)
messenger-lab3_api_1 hostname=0405cf8a4a54 Exited (0) 15 seconds ago
messenger-lab3_api_2 hostname=2751ae93e6d1 Up 35 seconds
messenger-lab3_api_2 hostname=5a9ffe83734a Exited (0) 22 seconds ago (healthy)
messenger-lab3_api_1 hostname=ab01920585fe Up 35 seconds (healthy)
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 3,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 30.0,
"elapsed_seconds": 30.008,
"concurrency": 4,
"successful_requests": 8712,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 290.322,
"successful_latency_ms": {
"p50": 13.117,
"p95": 17.627,
"p99": 23.947
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 3,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 30.0,
"elapsed_seconds": 30.013,
"concurrency": 4,
"successful_requests": 9508,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 316.791,
"successful_latency_ms": {
"p50": 12.105,
"p95": 16.14,
"p99": 22.351
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+1 -1
View File
@@ -4,5 +4,5 @@ successful responses (201): 20
failed requests: 0 []
distinct message ids in responses: 1
messages stored in history: 1
instances that served requests: ['0405cf8a4a54', '2751ae93e6d1']
instances that served requests: ['56e8d4ca6c28', 'd63350b561c6']
OK: exactly one message created
+10 -12
View File
@@ -1,18 +1,16 @@
20 GET /api/v1/users/me through LB (localhost:8080) with ONE bearer session, no re-login
X-Instance-Id 0405cf8a4a54 responses 10
X-Instance-Id 2751ae93e6d1 responses 10
X-Instance-Id 56e8d4ca6c28 responses 10
X-Instance-Id d63350b561c6 responses 10
$ podman ps --filter label=com.docker.compose.service=api --format "{{.Names}} {{.ID}} {{.Status}}"
messenger-lab3_api_1 0405cf8a4a54 Up 54 seconds
messenger-lab3_api_2 2751ae93e6d1 Up 53 seconds
$ podman ps (api replicas: name, container ID = hostname = X-Instance-Id)
messenger-lab3_api_1 d63350b561c6 Up 41 seconds (healthy)
messenger-lab3_api_2 56e8d4ca6c28 Up About a minute (healthy)
messenger-lab3_api_1 hostname=d63350b561c6
messenger-lab3_api_2 hostname=56e8d4ca6c28
$ podman inspect -f "{{.Name}} hostname={{.Config.Hostname}} ports={{.NetworkSettings.Ports}}" api replicas
messenger-lab3_api_1 hostname=0405cf8a4a54 ports=map[8080/tcp:[]]
messenger-lab3_api_2 hostname=2751ae93e6d1 ports=map[8080/tcp:[]]
$ podman ps --format "{{.Names}} {{.Ports}}" (only lb publishes 8080)
messenger-lab3_postgres_1 127.0.0.1:55432->5432/tcp
messenger-lab3_redis_1 127.0.0.1:56379->6379/tcp
$ podman ps (published ports: only lb exposes 8080)
messenger-lab3_api_1 8080/tcp
messenger-lab3_api_2 8080/tcp
messenger-lab3_lb_1 0.0.0.0:8080->8080/tcp
messenger-lab3_postgres_1 127.0.0.1:55432->5432/tcp
messenger-lab3_redis_1 127.0.0.1:56379->6379/tcp
+23
View File
@@ -0,0 +1,23 @@
$ podman inspect: limits, networks, published ports
messenger-lab3_api_1 cpus=1000000000 memory=268435456 networks=messenger-lab3_backend messenger-lab3_edge ports=
messenger-lab3_api_2 cpus=1000000000 memory=268435456 networks=messenger-lab3_backend messenger-lab3_edge ports=
messenger-lab3_lb_1 cpus=500000000 memory=67108864 networks=messenger-lab3_edge ports=8080/tcp->0.0.0.0:8080
messenger-lab3_migrate_1 cpus=500000000 memory=67108864 networks=messenger-lab3_backend ports=
messenger-lab3_postgres_1 cpus=1000000000 memory=536870912 networks=messenger-lab3_backend ports=5432/tcp->127.0.0.1:55432
messenger-lab3_redis_1 cpus=500000000 memory=134217728 networks=messenger-lab3_backend ports=6379/tcp->127.0.0.1:56379
$ ls /run/secrets in each running container
messenger-lab3_api_1: cache_url database_url
messenger-lab3_api_2: cache_url database_url
messenger-lab3_lb_1:
messenger-lab3_postgres_1: postgres_password
messenger-lab3_redis_1:
migrate (one-shot): /run/secrets/database_url
$ lb sees only the edge network
postgres: not resolvable from lb
redis: not resolvable from lb
10.89.4.28 api.dns.podman api.dns.podman api
$ grep -c container_name compose.yaml
0
+15 -8
View File
@@ -1,15 +1,22 @@
$ podman ps -a --filter label=com.docker.compose.service=migrate
messenger-lab3_migrate_1 Exited (0) 53 seconds ago
$ podman ps -a (migrate is one-shot, exited 0; api replicas started after it)
messenger-lab3_migrate_1 Exited (0) About a minute ago
$ podman logs messenger-lab3_migrate_1
1/u init (10.119477ms)
2/u message_idempotency (14.878187ms)
$ podman logs migrate (schema already at version 2 in the kept volume; repeated run is safe)
no change
no change
no change
$ podman logs messenger-lab3_api_1 | grep -i migrat (API replicas do not run migrations)
0
$ API replicas run no migrations (count of "migrat" in logs)
api_1: 0
api_2: 0
$ psql: SELECT version, dirty FROM schema_migrations
$ SELECT version, dirty FROM schema_migrations
2|f
$ \dt
chat_members
chats
message_idempotency
messages
schema_migrations
users
+13 -13
View File
@@ -1,10 +1,10 @@
$ containers before
messenger-lab3_postgres_1 8c509b4f5143 Up About a minute (healthy)
messenger-lab3_redis_1 b5db2a433051 Up About a minute (healthy)
messenger-lab3_migrate_1 9fa71320cdba Exited (0) About a minute ago
messenger-lab3_api_1 0405cf8a4a54 Up About a minute
messenger-lab3_api_2 2751ae93e6d1 Up About a minute
messenger-lab3_lb_1 d3a35fe2295d Up About a minute
messenger-lab3_api_1 d63350b561c6 Up 42 seconds (healthy)
messenger-lab3_api_2 56e8d4ca6c28 Up About a minute (healthy)
messenger-lab3_lb_1 d0ec4e5311dd Up 4 minutes
messenger-lab3_migrate_1 82c01bec10d9 Exited (0) 14 minutes ago
messenger-lab3_postgres_1 0d8a6c71fcaf Up 13 minutes (healthy)
messenger-lab3_redis_1 37f40fddaa42 Up 13 minutes (healthy)
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
@@ -12,13 +12,13 @@ Executing explicit persistence hook; hook output suppressed to avoid leaking sec
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
exit=0
$ containers after (same IDs, fresh Up time = restarted, volumes kept)
messenger-lab3_postgres_1 8c509b4f5143 Up 1 second (healthy)
messenger-lab3_redis_1 b5db2a433051 Up 1 second (healthy)
messenger-lab3_migrate_1 9fa71320cdba Exited (0) Less than a second ago
messenger-lab3_api_1 0405cf8a4a54 Up Less than a second
messenger-lab3_api_2 2751ae93e6d1 Up Less than a second
messenger-lab3_lb_1 d3a35fe2295d Up Less than a second
$ containers after (same IDs, restarted, volumes kept)
messenger-lab3_api_1 d63350b561c6 Up 2 seconds (healthy)
messenger-lab3_api_2 56e8d4ca6c28 Up 1 second (healthy)
messenger-lab3_lb_1 d0ec4e5311dd Up 2 seconds
messenger-lab3_migrate_1 82c01bec10d9 Exited (0) 14 minutes ago
messenger-lab3_postgres_1 0d8a6c71fcaf Up 2 seconds (healthy)
messenger-lab3_redis_1 37f40fddaa42 Up 1 second (healthy)
$ podman volume ls
messenger-lab3_pgdata
+17
View File
@@ -0,0 +1,17 @@
{
"lab": 3,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 60.0,
"elapsed_seconds": 60.013,
"concurrency": 4,
"successful_requests": 17311,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 288.453,
"successful_latency_ms": {
"p50": 13.202,
"p95": 17.032,
"p99": 20.075
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+45
View File
@@ -0,0 +1,45 @@
$ api replicas before
messenger-lab3_api_1 container=ab01920585fe image=3fcba3e82597 revision=1793930539 health=healthy
messenger-lab3_api_2 container=5a9ffe83734a image=3fcba3e82597 revision=1793930539 health=healthy
$ python3 tests/load.py --duration 60 --concurrency 4 --output evidence/rolling-load.json & (background load)
$ podman stats --no-stream (during load, before update)
messenger-lab3_api_1 cpu=5.87% mem=106.7MB / 268.4MB
messenger-lab3_api_2 cpu=2.47% mem=47.7MB / 268.4MB
messenger-lab3_lb_1 cpu=4.56% mem=31.62MB / 67.11MB
messenger-lab3_postgres_1 cpu=12.33% mem=156.8MB / 536.9MB
messenger-lab3_redis_1 cpu=0.59% mem=7.361MB / 134.2MB
$ scripts/rolling-update.sh (build new image -> migrate once -> replace replicas one by one)
exit=0 duration=21s
migrate: no change
$ podman stats --no-stream (during load, after update)
messenger-lab3_api_1 cpu=4.77% mem=12.05MB / 268.4MB
messenger-lab3_api_2 cpu=7.42% mem=11.21MB / 268.4MB
messenger-lab3_lb_1 cpu=4.78% mem=31.83MB / 67.11MB
messenger-lab3_postgres_1 cpu=12.49% mem=159.6MB / 536.9MB
messenger-lab3_redis_1 cpu=0.59% mem=7.119MB / 134.2MB
$ background tests/load.py result
{
"lab": 3,
"workload": "closed-loop POST messages; no automatic retries",
"requested_duration_seconds": 60.0,
"elapsed_seconds": 60.013,
"concurrency": 4,
"successful_requests": 17311,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 288.453,
"successful_latency_ms": {
"p50": 13.202,
"p95": 17.032,
"p99": 20.075
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
$ api replicas after (new containers, new image and revision)
messenger-lab3_api_1 container=d63350b561c6 image=3ab3deda3163 revision=1793930771 health=healthy
messenger-lab3_api_2 container=56e8d4ca6c28 image=3ab3deda3163 revision=1793930771 health=healthy
+19 -18
View File
@@ -2,41 +2,42 @@
? messenger/internal/config [no test files]
? messenger/internal/domain [no test files]
=== RUN TestSessionExpiry
--- PASS: TestSessionExpiry (3.09s)
--- PASS: TestSessionExpiry (3.11s)
=== RUN TestLogout
--- PASS: TestLogout (0.08s)
--- PASS: TestLogout (0.13s)
=== RUN TestWrongPassword
--- PASS: TestWrongPassword (0.10s)
--- PASS: TestWrongPassword (0.11s)
=== RUN TestRedisUnavailable
redis: 2026/11/06 03:16:52 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 03:16:52 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 03:16:53 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 03:16:53 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 03:16:54 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 03:16:54 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
--- PASS: TestRedisUnavailable (2.89s)
redis: 2026/11/06 05:07:57 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 05:07:57 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 05:07:58 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 05:07:58 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 05:07:59 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
redis: 2026/11/06 05:07:59 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
--- PASS: TestRedisUnavailable (2.94s)
=== RUN TestDatabaseUnavailable
--- PASS: TestDatabaseUnavailable (0.17s)
--- PASS: TestDatabaseUnavailable (0.20s)
=== RUN TestInvalidJSON
--- PASS: TestInvalidJSON (0.01s)
=== RUN TestForeignChat
--- PASS: TestForeignChat (0.17s)
redis: 2026/11/06 05:08:00 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
--- PASS: TestForeignChat (0.23s)
=== RUN TestEmptyMessage
--- PASS: TestEmptyMessage (0.08s)
=== RUN TestDuplicateUsername
--- PASS: TestDuplicateUsername (0.09s)
--- PASS: TestDuplicateUsername (0.10s)
=== RUN TestPaginationMultiplePages
--- PASS: TestPaginationMultiplePages (0.08s)
--- PASS: TestPaginationMultiplePages (0.09s)
=== RUN TestConcurrentMessages
--- PASS: TestConcurrentMessages (0.52s)
--- PASS: TestConcurrentMessages (0.57s)
PASS
ok messenger/internal/handler 7.273s
ok messenger/internal/handler 7.578s
=== RUN TestRegisterUsernameRace
--- PASS: TestRegisterUsernameRace (0.02s)
--- PASS: TestRegisterUsernameRace (0.07s)
=== RUN TestCreateChatRollback
--- PASS: TestCreateChatRollback (0.02s)
PASS
ok messenger/internal/repository/postgres 0.043s
ok messenger/internal/repository/postgres 0.088s
? messenger/internal/repository/redis [no test files]
? messenger/internal/router [no test files]
? messenger/internal/service [no test files]