forked from mtusi2026/mtusi2026lab2
ЛР2: PostgreSQL, сессии, Redis-кэш, трек 5.2
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"run": "load.py --duration 20 --concurrency 4 (repeat, with process sampling)",
|
||||
"successful_rps": 627.178,
|
||||
"latency_ms": {
|
||||
"p50": 5.98,
|
||||
"p95": 8.954,
|
||||
"p99": 11.843
|
||||
},
|
||||
"error_ratio": 0.0,
|
||||
"api_process_cpu_cores_avg": 0.99,
|
||||
"api_process_rss_peak_mib": 80.1,
|
||||
"host": "2 CPU, 8027 MiB RAM, no cgroup limits on native stand"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.031,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 17950,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 597.716,
|
||||
"successful_latency_ms": {
|
||||
"p50": 6.282,
|
||||
"p95": 9.446,
|
||||
"p99": 12.031
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# 2026-10-26T17:32:39Z native stand; Linux 6.18.44-fc-v153 x86_64; nproc=2; mem=8027MiB
|
||||
$ python3 tests/load.py --duration 30 --concurrency 4 --output evidence/load.json
|
||||
{
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 30.0,
|
||||
"elapsed_seconds": 30.031,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 17950,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 597.716,
|
||||
"successful_latency_ms": {
|
||||
"p50": 6.282,
|
||||
"p95": 9.446,
|
||||
"p99": 12.031
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
exit=0
|
||||
@@ -0,0 +1,5 @@
|
||||
# 2026-10-26T17:31:55Z native stand; Linux 6.18.44-fc-v153 x86_64; nproc=2; mem=8027MiB
|
||||
$ make check
|
||||
python3 scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
exit=0
|
||||
@@ -0,0 +1,47 @@
|
||||
# 2026-10-26T17:31:49Z native stand: empty database -> API start applies migrations; second run is a no-op
|
||||
$ grep migrations /srv/stand/api.log
|
||||
api.log:{"ts": "2026-10-26T17:31:46Z", "level": "info", "logger": "messenger.db", "msg": "migration applied", "version": "0002_cache_invalidation_outbox"}
|
||||
api.log:{"ts": "2026-10-26T17:31:46Z", "level": "info", "logger": "messenger.http", "msg": "migrations checked", "applied": ["0001_init", "0002_cache_invalidation_outbox"]}
|
||||
api-ttl.log:{"ts": "2026-10-26T17:24:57Z", "level": "info", "logger": "messenger.http", "msg": "migrations checked", "applied": []}
|
||||
api-ttl.log:{"ts": "2026-10-26T17:31:46Z", "level": "info", "logger": "messenger.http", "msg": "migrations checked", "applied": []}
|
||||
|
||||
$ python -m messenger migrate # repeat
|
||||
{"applied": []}
|
||||
|
||||
$ psql -c "\dt" ; select * from schema_migrations
|
||||
List of relations
|
||||
Schema | Name | Type | Owner
|
||||
--------+-----------------------------+-------+-----------
|
||||
public | chat_members | table | messenger
|
||||
public | chats | table | messenger
|
||||
public | messages | table | messenger
|
||||
public | schema_migrations | table | messenger
|
||||
public | session_cache_invalidations | table | messenger
|
||||
public | sessions | table | messenger
|
||||
public | users | table | messenger
|
||||
(7 rows)
|
||||
|
||||
version | checksum | applied_at
|
||||
--------------------------------+--------------+-------------------------------
|
||||
0001_init | 64c1576d88cc | 2026-10-26 20:31:46.828818+03
|
||||
0002_cache_invalidation_outbox | fcebf1c9345a | 2026-10-26 20:31:46.834237+03
|
||||
(2 rows)
|
||||
|
||||
List of relations
|
||||
Schema | Name | Type | Owner | Table
|
||||
--------+----------------------------------+-------+-----------+-----------------------------
|
||||
public | chat_members_pkey | index | messenger | chat_members
|
||||
public | chat_members_position_key | index | messenger | chat_members
|
||||
public | chat_members_user_idx | index | messenger | chat_members
|
||||
public | chats_pkey | index | messenger | chats
|
||||
public | messages_chat_created_id_idx | index | messenger | messages
|
||||
public | messages_pkey | index | messenger | messages
|
||||
public | schema_migrations_pkey | index | messenger | schema_migrations
|
||||
public | session_cache_invalidations_pkey | index | messenger | session_cache_invalidations
|
||||
public | sessions_expires_idx | index | messenger | sessions
|
||||
public | sessions_pkey | index | messenger | sessions
|
||||
public | sessions_user_idx | index | messenger | sessions
|
||||
public | users_pkey | index | messenger | users
|
||||
public | users_username_key | index | messenger | users
|
||||
(13 rows)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# 2026-10-26T17:38:02Z native stand; Linux 6.18.44-fc-v153 x86_64; nproc=2
|
||||
$ make test-persistence ACTION_SCRIPT=scripts/dev/restart-native.sh
|
||||
python3 tests/resilience.py --mode persistence --action-script "scripts/dev/restart-native.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
exit=0
|
||||
@@ -0,0 +1 @@
|
||||
19
|
||||
@@ -0,0 +1,14 @@
|
||||
2026-10-26T17:38:04Z before: api=2679 postgres=2735 redis=3086
|
||||
2026-10-26T17:38:07Z after: api=3157 postgres=3141 redis=3151
|
||||
== 2026-10-26T18:10:08Z before restart
|
||||
api status=running started=2026-10-26T18:08:46.692820352Z pid=29494
|
||||
postgres status=running started=2026-10-26T18:05:34.636862226Z pid=25034
|
||||
redis status=running started=2026-10-26T18:05:34.636155192Z pid=25035
|
||||
volume kept: hh_pgdata
|
||||
volume kept: mtusi-lab2_pgdata
|
||||
== 2026-10-26T18:10:15Z after restart
|
||||
api status=running started=2026-10-26T18:10:14.919014494Z pid=31955
|
||||
postgres status=running started=2026-10-26T18:10:12.189358354Z pid=31771
|
||||
redis status=running started=2026-10-26T18:10:12.117424093Z pid=31761
|
||||
volume kept: hh_pgdata
|
||||
volume kept: mtusi-lab2_pgdata
|
||||
@@ -0,0 +1,5 @@
|
||||
# 2026-10-26T17:31:55Z native stand; Linux 6.18.44-fc-v153 x86_64; nproc=2; mem=8027MiB
|
||||
$ make test
|
||||
python3 tests/smoke.py --base-url "http://localhost:8080"
|
||||
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
|
||||
exit=0
|
||||
@@ -0,0 +1,14 @@
|
||||
# 2026-10-26T17:33:58Z native stand (Docker Hub недоступен из среды сборки, см. REPORT.md)
|
||||
host: Linux 6.18.44-fc-v153 x86_64; Intel(R) Xeon(R) Processor @ 2.80GHz; nproc=2; RAM=8027 MiB
|
||||
python: Python 3.13.17
|
||||
starlette 1.7.0 | uvicorn 0.54.0 | anyio 4.15.1
|
||||
psycopg 3.2.10 (pure-python impl, system libpq 16.15), psycopg_pool 3.2.6, redis-py 5.2.1 — из git-тегов upstream
|
||||
postgresql server: 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)
|
||||
redis server: v=7.0.15
|
||||
|
||||
processes:
|
||||
1551 05:25 29992 /usr/lib/postgresql/16/bin/postgres -D /srv/stand/pg-restore -p 5433 -k /run/postgresql
|
||||
2499 02:12 81488 /home/claude/venv/bin/python -m messenger serve
|
||||
2679 01:40 81992 /home/claude/venv/bin/python -m messenger serve
|
||||
2716 01:37 7652 redis-server *:6379
|
||||
2735 01:22 30248 /usr/lib/postgresql/16/bin/postgres -D /srv/stand/pg -p 5432 -k /run/postgresql
|
||||
@@ -0,0 +1,23 @@
|
||||
# 2026-10-26T17:31:57Z native stand; Linux 6.18.44-fc-v153 x86_64; nproc=2; mem=8027MiB
|
||||
$ python3 student-tests/test_api.py
|
||||
## API, auth, validation, ACL, transactions (http://localhost:8080)
|
||||
PASS password stored only as scrypt KDF hash; User has no secret fields 0.36s
|
||||
PASS wrong password and unknown user: identical 401 + Basic challenge 0.80s
|
||||
PASS malformed Basic / Bearer on /auth/sessions / body on login 0.01s
|
||||
PASS password with ':' and non-ASCII UTF-8 works (RFC 7617) 0.57s
|
||||
PASS opaque 256-bit token, unique per login, DB stores only SHA-256 0.66s
|
||||
PASS only Bearer accepted; Basic and X-User-Id never authenticate 0.01s
|
||||
PASS logout revokes only the current session; repeat -> 401 0.92s
|
||||
PASS strict JSON validation -> 400 0.02s
|
||||
PASS message text: 4000 code points OK, 4001 / whitespace / sender_id -> 400 0.02s
|
||||
PASS SQL is parameterized: injection payloads stored verbatim 0.01s
|
||||
PASS ACL: outsider gets 404 everywhere (even for invalid body) 0.02s
|
||||
PASS create chat validation: duplicates, caller missing, unknown member 0.00s
|
||||
PASS compound create-chat rolls back on FK failure (no orphan chat) 0.14s chats before=2, failed insert left 0 rows
|
||||
PASS registration race: 20 parallel same username -> exactly one 201 2.91s 201x1, 409x19, rows=1
|
||||
PASS keyset pagination: 120 msgs, varying limit, no gaps/duplicates 0.54s 4 pages
|
||||
PASS chat list: only own chats, ordered, cursor bound to user 0.64s
|
||||
PASS read-after-write: confirmed message visible to next read 0.01s
|
||||
PASS unknown route 404 / wrong method 405 in error format 0.01s
|
||||
summary: 18 passed, 0 failed
|
||||
exit=0
|
||||
@@ -0,0 +1,13 @@
|
||||
# 2026-10-26T17:35:09Z native stand, Redis v=7.0.15
|
||||
$ CACHE_URL_FILE=... python student-tests/test_cache_race.py
|
||||
PASS read-through put makes entry readable
|
||||
PASS entry TTL capped by SESSION_CACHE_TTL_SECONDS pttl=60000ms
|
||||
PASS invalidate removes entry
|
||||
PASS late put after logout is refused by tombstone
|
||||
PASS tombstone outlives any cache entry pttl=75000ms
|
||||
PASS entry never outlives session expiry pttl=1198ms
|
||||
PASS expired session not served from cache
|
||||
cache unavailable; falling back to PostgreSQL
|
||||
PASS degraded mode: cache is not read until outbox drained
|
||||
summary: all passed
|
||||
exit=0
|
||||
@@ -0,0 +1,8 @@
|
||||
# 2026-10-26T17:32:07Z native stand; Linux 6.18.44-fc-v153 x86_64; nproc=2; mem=8027MiB
|
||||
$ python3 student-tests/test_expiry.py
|
||||
## session expiry, SESSION_TTL_SECONDS=2 (http://localhost:8081)
|
||||
PASS expires_at = now + SESSION_TTL_SECONDS 0.54s remaining 2.00s
|
||||
PASS token valid before expiry, 401 Bearer after (cache warmed) 3.59s
|
||||
PASS re-login after expiry issues a new valid session 3.79s
|
||||
summary: 3 passed, 0 failed
|
||||
exit=0
|
||||
@@ -0,0 +1,7 @@
|
||||
# 2026-10-26T17:32:19Z native stand; Linux 6.18.44-fc-v153 x86_64; nproc=2; mem=8027MiB
|
||||
$ python3 student-tests/test_failures.py
|
||||
## dependency failures (http://localhost:8080)
|
||||
PASS Redis down: API bypasses cache via PostgreSQL, no anonymous trust 4.75s fallback latency 0.005s; outbox rows during outage=1, drained after recovery
|
||||
PASS PostgreSQL down: bounded 503 in error format; anonymous still 401 14.31s latency(s)={'ready': 1.5, 'post_message': 2.0, 'history': 2.0, 'login': 2.0, 'register': 2.0}; ready again in 2.5s
|
||||
summary: 2 passed, 0 failed
|
||||
exit=0
|
||||
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"measured_at": "2026-10-26T17:30:45+00:00",
|
||||
"dump": {
|
||||
"format": "custom (-Fc -Z 6)",
|
||||
"seconds": 0.783,
|
||||
"bytes": 7220447
|
||||
},
|
||||
"restore": {
|
||||
"parallel_jobs": 4,
|
||||
"seconds": 0.969
|
||||
},
|
||||
"verify_seconds": 2.372,
|
||||
"rto_dump_plus_restore_plus_verify_seconds": 4.124,
|
||||
"table_checks": {
|
||||
"users": {
|
||||
"source": "2000",
|
||||
"restored": "2000",
|
||||
"match": true
|
||||
},
|
||||
"chats": {
|
||||
"source": "300",
|
||||
"restored": "300",
|
||||
"match": true
|
||||
},
|
||||
"chat_members": {
|
||||
"source": "7720",
|
||||
"restored": "7720",
|
||||
"match": true
|
||||
},
|
||||
"messages_static": {
|
||||
"source": "120000",
|
||||
"restored": "120000",
|
||||
"match": true
|
||||
},
|
||||
"schema_migrations": {
|
||||
"source": "2",
|
||||
"restored": "2",
|
||||
"match": true
|
||||
},
|
||||
"indexes": {
|
||||
"source": "13",
|
||||
"restored": "13",
|
||||
"match": true
|
||||
},
|
||||
"constraints": {
|
||||
"source": "23",
|
||||
"restored": "23",
|
||||
"match": true
|
||||
}
|
||||
},
|
||||
"sample_messages": {
|
||||
"count": 200,
|
||||
"identical": true
|
||||
},
|
||||
"history_page_hot_chat_offset_1000_identical": true,
|
||||
"concurrent_writes": {
|
||||
"acked_before_dump_started": 76,
|
||||
"acked_when_dump_finished": 137,
|
||||
"acked_total": 221,
|
||||
"present_in_source": 221,
|
||||
"present_in_restored": 80,
|
||||
"restored_is_contiguous_prefix": true,
|
||||
"lost_relative_to_source": 141
|
||||
},
|
||||
"all_match": true
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"generated_at": "2026-10-26T17:30:01+00:00",
|
||||
"params": {
|
||||
"seed": 0.42,
|
||||
"users": 2000,
|
||||
"chats": 300,
|
||||
"messages": 120000,
|
||||
"zipf_s": 1.1
|
||||
},
|
||||
"generation_seconds": 14.58,
|
||||
"messages_total": 120000,
|
||||
"chats_with_messages": 300,
|
||||
"chat_size_top5": [
|
||||
24294,
|
||||
11289,
|
||||
7264,
|
||||
5382,
|
||||
4266
|
||||
],
|
||||
"chat_size_p50": 98,
|
||||
"chat_size_min": 38,
|
||||
"top1_share": 0.2024,
|
||||
"top10_share": 0.5441,
|
||||
"messages_table_mb": 28.3,
|
||||
"server_version": "16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)",
|
||||
"shared_buffers": "128MB"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
-- btree(chat_id); hot chat, 24294 messages; keyset cursor at 50%
|
||||
Limit (cost=4708.68..4708.80 rows=51 width=213) (actual time=14.248..14.259 rows=51 loops=1)
|
||||
Buffers: shared hit=3642
|
||||
-> Sort (cost=4708.68..4738.72 rows=12019 width=213) (actual time=14.247..14.254 rows=51 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 42kB
|
||||
Buffers: shared hit=3642
|
||||
-> Bitmap Heap Scan on messages (cost=271.12..4307.70 rows=12019 width=213) (actual time=6.934..12.540 rows=12147 loops=1)
|
||||
Recheck Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
|
||||
Filter: (ROW(created_at, id) > ROW('2026-02-04 13:58:00+03'::timestamp with time zone, 'dc3c4cd9-029a-40dd-976c-64cd71098149'::uuid))
|
||||
Rows Removed by Filter: 12147
|
||||
Heap Blocks: exact=3614
|
||||
Buffers: shared hit=3636
|
||||
-> Bitmap Index Scan on hist_idx (cost=0.00..268.11 rows=23976 width=0) (actual time=1.156..1.156 rows=24294 loops=1)
|
||||
Index Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
|
||||
Buffers: shared hit=22
|
||||
Planning:
|
||||
Buffers: shared hit=132
|
||||
Planning Time: 0.426 ms
|
||||
Execution Time: 14.305 ms
|
||||
|
||||
-- same chat, OFFSET 12147
|
||||
Limit (cost=5968.35..5968.48 rows=51 width=213) (actual time=24.772..24.782 rows=51 loops=1)
|
||||
Buffers: shared hit=3642, temp read=535 written=676
|
||||
-> Sort (cost=5937.98..5997.92 rows=23976 width=213) (actual time=22.894..24.401 rows=12198 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: external merge Disk: 5392kB
|
||||
Buffers: shared hit=3642, temp read=535 written=676
|
||||
-> Bitmap Heap Scan on messages (cost=274.11..4190.81 rows=23976 width=213) (actual time=1.657..11.046 rows=24294 loops=1)
|
||||
Recheck Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
|
||||
Heap Blocks: exact=3614
|
||||
Buffers: shared hit=3636
|
||||
-> Bitmap Index Scan on hist_idx (cost=0.00..268.11 rows=23976 width=0) (actual time=1.179..1.179 rows=24294 loops=1)
|
||||
Index Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
|
||||
Buffers: shared hit=22
|
||||
Planning:
|
||||
Buffers: shared hit=133
|
||||
Planning Time: 0.460 ms
|
||||
Execution Time: 25.426 ms
|
||||
@@ -0,0 +1,29 @@
|
||||
-- btree(chat_id, created_at, id) — выбран в миграции 0001; hot chat, 24294 messages; keyset cursor at 50%
|
||||
Limit (cost=0.42..62.81 rows=51 width=213) (actual time=0.032..0.053 rows=51 loops=1)
|
||||
Buffers: shared hit=12
|
||||
-> Index Scan using hist_idx on messages (cost=0.42..15039.53 rows=12293 width=213) (actual time=0.031..0.049 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid) AND (ROW(created_at, id) > ROW('2026-02-04 13:58:00+03'::timestamp with time zone, 'dc3c4cd9-029a-40dd-976c-64cd71098149'::uuid)))
|
||||
Buffers: shared hit=12
|
||||
Planning:
|
||||
Buffers: shared hit=143
|
||||
Planning Time: 0.506 ms
|
||||
Execution Time: 0.083 ms
|
||||
|
||||
-- same chat, OFFSET 12147
|
||||
Limit (cost=6633.54..6633.67 rows=51 width=213) (actual time=32.900..32.912 rows=51 loops=1)
|
||||
Buffers: shared hit=3796, temp read=535 written=676
|
||||
-> Sort (cost=6603.18..6664.33 rows=24460 width=213) (actual time=29.824..32.370 rows=12198 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: external merge Disk: 5392kB
|
||||
Buffers: shared hit=3796, temp read=535 written=676
|
||||
-> Bitmap Heap Scan on messages (cost=897.98..4820.73 rows=24460 width=213) (actual time=2.958..14.794 rows=24294 loops=1)
|
||||
Recheck Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
|
||||
Heap Blocks: exact=3614
|
||||
Buffers: shared hit=3790
|
||||
-> Bitmap Index Scan on hist_idx (cost=0.00..891.87 rows=24460 width=0) (actual time=2.442..2.442 rows=24294 loops=1)
|
||||
Index Cond: (chat_id = '0ab807ce-24eb-4da8-8458-ef0836fb3470'::uuid)
|
||||
Buffers: shared hit=176
|
||||
Planning:
|
||||
Buffers: shared hit=144
|
||||
Planning Time: 0.500 ms
|
||||
Execution Time: 33.741 ms
|
||||
@@ -0,0 +1,563 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"label": "hot",
|
||||
"chat_id": "0ab807ce-24eb-4da8-8458-ef0836fb3470",
|
||||
"messages": 24294,
|
||||
"offset": 12147,
|
||||
"cursor_ts": "2026-02-04 13:58:00+03",
|
||||
"cursor_id": "dc3c4cd9-029a-40dd-976c-64cd71098149"
|
||||
},
|
||||
{
|
||||
"label": "median",
|
||||
"chat_id": "5455628c-0b94-4d4a-95bf-74145b899408",
|
||||
"messages": 99,
|
||||
"offset": 49,
|
||||
"cursor_ts": "2026-02-04 03:36:40+03",
|
||||
"cursor_id": "01b51bb5-cfb2-4fce-a665-02087836dd8c"
|
||||
},
|
||||
{
|
||||
"label": "small",
|
||||
"chat_id": "74d7b4ab-e4ce-4065-b97b-1b00a2383364",
|
||||
"messages": 38,
|
||||
"offset": 19,
|
||||
"cursor_ts": "2026-02-04 08:40:15+03",
|
||||
"cursor_id": "b94bd4dd-e28c-4bce-8065-8a07a85a72bd"
|
||||
}
|
||||
],
|
||||
"repeats": 15,
|
||||
"variants": {
|
||||
"V0_no_index": {
|
||||
"note": "только PK(id): нет индекса по chat_id",
|
||||
"index_bytes": 0,
|
||||
"queries": {
|
||||
"hot/keyset_first": {
|
||||
"exec_ms_median": 18.126,
|
||||
"exec_ms_p90": 19.806,
|
||||
"shared_hit": 3705,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Gather Merge",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"hot/keyset_middle": {
|
||||
"exec_ms_median": 18.343,
|
||||
"exec_ms_p90": 22.394,
|
||||
"shared_hit": 3647,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Gather Merge",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"hot/offset_middle": {
|
||||
"exec_ms_median": 28.459,
|
||||
"exec_ms_p90": 33.177,
|
||||
"shared_hit": 3617,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"median/keyset_first": {
|
||||
"exec_ms_median": 14.429,
|
||||
"exec_ms_p90": 15.984,
|
||||
"shared_hit": 3617,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"median/keyset_middle": {
|
||||
"exec_ms_median": 15.644,
|
||||
"exec_ms_p90": 16.287,
|
||||
"shared_hit": 3647,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Gather Merge",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"median/offset_middle": {
|
||||
"exec_ms_median": 14.285,
|
||||
"exec_ms_p90": 15.051,
|
||||
"shared_hit": 3617,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"small/keyset_first": {
|
||||
"exec_ms_median": 13.895,
|
||||
"exec_ms_p90": 17.684,
|
||||
"shared_hit": 3617,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"small/keyset_middle": {
|
||||
"exec_ms_median": 17.617,
|
||||
"exec_ms_p90": 19.349,
|
||||
"shared_hit": 3647,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Gather Merge",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
},
|
||||
"small/offset_middle": {
|
||||
"exec_ms_median": 14.198,
|
||||
"exec_ms_p90": 16.743,
|
||||
"shared_hit": 3617,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Seq Scan"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"V1_chat": {
|
||||
"note": "btree(chat_id)",
|
||||
"index_bytes": 876544,
|
||||
"queries": {
|
||||
"hot/keyset_first": {
|
||||
"exec_ms_median": 12.668,
|
||||
"exec_ms_p90": 15.04,
|
||||
"shared_hit": 3636,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/keyset_middle": {
|
||||
"exec_ms_median": 12.078,
|
||||
"exec_ms_p90": 13.361,
|
||||
"shared_hit": 3636,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/offset_middle": {
|
||||
"exec_ms_median": 20.116,
|
||||
"exec_ms_p90": 26.066,
|
||||
"shared_hit": 3636,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_first": {
|
||||
"exec_ms_median": 0.163,
|
||||
"exec_ms_p90": 0.192,
|
||||
"shared_hit": 99,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_middle": {
|
||||
"exec_ms_median": 0.081,
|
||||
"exec_ms_p90": 0.109,
|
||||
"shared_hit": 99,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/offset_middle": {
|
||||
"exec_ms_median": 0.075,
|
||||
"exec_ms_p90": 0.105,
|
||||
"shared_hit": 99,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_first": {
|
||||
"exec_ms_median": 0.056,
|
||||
"exec_ms_p90": 0.061,
|
||||
"shared_hit": 40,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_middle": {
|
||||
"exec_ms_median": 0.038,
|
||||
"exec_ms_p90": 0.041,
|
||||
"shared_hit": 40,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/offset_middle": {
|
||||
"exec_ms_median": 0.038,
|
||||
"exec_ms_p90": 0.041,
|
||||
"shared_hit": 40,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"V2_chat_created": {
|
||||
"note": "btree(chat_id, created_at)",
|
||||
"index_bytes": 4898816,
|
||||
"queries": {
|
||||
"hot/keyset_first": {
|
||||
"exec_ms_median": 0.036,
|
||||
"exec_ms_p90": 0.061,
|
||||
"shared_hit": 10,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Incremental Sort",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/keyset_middle": {
|
||||
"exec_ms_median": 0.038,
|
||||
"exec_ms_p90": 0.049,
|
||||
"shared_hit": 11,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Incremental Sort",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/offset_middle": {
|
||||
"exec_ms_median": 21.445,
|
||||
"exec_ms_p90": 25.194,
|
||||
"shared_hit": 3737,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_first": {
|
||||
"exec_ms_median": 0.048,
|
||||
"exec_ms_p90": 0.052,
|
||||
"shared_hit": 54,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Incremental Sort",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_middle": {
|
||||
"exec_ms_median": 0.07,
|
||||
"exec_ms_p90": 0.102,
|
||||
"shared_hit": 53,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/offset_middle": {
|
||||
"exec_ms_median": 0.135,
|
||||
"exec_ms_p90": 0.16,
|
||||
"shared_hit": 100,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_first": {
|
||||
"exec_ms_median": 0.054,
|
||||
"exec_ms_p90": 0.082,
|
||||
"shared_hit": 41,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Incremental Sort",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_middle": {
|
||||
"exec_ms_median": 0.048,
|
||||
"exec_ms_p90": 0.056,
|
||||
"shared_hit": 23,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/offset_middle": {
|
||||
"exec_ms_median": 0.05,
|
||||
"exec_ms_p90": 0.059,
|
||||
"shared_hit": 41,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Incremental Sort",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"V3_chat_created_id": {
|
||||
"note": "btree(chat_id, created_at, id) — выбран в миграции 0001",
|
||||
"index_bytes": 7094272,
|
||||
"queries": {
|
||||
"hot/keyset_first": {
|
||||
"exec_ms_median": 0.023,
|
||||
"exec_ms_p90": 0.034,
|
||||
"shared_hit": 10,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/keyset_middle": {
|
||||
"exec_ms_median": 0.033,
|
||||
"exec_ms_p90": 0.038,
|
||||
"shared_hit": 12,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/offset_middle": {
|
||||
"exec_ms_median": 25.014,
|
||||
"exec_ms_p90": 28.762,
|
||||
"shared_hit": 3790,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_first": {
|
||||
"exec_ms_median": 0.028,
|
||||
"exec_ms_p90": 0.036,
|
||||
"shared_hit": 53,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_middle": {
|
||||
"exec_ms_median": 0.05,
|
||||
"exec_ms_p90": 0.077,
|
||||
"shared_hit": 52,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/offset_middle": {
|
||||
"exec_ms_median": 0.128,
|
||||
"exec_ms_p90": 0.133,
|
||||
"shared_hit": 100,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_first": {
|
||||
"exec_ms_median": 0.026,
|
||||
"exec_ms_p90": 0.03,
|
||||
"shared_hit": 42,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_middle": {
|
||||
"exec_ms_median": 0.028,
|
||||
"exec_ms_p90": 0.029,
|
||||
"shared_hit": 22,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Sort",
|
||||
"Bitmap Heap Scan",
|
||||
"Bitmap Index Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/offset_middle": {
|
||||
"exec_ms_median": 0.023,
|
||||
"exec_ms_p90": 0.038,
|
||||
"shared_hit": 42,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Scan using hist_idx"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"V4_covering": {
|
||||
"note": "covering: + INCLUDE(sender_id, text)",
|
||||
"index_bytes": 31449088,
|
||||
"queries": {
|
||||
"hot/keyset_first": {
|
||||
"exec_ms_median": 0.031,
|
||||
"exec_ms_p90": 0.033,
|
||||
"shared_hit": 5,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/keyset_middle": {
|
||||
"exec_ms_median": 0.035,
|
||||
"exec_ms_p90": 0.036,
|
||||
"shared_hit": 6,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"hot/offset_middle": {
|
||||
"exec_ms_median": 2.14,
|
||||
"exec_ms_p90": 2.4,
|
||||
"shared_hit": 390,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_first": {
|
||||
"exec_ms_median": 0.032,
|
||||
"exec_ms_p90": 0.052,
|
||||
"shared_hit": 6,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/keyset_middle": {
|
||||
"exec_ms_median": 0.034,
|
||||
"exec_ms_p90": 0.035,
|
||||
"shared_hit": 5,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"median/offset_middle": {
|
||||
"exec_ms_median": 0.042,
|
||||
"exec_ms_p90": 0.044,
|
||||
"shared_hit": 7,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_first": {
|
||||
"exec_ms_median": 0.027,
|
||||
"exec_ms_p90": 0.029,
|
||||
"shared_hit": 5,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/keyset_middle": {
|
||||
"exec_ms_median": 0.022,
|
||||
"exec_ms_p90": 0.022,
|
||||
"shared_hit": 4,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
},
|
||||
"small/offset_middle": {
|
||||
"exec_ms_median": 0.025,
|
||||
"exec_ms_p90": 0.025,
|
||||
"shared_hit": 5,
|
||||
"shared_read": 0,
|
||||
"plan": [
|
||||
"Limit",
|
||||
"Index Only Scan using hist_idx"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"rows_per_run": 50000,
|
||||
"runs": 5,
|
||||
"note": "один INSERT на строку внутри одной транзакции (без fsync на COMMIT); FK исключён, чтобы изолировать стоимость поддержки индекса истории",
|
||||
"variants": {
|
||||
"V0_no_index": {
|
||||
"note": "только PK(id): нет индекса по chat_id",
|
||||
"ms_median": 640.3,
|
||||
"us_per_insert": 12.81,
|
||||
"wal_bytes_per_insert": 360.4,
|
||||
"index_bytes_after_run": 0,
|
||||
"runs_ms": [
|
||||
533.5,
|
||||
646.4,
|
||||
640.3,
|
||||
641.4,
|
||||
612.8
|
||||
],
|
||||
"overhead_vs_no_index_pct": 0.0
|
||||
},
|
||||
"V1_chat": {
|
||||
"note": "btree(chat_id)",
|
||||
"ms_median": 778.0,
|
||||
"us_per_insert": 15.56,
|
||||
"wal_bytes_per_insert": 438.4,
|
||||
"index_bytes_after_run": 458752,
|
||||
"runs_ms": [
|
||||
778.0,
|
||||
995.6,
|
||||
826.4,
|
||||
660.6,
|
||||
758.6
|
||||
],
|
||||
"overhead_vs_no_index_pct": 21.5
|
||||
},
|
||||
"V2_chat_created": {
|
||||
"note": "btree(chat_id, created_at)",
|
||||
"ms_median": 772.0,
|
||||
"us_per_insert": 15.44,
|
||||
"wal_bytes_per_insert": 471.0,
|
||||
"index_bytes_after_run": 3284992,
|
||||
"runs_ms": [
|
||||
805.3,
|
||||
772.0,
|
||||
756.2,
|
||||
757.3,
|
||||
817.3
|
||||
],
|
||||
"overhead_vs_no_index_pct": 20.5
|
||||
},
|
||||
"V3_chat_created_id": {
|
||||
"note": "btree(chat_id, created_at, id) — выбран в миграции 0001",
|
||||
"ms_median": 744.0,
|
||||
"us_per_insert": 14.88,
|
||||
"wal_bytes_per_insert": 501.8,
|
||||
"index_bytes_after_run": 4743168,
|
||||
"runs_ms": [
|
||||
763.3,
|
||||
676.1,
|
||||
744.0,
|
||||
749.5,
|
||||
707.4
|
||||
],
|
||||
"overhead_vs_no_index_pct": 16.2
|
||||
},
|
||||
"V4_covering": {
|
||||
"note": "covering: + INCLUDE(sender_id, text)",
|
||||
"ms_median": 928.8,
|
||||
"us_per_insert": 18.58,
|
||||
"wal_bytes_per_insert": 849.2,
|
||||
"index_bytes_after_run": 21970944,
|
||||
"runs_ms": [
|
||||
928.8,
|
||||
973.1,
|
||||
970.6,
|
||||
872.0,
|
||||
857.7
|
||||
],
|
||||
"overhead_vs_no_index_pct": 45.0
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user