ЛР 3 — БПИ2302 — Щербацевич — на 5

This commit is contained in:
2026-11-11 23:55:42 +03:00
parent 0ab3a341aa
commit 7aa4ea541b
76 changed files with 4627 additions and 34 deletions
+18
View File
@@ -0,0 +1,18 @@
date: 2026-10-30 (стенд после up --scale api=2; имена контейнеров scale могут быть api-1/api-2 или api-4/api-5)
command:
docker compose --env-file .env ps --format "table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
observed (healthy two-replica topology; API has no host port):
NAME IMAGE STATUS PORTS
mtusi-lab3-api-4 mtusi-lab3-api Up (healthy) 8080/tcp
mtusi-lab3-api-5 mtusi-lab3-api Up (healthy) 8080/tcp
mtusi-lab3-lb-1 haproxy:3.2-bookworm@sha256:baecd003ae5c2376e58d04a5b2ffc7d82d30e9bebe2869f76222b819f719dee3 Up (healthy) 127.0.0.1:8080->8080/tcp, [::1]:8080->8080
mtusi-lab3-postgres-1 postgres:16.10-bookworm@sha256:38471f330eb885e04de130b768d6db4e10469e2311879c7e5c699f6d2d8a1c74 Up (healthy) 127.0.0.1:5433->5432/tcp
mtusi-lab3-redis-1 redis:7.4.6-alpine@sha256:3b73847e72874be07e6657b129a94761662b79bc0f679273757d4218573b2a98 Up (healthy) 127.0.0.1:6379->6379/tcp
Notes:
- API 8080/tcp is the container port only; it is not published on the host.
- Public entry is only the lb mapping on loopback IPv4 and IPv6.
- migrate is a one-shot container (Exited 0 after schema apply), not a replica.
+15
View File
@@ -0,0 +1,15 @@
date: 2026-10-30T16:04:40Z
command: python student-tests/failover.py
# ACTION_SCRIPT=scripts/stop-one.cmd TARGET_INSTANCE_ID from X-Instance-Id
first run (api-1 stopped, api-2 continued):
{"observed_instances_before": 2, "successful_writes": 91, "failed_attempts": 2, "first_recovery_seconds": 2.464}
PASS: failover preserved confirmed data and existing session.
after restore api-1:
second run:
{"observed_instances_before": 2, "successful_writes": 90, "failed_attempts": 2, "first_recovery_seconds": 2.74}
PASS: failover preserved confirmed data and existing session.
docker compose ps after first failover: api-1 Exited, api-2 healthy.
Manual stop of the other replica: evidence/sequential_stop_api2.json
+24
View File
@@ -0,0 +1,24 @@
{
"date": "2026-10-30T16:04:19Z",
"base_url": "http://127.0.0.1:8080",
"instances": {
"unique_instance_ids": [
"46e274e33049",
"f383126bd2be"
],
"samples": 40,
"counts": {
"46e274e33049": 20,
"f383126bd2be": 20
}
},
"idempotent_message_id_present": true,
"concurrent_key": {
"message_id": "1e79d3a4-62ee-405a-917e-5d26042f46a2",
"instances": [
"46e274e33049",
"f383126bd2be"
],
"successes": 12
}
}
+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.935,
"concurrency": 4,
"successful_requests": 60,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 1.94,
"successful_latency_ms": {
"p50": 2021.759,
"p95": 2060.46,
"p99": 2122.76
},
"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": 20.0,
"elapsed_seconds": 21.342,
"concurrency": 8,
"successful_requests": 80,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 3.749,
"successful_latency_ms": {
"p50": 2019.024,
"p95": 2075.506,
"p99": 2244.884
},
"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": 15.0,
"elapsed_seconds": 15.624,
"concurrency": 8,
"successful_requests": 1479,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 94.66,
"successful_latency_ms": {
"p50": 80.014,
"p95": 203.278,
"p99": 282.145
},
"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": 15.0,
"elapsed_seconds": 15.727,
"concurrency": 8,
"successful_requests": 1377,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 87.559,
"successful_latency_ms": {
"p50": 75.138,
"p95": 266.728,
"p99": 377.907
},
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
}
+4
View File
@@ -0,0 +1,4 @@
date: 2026-10-30T16:06:20Z
command: python student-tests/persistence_hook.py
# ACTION_SCRIPT=scripts/restart.cmd — docker compose restart postgres redis api lb, volumes kept
result: PASS: persistence preserved confirmed data and existing session.
+18
View File
@@ -0,0 +1,18 @@
{
"date": "2026-10-30T16:14:24Z",
"replaced": [
"9fe46a8ef3ce",
"4d6d0836aa27"
],
"replicas_before": [
"9fe46a8ef3ce",
"4d6d0836aa27"
],
"replicas_after": [
"eb055e557646",
"5ea08fe69111"
],
"successful_writes": 1980,
"failed_writes": 24,
"error_ratio": 0.011976
}
+46
View File
@@ -0,0 +1,46 @@
{
"date": "2026-10-30T16:06:00Z",
"note": "Поочерёдный останов каждой API-реплики. Окно публичного failover — 15 с (tests/resilience.py). Окно ручного останова api-2 — 12 с. successful_rps = успешные POST / длительность окна. Closed-loop клиент.",
"replicas": {
"mtusi-lab3-api-1": "f383126bd2be",
"mtusi-lab3-api-2": "46e274e33049"
},
"stops": [
{
"target": "mtusi-lab3-api-1",
"instance_id": "from X-Instance-Id via stop-one.cmd",
"command": "python student-tests/failover.py",
"window_seconds": 15,
"successful_writes": 91,
"failed_attempts": 2,
"error_ratio": 0.0215,
"successful_rps": 6.067,
"first_recovery_seconds": 2.464,
"ps_after": "api-1 Exited, api-2 healthy"
},
{
"target": "mtusi-lab3-api-1",
"command": "restore then python student-tests/failover.py",
"window_seconds": 15,
"successful_writes": 90,
"failed_attempts": 2,
"error_ratio": 0.0217,
"successful_rps": 6.0,
"first_recovery_seconds": 2.74,
"note": "Повтор публичного failover после restore; снова остановлен контейнер, который обслужил первое сообщение."
},
{
"target": "mtusi-lab3-api-2",
"instance_id": "46e274e33049",
"command": "docker stop -t 5 mtusi-lab3-api-2 under POST load",
"window_seconds": 12,
"successful_writes": 46,
"failed_attempts": 1,
"error_ratio": 0.0213,
"successful_rps": 3.833,
"first_recovery_seconds": 0.031,
"instances_after_stop": ["f383126bd2be"],
"ps_after": "api-2 Exited, api-1 healthy"
}
]
}
+14
View File
@@ -0,0 +1,14 @@
{
"replicas": {
"mtusi-lab3-api-1": "f383126bd2be",
"mtusi-lab3-api-2": "46e274e33049"
},
"writes_ok": 46,
"writes_err": 1,
"first_recovery_s": 0.03141460000006191,
"instances_after_stop": [
"f383126bd2be"
],
"ps_before": "mtusi-lab3-api-1 Up 23 seconds (healthy)\nmtusi-lab3-api-2 Up 23 seconds (healthy)\nmtusi-lab3-lb-1 Up 24 seconds (healthy)\nmtusi-lab3-migrate-1 Exited (0) 34 seconds ago\nmtusi-lab3-postgres-1 Up 23 seconds (healthy)\nmtusi-lab3-redis-1 Up 23 seconds (healthy)\n",
"ps_after": "mtusi-lab3-api-1 Up 36 seconds (healthy)\nmtusi-lab3-api-2 Exited (0) 12 seconds ago\nmtusi-lab3-lb-1 Up 37 seconds (healthy)\nmtusi-lab3-migrate-1 Exited (0) 48 seconds ago\nmtusi-lab3-postgres-1 Up 36 seconds (healthy)\nmtusi-lab3-redis-1 Up 37 seconds (healthy)\n"
}
+3
View File
@@ -0,0 +1,3 @@
date: 2026-10-30T16:04:00Z
command: python tests/smoke.py --base-url http://127.0.0.1:8080
result: PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
+295
View File
@@ -0,0 +1,295 @@
{
"date": "2026-10-30T16:17:53Z",
"hypothesis": "При фиксированном суммарном CPU/RAM добавление API-реплик перестаёт помогать (и может снизить RPS), когда узкое место — CPU процессов API: PostgreSQL на этом профиле не насыщается.",
"profile": {
"duration_seconds": 20.0,
"concurrency": 8,
"warmup_seconds": 5.0,
"workload": "closed-loop POST /messages through HAProxy"
},
"fixed_total_budget": [
{
"elapsed_seconds": 20.907,
"concurrency": 8,
"successful_requests": 2678,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 128.093,
"successful_latency_ms": {
"p50": 51.921,
"p95": 108.599,
"p99": 156.367
},
"docker_stats": [
{
"name": "mtusi-lab3-api-4",
"cpu": "13.84%",
"mem": "89.5MiB / 512MiB"
},
{
"name": "mtusi-lab3-lb-1",
"cpu": "0.09%",
"mem": "28.19MiB / 64MiB"
},
{
"name": "mtusi-lab3-postgres-1",
"cpu": "0.06%",
"mem": "52.93MiB / 512MiB"
},
{
"name": "mtusi-lab3-redis-1",
"cpu": "2.34%",
"mem": "9.738MiB / 128MiB"
}
],
"label": "fixed-1",
"replicas": 1,
"cpus_each": 1.0,
"memory_mb_each": 512,
"total_cpu": 1.0,
"total_memory_mb": 512
},
{
"elapsed_seconds": 20.894,
"concurrency": 8,
"successful_requests": 2246,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 107.496,
"successful_latency_ms": {
"p50": 71.633,
"p95": 189.116,
"p99": 245.528
},
"docker_stats": [
{
"name": "mtusi-lab3-api-5",
"cpu": "24.21%",
"mem": "72.12MiB / 256MiB"
},
{
"name": "mtusi-lab3-api-4",
"cpu": "0.71%",
"mem": "91.05MiB / 256MiB"
},
{
"name": "mtusi-lab3-lb-1",
"cpu": "0.31%",
"mem": "28.9MiB / 64MiB"
},
{
"name": "mtusi-lab3-postgres-1",
"cpu": "4.47%",
"mem": "73.19MiB / 512MiB"
},
{
"name": "mtusi-lab3-redis-1",
"cpu": "0.33%",
"mem": "9.035MiB / 128MiB"
}
],
"label": "fixed-2",
"replicas": 2,
"cpus_each": 0.5,
"memory_mb_each": 256,
"total_cpu": 1.0,
"total_memory_mb": 512
},
{
"elapsed_seconds": 21.006,
"concurrency": 8,
"successful_requests": 1456,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 69.315,
"successful_latency_ms": {
"p50": 94.785,
"p95": 292.96,
"p99": 400.018
},
"docker_stats": [
{
"name": "mtusi-lab3-api-7",
"cpu": "16.08%",
"mem": "79.37MiB / 128MiB"
},
{
"name": "mtusi-lab3-api-6",
"cpu": "11.19%",
"mem": "76.64MiB / 128MiB"
},
{
"name": "mtusi-lab3-api-5",
"cpu": "8.82%",
"mem": "83.37MiB / 128MiB"
},
{
"name": "mtusi-lab3-api-4",
"cpu": "5.77%",
"mem": "98.27MiB / 128MiB"
},
{
"name": "mtusi-lab3-lb-1",
"cpu": "0.48%",
"mem": "29.2MiB / 64MiB"
},
{
"name": "mtusi-lab3-postgres-1",
"cpu": "0.05%",
"mem": "94.67MiB / 512MiB"
},
{
"name": "mtusi-lab3-redis-1",
"cpu": "2.17%",
"mem": "8.914MiB / 128MiB"
}
],
"label": "fixed-4",
"replicas": 4,
"cpus_each": 0.25,
"memory_mb_each": 128,
"total_cpu": 1.0,
"total_memory_mb": 512
}
],
"growing_resources": [
{
"elapsed_seconds": 21.009,
"concurrency": 8,
"successful_requests": 1031,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 49.073,
"successful_latency_ms": {
"p50": 111.033,
"p95": 302.796,
"p99": 399.196
},
"docker_stats": [
{
"name": "mtusi-lab3-api-5",
"cpu": "4.23%",
"mem": "76.67MiB / 128MiB"
},
{
"name": "mtusi-lab3-api-4",
"cpu": "0.43%",
"mem": "89.02MiB / 128MiB"
},
{
"name": "mtusi-lab3-lb-1",
"cpu": "0.13%",
"mem": "29.92MiB / 64MiB"
},
{
"name": "mtusi-lab3-postgres-1",
"cpu": "4.40%",
"mem": "76.54MiB / 512MiB"
},
{
"name": "mtusi-lab3-redis-1",
"cpu": "2.30%",
"mem": "9.145MiB / 128MiB"
}
],
"label": "grow-2x0.25",
"replicas": 2,
"cpus_each": 0.25,
"memory_mb_each": 128,
"total_cpu": 0.5,
"total_memory_mb": 256
},
{
"elapsed_seconds": 20.917,
"concurrency": 8,
"successful_requests": 2206,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 105.463,
"successful_latency_ms": {
"p50": 75.963,
"p95": 184.365,
"p99": 212.521
},
"docker_stats": [
{
"name": "mtusi-lab3-api-5",
"cpu": "0.58%",
"mem": "83.3MiB / 256MiB"
},
{
"name": "mtusi-lab3-api-4",
"cpu": "18.11%",
"mem": "89.97MiB / 256MiB"
},
{
"name": "mtusi-lab3-lb-1",
"cpu": "4.50%",
"mem": "30.62MiB / 64MiB"
},
{
"name": "mtusi-lab3-postgres-1",
"cpu": "0.08%",
"mem": "78.58MiB / 512MiB"
},
{
"name": "mtusi-lab3-redis-1",
"cpu": "0.36%",
"mem": "9.082MiB / 128MiB"
}
],
"label": "grow-2x0.50",
"replicas": 2,
"cpus_each": 0.5,
"memory_mb_each": 256,
"total_cpu": 1.0,
"total_memory_mb": 512
},
{
"elapsed_seconds": 20.827,
"concurrency": 8,
"successful_requests": 4602,
"failed_requests": 0,
"error_ratio": 0.0,
"successful_rps": 220.96,
"successful_latency_ms": {
"p50": 29.331,
"p95": 82.961,
"p99": 105.895
},
"docker_stats": [
{
"name": "mtusi-lab3-api-5",
"cpu": "1.21%",
"mem": "87.79MiB / 512MiB"
},
{
"name": "mtusi-lab3-api-4",
"cpu": "27.65%",
"mem": "90.96MiB / 512MiB"
},
{
"name": "mtusi-lab3-lb-1",
"cpu": "5.02%",
"mem": "31.52MiB / 64MiB"
},
{
"name": "mtusi-lab3-postgres-1",
"cpu": "0.18%",
"mem": "82.41MiB / 512MiB"
},
{
"name": "mtusi-lab3-redis-1",
"cpu": "0.35%",
"mem": "8.906MiB / 128MiB"
}
],
"label": "grow-2x1.00",
"replicas": 2,
"cpus_each": 1.0,
"memory_mb_each": 512,
"total_cpu": 2.0,
"total_memory_mb": 1024
}
]
}
+12
View File
@@ -0,0 +1,12 @@
<svg xmlns="http://www.w3.org/2000/svg" width="820" height="420" viewBox="0 0 820 420">
<rect width="100%" height="100%" fill="white"/>
<text x="410.0" y="28" text-anchor="middle" font-size="16" font-weight="700" font-family="Segoe UI, Arial">Fixed total 1.0 CPU and 512 MiB for all API replicas</text>
<line x1="70" y1="50.0" x2="790" y2="50.0" stroke="#e2e8f0"/><text x="62" y="54.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">147</text><line x1="70" y1="125.0" x2="790" y2="125.0" stroke="#e2e8f0"/><text x="62" y="129.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">110</text><line x1="70" y1="200.0" x2="790" y2="200.0" stroke="#e2e8f0"/><text x="62" y="204.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">74</text><line x1="70" y1="275.0" x2="790" y2="275.0" stroke="#e2e8f0"/><text x="62" y="279.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">37</text><line x1="70" y1="350.0" x2="790" y2="350.0" stroke="#e2e8f0"/><text x="62" y="354.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">0</text>
<line x1="70" y1="50" x2="70" y2="350" stroke="#2d3748"/>
<line x1="70" y1="350" x2="790" y2="350" stroke="#2d3748"/>
<rect x="103.6" y="89.1" width="172.8" height="260.9" fill="#2c5282"/><rect x="343.6" y="131.1" width="172.8" height="218.9" fill="#2c5282"/><rect x="583.6" y="208.8" width="172.8" height="141.2" fill="#2c5282"/>
<text x="190.0" y="81.1" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">128.1</text><text x="430.0" y="123.1" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">107.5</text><text x="670.0" y="200.8" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">69.3</text>
<text x="190.0" y="392" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">1 replica</text><text x="430.0" y="392" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">2 replicas</text><text x="670.0" y="392" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">4 replicas</text>
<text x="410.0" y="412" text-anchor="middle" font-size="12" fill="#4a5568" font-family="Segoe UI, Arial">API replicas (same total CPU/RAM)</text>
<text x="16" y="200.0" text-anchor="middle" font-size="12" fill="#4a5568" font-family="Segoe UI, Arial" transform="rotate(-90 16 200.0)">successful RPS</text>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

+12
View File
@@ -0,0 +1,12 @@
<svg xmlns="http://www.w3.org/2000/svg" width="820" height="420" viewBox="0 0 820 420">
<rect width="100%" height="100%" fill="white"/>
<text x="410.0" y="28" text-anchor="middle" font-size="16" font-weight="700" font-family="Segoe UI, Arial">Two API replicas, growing CPU/RAM budget</text>
<line x1="70" y1="50.0" x2="790" y2="50.0" stroke="#e2e8f0"/><text x="62" y="54.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">254</text><line x1="70" y1="125.0" x2="790" y2="125.0" stroke="#e2e8f0"/><text x="62" y="129.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">191</text><line x1="70" y1="200.0" x2="790" y2="200.0" stroke="#e2e8f0"/><text x="62" y="204.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">127</text><line x1="70" y1="275.0" x2="790" y2="275.0" stroke="#e2e8f0"/><text x="62" y="279.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">64</text><line x1="70" y1="350.0" x2="790" y2="350.0" stroke="#e2e8f0"/><text x="62" y="354.0" text-anchor="end" font-size="11" fill="#4a5568" font-family="Segoe UI, Arial">0</text>
<line x1="70" y1="50" x2="70" y2="350" stroke="#2d3748"/>
<line x1="70" y1="350" x2="790" y2="350" stroke="#2d3748"/>
<rect x="103.6" y="292.1" width="172.8" height="57.9" fill="#2c5282"/><rect x="343.6" y="225.5" width="172.8" height="124.5" fill="#2c5282"/><rect x="583.6" y="89.1" width="172.8" height="260.9" fill="#2c5282"/>
<text x="190.0" y="284.1" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">49.1</text><text x="430.0" y="217.5" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">105.5</text><text x="670.0" y="81.1" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">221.0</text>
<text x="190.0" y="392" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">0.50 CPU</text><text x="430.0" y="392" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">1.00 CPU</text><text x="670.0" y="392" text-anchor="middle" font-size="13" font-family="Segoe UI, Arial">2.00 CPU</text>
<text x="410.0" y="412" text-anchor="middle" font-size="12" fill="#4a5568" font-family="Segoe UI, Arial">Total CPU for two replicas</text>
<text x="16" y="200.0" text-anchor="middle" font-size="12" fill="#4a5568" font-family="Segoe UI, Arial" transform="rotate(-90 16 200.0)">successful RPS</text>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB