This commit is contained in:
2026-10-16 19:49:48 +03:00
parent 65003b6119
commit c4ec287633
57 changed files with 4749 additions and 19 deletions
+9
View File
@@ -0,0 +1,9 @@
# Роль Redis/Valkey: read-through кэш сессий (источник истины — PostgreSQL)
число ключей sess:v1:*: 3
пример ключа (хеш токена, не токен): sess:v1:db24de3dbb236846...
PTTL, мс (≤ SESSION_CACHE_TTL_SECONDS*1000 = 60000): 44231
поля значения: ['exp', 'user'] / user: ['created_at', 'display_name', 'id', 'username']
есть ли password/hash/token в значении: False
после logout значение ключа (tombstone): revoked
после FLUSHALL ключей: 0
сессия работает после FLUSHALL (из PostgreSQL), кэш наполнился заново, ключей: 1
+11
View File
@@ -0,0 +1,11 @@
# Зависимости: Redis (кэш сессий) и PostgreSQL; команды управления — песочничные (в стенде — docker compose stop/start)
1) Valkey остановлен
$ CACHE_STOP
$ CACHE_START
2) Кэш сброшен (FLUSHALL): сессии берутся из PostgreSQL
$ CACHE_FLUSH
3) PostgreSQL остановлен
$ DB_STOP
$ DB_START
4) Восстановление
PASS: кэш и БД отказывают предсказуемо: кэш обходится, БД -> 503, анонимный доступ невозможен, данные и сессии целы
+85
View File
@@ -0,0 +1,85 @@
rows total=100000, rows in target chat=20000, page=50
PostgreSQL 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0, 64-bit
====================================================================================================
A. Первая страница, keyset, С индексом (chat_id, created_at, id)
====================================================================================================
Limit (cost=0.42..14.81 rows=51 width=69) (actual time=0.010..0.021 rows=51 loops=1)
Buffers: shared hit=4
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.42..5670.87 rows=20093 width=69) (actual time=0.009..0.016 rows=51 loops=1)
Index Cond: (chat_id = '010619e6-7ff5-46b1-877c-03368e85f10b'::uuid)
Buffers: shared hit=4
Planning:
Buffers: shared hit=6
Planning Time: 0.063 ms
Execution Time: 0.032 ms
====================================================================================================
B. Страница на глубине ~15 000, keyset, С индексом
====================================================================================================
Limit (cost=0.42..48.66 rows=51 width=69) (actual time=0.011..0.021 rows=51 loops=1)
Buffers: shared hit=4
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.42..4756.71 rows=5028 width=69) (actual time=0.011..0.016 rows=51 loops=1)
Index Cond: ((chat_id = '010619e6-7ff5-46b1-877c-03368e85f10b'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 20:50:05.000522+00'::timestamp with time zone, 'f47f8dd1-aaae-4701-a00d-6e20a06648e3'::uuid)))
Buffers: shared hit=4
Planning Time: 0.059 ms
Execution Time: 0.044 ms
====================================================================================================
C. Та же страница, keyset, БЕЗ индекса (индекс удалён в откатываемой транзакции)
====================================================================================================
Limit (cost=3152.74..3152.87 rows=51 width=69) (actual time=9.057..9.066 rows=51 loops=1)
Buffers: shared hit=1235
-> Sort (cost=3152.74..3165.31 rows=5028 width=69) (actual time=9.056..9.060 rows=51 loops=1)
Sort Key: created_at, id
Sort Method: top-N heapsort Memory: 31kB
Buffers: shared hit=1235
-> Seq Scan on messages (cost=0.00..2985.00 rows=5028 width=69) (actual time=1.098..8.625 rows=4999 loops=1)
Filter: ((chat_id = '010619e6-7ff5-46b1-877c-03368e85f10b'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 20:50:05.000522+00'::timestamp with time zone, 'f47f8dd1-aaae-4701-a00d-6e20a06648e3'::uuid)))
Rows Removed by Filter: 95001
Buffers: shared hit=1235
Planning:
Buffers: shared hit=4
Planning Time: 0.065 ms
Execution Time: 9.081 ms
====================================================================================================
D. Та же глубина через OFFSET 15000, С индексом (антипример)
====================================================================================================
Limit (cost=3958.59..3958.71 rows=51 width=69) (actual time=10.512..10.519 rows=51 loops=1)
Buffers: shared hit=1235
-> Sort (cost=3921.09..3971.32 rows=20093 width=69) (actual time=9.103..9.920 rows=15051 loops=1)
Sort Key: created_at, id
Sort Method: quicksort Memory: 3271kB
Buffers: shared hit=1235
-> Seq Scan on messages (cost=0.00..2485.00 rows=20093 width=69) (actual time=0.003..6.416 rows=20000 loops=1)
Filter: (chat_id = '010619e6-7ff5-46b1-877c-03368e85f10b'::uuid)
Rows Removed by Filter: 80000
Buffers: shared hit=1235
Planning:
Buffers: shared hit=22
Planning Time: 0.101 ms
Execution Time: 10.643 ms
====================================================================================================
E. Первая страница, БЕЗ индекса
====================================================================================================
Limit (cost=3155.35..3155.47 rows=51 width=69) (actual time=7.702..7.709 rows=51 loops=1)
Buffers: shared hit=1235
-> Sort (cost=3155.35..3205.58 rows=20093 width=69) (actual time=7.701..7.704 rows=51 loops=1)
Sort Key: created_at, id
Sort Method: top-N heapsort Memory: 31kB
Buffers: shared hit=1235
-> Seq Scan on messages (cost=0.00..2485.00 rows=20093 width=69) (actual time=0.004..6.070 rows=20000 loops=1)
Filter: (chat_id = '010619e6-7ff5-46b1-877c-03368e85f10b'::uuid)
Rows Removed by Filter: 80000
Buffers: shared hit=1235
Planning:
Buffers: shared hit=4
Planning Time: 0.060 ms
Execution Time: 7.721 ms
Индексы messages:
messages_chat_created_id_idx -> CREATE INDEX messages_chat_created_id_idx ON public.messages USING btree (chat_id, created_at, id)
messages_pkey -> CREATE UNIQUE INDEX messages_pkey ON public.messages USING btree (id)
Размер индекса: 8536 kB ; таблицы: 9880 kB
Binary file not shown.
+22
View File
@@ -0,0 +1,22 @@
# Миграции с нуля и повторный запуск (песочница, PostgreSQL 16)
$ python -m app.migrate (запуск 1)
2026-10-15 09:56:03,651 migrate applied: 0001_core, 0002_sessions
$ python -m app.migrate (запуск 2)
2026-10-15 09:56:03,862 migrate applied: nothing to do (schema is up to date)
version | checksum
---------------+--------------
0001_core | 5cc38bccb02e
0002_sessions | 6ef657d22fa7
(2 rows)
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 | sessions | table | messenger
public | users | table | messenger
(6 rows)
+15
View File
@@ -0,0 +1,15 @@
=== Persistence on Docker Compose (Windows 11 + Docker Desktop) ===
Дата: 2026-10-16 19:28
Шаги:
1. POST /api/v1/users (username=persist, password 12+) -> 201
2. POST /api/v1/auth/sessions (Basic) -> 201, получен Bearer-токен
3. GET /api/v1/users/me с Bearer -> 200 OK (username=persist)
4. docker compose stop api valkey postgres
5. docker compose up -d -> migrate пропустил миграции, api healthy
6. GET /api/v1/users/me тем же Bearer-токеном ПОСЛЕ рестарта -> 200 OK
Вывод: PostgreSQL сохранил данные в volume pgdata.
Valkey-кэш потерян (RAM), но при промахе сессия читается из PostgreSQL.
Пользователи, сообщения и действующие сессии переживают полный рестарт
всех хранилищ без удаления volumes.
+14
View File
@@ -0,0 +1,14 @@
# Сохранность при полном рестарте (песочничный hook: API (uvicorn, 2 процесса) + PostgreSQL + Redis, данные на диске сохраняются)
== before ==
postgres postmaster_start=2026-10-15 21:38:10.905693+00
redis uptime_s=73
api master_pid=197
rows users=127 messages=1242 sessions=52
== make test-persistence ==
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
== after ==
postgres postmaster_start=2026-10-15 21:39:16.659936+00
redis uptime_s=2
api master_pid=587
rows users=130 messages=1243 sessions=55
+47
View File
@@ -0,0 +1,47 @@
# Среда: песочница без Docker. PostgreSQL 16.15, Redis 7 (вместо Valkey), Python 3.12.3, FastAPI 0.115.0 + uvicorn 0.30.6 (2 процесса), 2026-10-15T21:39:00Z
# Compose-стенд в этой среде не запускался (нет Docker) — см. REPORT.md, «Ограничения проверки».
$ make check
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
$ make test
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
$ python3 tests_student/test_integration.py
PASS registration_race_same_username
PASS username_and_field_validation
PASS password_with_colon_and_unicode_login
PASS login_failures_look_identical
PASS bearer_rules
PASS logout_revokes_only_that_session
PASS chat_creation_rules_and_no_side_effects
PASS message_rules
PASS pagination_walk_and_cursor_binding
PASS chat_list_pagination_and_order
PASS request_id_and_error_shape
11/11 passed
$ pytest tests/test_own.py tests/test_race.py -v
test_own.py::test_invalid_json PASSED
test_own.py::test_duplicate_username PASSED
test_own.py::test_extra_fields PASSED
test_own.py::test_empty_message PASSED
test_own.py::test_foreign_chat PASSED
test_own.py::test_pagination PASSED
test_own.py::test_cursor_from_other_chat_is_400 PASSED
test_own.py::test_x_user_id_no_longer_grants_access PASSED
test_own.py::test_basic_only_on_login PASSED
test_own.py::test_wrong_password_and_unknown_user_look_the_same PASSED
test_own.py::test_logout_revokes_token PASSED
test_own.py::test_password_is_never_returned PASSED
test_own.py::test_short_password_rejected PASSED
test_race.py::test_concurrent_writes PASSED
test_race.py::test_concurrent_registration_same_username PASSED
============================== 15 passed in 1.28s ==============================
$ python tests_student/test_db_rollback.py
PASS: ошибка внутри транзакции откатила вставку chats (0 строк), контрольный commit сохранил чат и участника
$ SESSION_TTL_SECONDS=2 (API на :8081) python tests_student/test_expiry.py 2
PASS: сессия с TTL=2.0s перестала действовать (401 на users/me, chats, logout) после ожидания 3.5s
Binary file not shown.
Binary file not shown.
+502
View File
@@ -0,0 +1,502 @@
{
"environment": {
"postgres": "17.6",
"shared_buffers": "128MB",
"work_mem": "4MB",
"fsync": "on",
"synchronous_commit": "on",
"cpus": 8,
"python": "3.14.0",
"platform": "Windows-11-10.0.26200-SP0"
},
"dataset": {
"messages": 100000,
"chats": 563,
"chat_size_distribution": {
"50000": 1,
"20000": 1,
"10000": 1,
"1000": 10,
"100": 50,
"10": 500
},
"text_length_chars": "10..400 (ðàâíîìåðíî)",
"page_size": 50,
"read_runs": 300,
"warmup": 20,
"single_inserts": 2000,
"bulk_repeats": 3,
"order": "forward"
},
"configs": {
"C0_pk_only": {
"ddl": null,
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.279,
2.998,
2.954
],
"median": 2.998
},
"single_insert_ms": {
"n": 2000,
"mean": 2.04,
"p50": 1.77,
"p95": 2.782,
"p99": 9.041
},
"history_index_bytes": 0,
"table_bytes": 49356800,
"pk_index_bytes": 4399104
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 20.143,
"p95_ms": 21.423,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 16.284,
"shared_buffers": 6113,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 14.824,
"p95_ms": 18.251,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 14.493,
"shared_buffers": 6055,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 14.878,
"p95_ms": 16.222,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 13.788,
"shared_buffers": 6025,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 14.544,
"p95_ms": 19.133,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 16.134,
"shared_buffers": 6025,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 68.21,
"p95_ms": 73.534,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 52.653,
"shared_buffers": 6113,
"rows": 51
}
}
}
},
"C1_chat_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.061,
3.026,
3.2
],
"median": 3.061
},
"single_insert_ms": {
"n": 2000,
"mean": 1.881,
"p50": 1.787,
"p95": 2.476,
"p99": 3.015
},
"history_index_bytes": 909312,
"table_bytes": 49356800,
"pk_index_bytes": 4366336
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 14.884,
"p95_ms": 16.423,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 13.512,
"shared_buffers": 6113,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 14.3,
"p95_ms": 15.906,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 12.621,
"shared_buffers": 3133,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.957,
"p95_ms": 1.473,
"plan": {
"nodes": [
"Index Scan",
"Sort",
"Limit"
],
"execution_ms": 0.05,
"shared_buffers": 4,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 1.787,
"p95_ms": 2.624,
"plan": {
"nodes": [
"Index Scan",
"Sort",
"Limit"
],
"execution_ms": 0.382,
"shared_buffers": 91,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 62.441,
"p95_ms": 68.187,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 60.441,
"shared_buffers": 6113,
"rows": 51
}
}
}
},
"C2_chat_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.12,
3.112,
3.109
],
"median": 3.112
},
"single_insert_ms": {
"n": 2000,
"mean": 1.965,
"p50": 1.733,
"p95": 2.488,
"p99": 8.053
},
"history_index_bytes": 7184384,
"table_bytes": 49356800,
"pk_index_bytes": 4374528
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 1.219,
"p95_ms": 1.86,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.066,
"shared_buffers": 7,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 1.196,
"p95_ms": 1.721,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.059,
"shared_buffers": 12,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.932,
"p95_ms": 1.533,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.041,
"shared_buffers": 5,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 1.25,
"p95_ms": 1.847,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.066,
"shared_buffers": 10,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 9.21,
"p95_ms": 10.112,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 10.02,
"shared_buffers": 3955,
"rows": 51
}
}
}
},
"C3_covering_include": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id) INCLUDE (sender_id, text)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.791,
3.695,
3.919
],
"median": 3.791
},
"single_insert_ms": {
"n": 2000,
"mean": 1.84,
"p50": 1.741,
"p95": 2.373,
"p99": 2.899
},
"history_index_bytes": 37306368,
"table_bytes": 49356800,
"pk_index_bytes": 4349952
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 1.184,
"p95_ms": 1.863,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.062,
"shared_buffers": 6,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 1.221,
"p95_ms": 1.916,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.085,
"shared_buffers": 6,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 1.05,
"p95_ms": 1.488,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.043,
"shared_buffers": 4,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 1.3,
"p95_ms": 2.022,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.073,
"shared_buffers": 8,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 8.186,
"p95_ms": 10.23,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 9.554,
"shared_buffers": 1474,
"rows": 51
}
}
}
},
"C4_global_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.189,
3.259,
3.973
],
"median": 3.259
},
"single_insert_ms": {
"n": 2000,
"mean": 2.09,
"p50": 1.904,
"p95": 2.826,
"p99": 3.545
},
"history_index_bytes": 5193728,
"table_bytes": 49356800,
"pk_index_bytes": 4341760
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 3.453,
"p95_ms": 4.159,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 2.093,
"shared_buffers": 5500,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 1.492,
"p95_ms": 2.025,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.081,
"shared_buffers": 11,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 32.912,
"p95_ms": 35.359,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 12.81,
"shared_buffers": 6025,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 1.491,
"p95_ms": 2.278,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.286,
"shared_buffers": 669,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 67.904,
"p95_ms": 74.677,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 57.802,
"shared_buffers": 6113,
"rows": 51
}
}
}
}
}
}
+508
View File
@@ -0,0 +1,508 @@
{
"environment": {
"postgres": "17.6",
"shared_buffers": "128MB",
"work_mem": "4MB",
"fsync": "on",
"synchronous_commit": "on",
"cpus": 8,
"python": "3.14.0",
"platform": "Windows-11-10.0.26200-SP0"
},
"dataset": {
"messages": 100000,
"chats": 563,
"chat_size_distribution": {
"50000": 1,
"20000": 1,
"10000": 1,
"1000": 10,
"100": 50,
"10": 500
},
"text_length_chars": "10..400 (ðàâíîìåðíî)",
"page_size": 50,
"read_runs": 300,
"warmup": 20,
"single_inserts": 2000,
"bulk_repeats": 3,
"order": "reverse"
},
"configs": {
"C4_global_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.384,
3.279,
3.452
],
"median": 3.384
},
"single_insert_ms": {
"n": 2000,
"mean": 1.787,
"p50": 1.714,
"p95": 2.309,
"p99": 2.722
},
"history_index_bytes": 5201920,
"table_bytes": 49471488,
"pk_index_bytes": 4358144
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 3.433,
"p95_ms": 4.326,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 2.116,
"shared_buffers": 5503,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 1.418,
"p95_ms": 2.031,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.11,
"shared_buffers": 8,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 15.92,
"p95_ms": 33.715,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 12.834,
"shared_buffers": 6039,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 1.455,
"p95_ms": 2.026,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.302,
"shared_buffers": 669,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 72.363,
"p95_ms": 134.385,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 71.893,
"shared_buffers": 6127,
"rows": 51
}
}
}
},
"C3_covering_include": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id) INCLUDE (sender_id, text)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
5.342,
4.847,
5.174
],
"median": 5.174
},
"single_insert_ms": {
"n": 2000,
"mean": 2.497,
"p50": 2.267,
"p95": 3.945,
"p99": 6.674
},
"history_index_bytes": 37232640,
"table_bytes": 49471488,
"pk_index_bytes": 4374528
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 2.224,
"p95_ms": 4.071,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.249,
"shared_buffers": 6,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 1.837,
"p95_ms": 2.794,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.106,
"shared_buffers": 6,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 1.347,
"p95_ms": 2.536,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.121,
"shared_buffers": 4,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 2.845,
"p95_ms": 5.62,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.112,
"shared_buffers": 7,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 10.613,
"p95_ms": 15.66,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 9.475,
"shared_buffers": 1468,
"rows": 51
}
}
}
},
"C2_chat_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.81,
3.621,
3.556
],
"median": 3.621
},
"single_insert_ms": {
"n": 2000,
"mean": 1.942,
"p50": 1.847,
"p95": 2.499,
"p99": 3.009
},
"history_index_bytes": 7200768,
"table_bytes": 49471488,
"pk_index_bytes": 4358144
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 1.327,
"p95_ms": 1.95,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.071,
"shared_buffers": 6,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 1.861,
"p95_ms": 2.543,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.09,
"shared_buffers": 9,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 1.095,
"p95_ms": 1.511,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 0.262,
"shared_buffers": 5,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 1.564,
"p95_ms": 2.092,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.075,
"shared_buffers": 12,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 62.262,
"p95_ms": 89.574,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 81.055,
"shared_buffers": 6127,
"rows": 51
}
}
}
},
"C1_chat_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
5.229,
3.858,
3.608
],
"median": 3.858
},
"single_insert_ms": {
"n": 2000,
"mean": 2.301,
"p50": 2.258,
"p95": 2.911,
"p99": 3.367
},
"history_index_bytes": 892928,
"table_bytes": 49471488,
"pk_index_bytes": 4399104
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 17.321,
"p95_ms": 21.988,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 22.421,
"shared_buffers": 6127,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 16.562,
"p95_ms": 21.11,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 14.295,
"shared_buffers": 3142,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 1.417,
"p95_ms": 1.895,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 0.136,
"shared_buffers": 4,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 2.429,
"p95_ms": 3.066,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 0.556,
"shared_buffers": 92,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 77.773,
"p95_ms": 114.858,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 69.741,
"shared_buffers": 6127,
"rows": 51
}
}
}
},
"C0_pk_only": {
"ddl": null,
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
3.645,
3.652,
3.632
],
"median": 3.645
},
"single_insert_ms": {
"n": 2000,
"mean": 1.889,
"p50": 1.822,
"p95": 2.427,
"p99": 2.731
},
"history_index_bytes": 0,
"table_bytes": 49471488,
"pk_index_bytes": 4366336
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 18.452,
"p95_ms": 21.713,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 20.771,
"shared_buffers": 6127,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 18.306,
"p95_ms": 21.371,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 16.318,
"shared_buffers": 6069,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 14.635,
"p95_ms": 16.207,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 12.85,
"shared_buffers": 6039,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 17.253,
"p95_ms": 19.007,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 15.036,
"shared_buffers": 6039,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 68.051,
"p95_ms": 73.12,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 49.273,
"shared_buffers": 6127,
"rows": 51
}
}
}
}
}
}
+505
View File
@@ -0,0 +1,505 @@
{
"environment": {
"postgres": "16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)",
"shared_buffers": "128MB",
"work_mem": "4MB",
"fsync": "on",
"synchronous_commit": "on",
"cpus": 1,
"python": "3.12.3",
"platform": "Linux-6.18.44-fc-v114-x86_64-with-glibc2.39"
},
"dataset": {
"messages": 100000,
"chats": 563,
"chat_size_distribution": {
"50000": 1,
"20000": 1,
"10000": 1,
"1000": 10,
"100": 50,
"10": 500
},
"text_length_chars": "10..400 (равномерно)",
"page_size": 50,
"read_runs": 300,
"warmup": 20,
"single_inserts": 2000,
"bulk_repeats": 3,
"order": "reverse"
},
"configs": {
"C4_global_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.193,
1.12,
1.154
],
"median": 1.154
},
"single_insert_ms": {
"n": 2000,
"mean": 0.683,
"p50": 0.631,
"p95": 1.128,
"p99": 1.724
},
"history_index_bytes": 5185536,
"table_bytes": 49528832,
"pk_index_bytes": 4423680
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 2.973,
"p95_ms": 3.433,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 1.295,
"shared_buffers": 5505,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 0.38,
"p95_ms": 0.561,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.044,
"shared_buffers": 8,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 25.688,
"p95_ms": 44.275,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 15.299,
"shared_buffers": 6046,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.505,
"p95_ms": 0.915,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.18,
"shared_buffers": 669,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 41.86,
"p95_ms": 61.732,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 76.728,
"shared_buffers": 6134,
"rows": 51
}
}
}
},
"C3_covering_include": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id) INCLUDE (sender_id, text)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.276,
1.46,
1.42
],
"median": 1.42
},
"single_insert_ms": {
"n": 2000,
"mean": 0.567,
"p50": 0.507,
"p95": 0.923,
"p99": 1.459
},
"history_index_bytes": 38543360,
"table_bytes": 49528832,
"pk_index_bytes": 4431872
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 0.212,
"p95_ms": 0.399,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.032,
"shared_buffers": 7,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 0.329,
"p95_ms": 0.613,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.029,
"shared_buffers": 6,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.08,
"p95_ms": 0.133,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.016,
"shared_buffers": 4,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.327,
"p95_ms": 0.551,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.039,
"shared_buffers": 6,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 4.339,
"p95_ms": 7.16,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 7.172,
"shared_buffers": 1468,
"rows": 51
}
}
}
},
"C2_chat_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.25,
1.182,
1.198
],
"median": 1.198
},
"single_insert_ms": {
"n": 2000,
"mean": 0.813,
"p50": 0.758,
"p95": 1.324,
"p99": 2.348
},
"history_index_bytes": 7487488,
"table_bytes": 49528832,
"pk_index_bytes": 4423680
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 0.214,
"p95_ms": 0.29,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.033,
"shared_buffers": 7,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 0.326,
"p95_ms": 0.596,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.048,
"shared_buffers": 9,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.121,
"p95_ms": 0.293,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.025,
"shared_buffers": 6,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.297,
"p95_ms": 0.561,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.031,
"shared_buffers": 8,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 40.25,
"p95_ms": 54.269,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 96.889,
"shared_buffers": 6139,
"rows": 51
}
}
}
},
"C1_chat_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.408,
1.338,
1.259
],
"median": 1.338
},
"single_insert_ms": {
"n": 2000,
"mean": 0.609,
"p50": 0.573,
"p95": 0.947,
"p99": 1.226
},
"history_index_bytes": 876544,
"table_bytes": 49528832,
"pk_index_bytes": 4415488
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 8.119,
"p95_ms": 13.049,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 31.511,
"shared_buffers": 6134,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 8.103,
"p95_ms": 15.315,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 17.174,
"shared_buffers": 3151,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.144,
"p95_ms": 0.229,
"plan": {
"nodes": [
"Index Scan",
"Sort",
"Limit"
],
"execution_ms": 0.037,
"shared_buffers": 5,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.642,
"p95_ms": 0.925,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 0.363,
"shared_buffers": 90,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 36.041,
"p95_ms": 48.493,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 79.39,
"shared_buffers": 6134,
"rows": 51
}
}
}
},
"C0_pk_only": {
"ddl": null,
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
0.963,
1.098,
1.406
],
"median": 1.098
},
"single_insert_ms": {
"n": 2000,
"mean": 0.944,
"p50": 0.847,
"p95": 1.616,
"p99": 2.599
},
"history_index_bytes": 0,
"table_bytes": 49528832,
"pk_index_bytes": 4415488
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 26.853,
"p95_ms": 44.262,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 33.108,
"shared_buffers": 6134,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 33.107,
"p95_ms": 46.562,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 32.472,
"shared_buffers": 6076,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 16.6,
"p95_ms": 24.988,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 14.32,
"shared_buffers": 6046,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 21.05,
"p95_ms": 33.296,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 18.585,
"shared_buffers": 6046,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 45.405,
"p95_ms": 66.359,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 82.673,
"shared_buffers": 6134,
"rows": 51
}
}
}
}
}
}
+504
View File
@@ -0,0 +1,504 @@
{
"environment": {
"postgres": "16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)",
"shared_buffers": "128MB",
"work_mem": "4MB",
"fsync": "on",
"synchronous_commit": "on",
"cpus": 1,
"python": "3.12.3",
"platform": "Linux-6.18.44-fc-v114-x86_64-with-glibc2.39"
},
"dataset": {
"messages": 100000,
"chats": 563,
"chat_size_distribution": {
"50000": 1,
"20000": 1,
"10000": 1,
"1000": 10,
"100": 50,
"10": 500
},
"text_length_chars": "10..400 (равномерно)",
"page_size": 50,
"read_runs": 300,
"warmup": 20,
"single_inserts": 2000,
"bulk_repeats": 3
},
"configs": {
"C0_pk_only": {
"ddl": null,
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.249,
1.182,
1.17
],
"median": 1.182
},
"single_insert_ms": {
"n": 2000,
"mean": 0.809,
"p50": 0.696,
"p95": 1.625,
"p99": 3.319
},
"history_index_bytes": 0,
"table_bytes": 49446912,
"pk_index_bytes": 4644864
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 19.011,
"p95_ms": 29.257,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 39.274,
"shared_buffers": 6124,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 36.202,
"p95_ms": 49.585,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 31.905,
"shared_buffers": 6066,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 14.85,
"p95_ms": 25.226,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 18.925,
"shared_buffers": 6036,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 36.263,
"p95_ms": 52.683,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 30.508,
"shared_buffers": 6036,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 47.972,
"p95_ms": 66.037,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 72.734,
"shared_buffers": 6124,
"rows": 51
}
}
}
},
"C1_chat_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.345,
1.301,
1.366
],
"median": 1.345
},
"single_insert_ms": {
"n": 2000,
"mean": 1.21,
"p50": 0.944,
"p95": 2.856,
"p99": 5.362
},
"history_index_bytes": 925696,
"table_bytes": 49446912,
"pk_index_bytes": 4636672
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 16.093,
"p95_ms": 22.986,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 45.496,
"shared_buffers": 6124,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 11.782,
"p95_ms": 20.282,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 21.566,
"shared_buffers": 3140,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.157,
"p95_ms": 0.32,
"plan": {
"nodes": [
"Index Scan",
"Sort",
"Limit"
],
"execution_ms": 0.04,
"shared_buffers": 5,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.676,
"p95_ms": 1.21,
"plan": {
"nodes": [
"Bitmap Index Scan",
"Bitmap Heap Scan",
"Sort",
"Limit"
],
"execution_ms": 0.296,
"shared_buffers": 88,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 37.922,
"p95_ms": 51.332,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 82.629,
"shared_buffers": 6124,
"rows": 51
}
}
}
},
"C2_chat_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.245,
1.246,
1.339
],
"median": 1.246
},
"single_insert_ms": {
"n": 2000,
"mean": 0.755,
"p50": 0.709,
"p95": 1.219,
"p99": 1.725
},
"history_index_bytes": 8085504,
"table_bytes": 49446912,
"pk_index_bytes": 4653056
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 0.446,
"p95_ms": 0.916,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.059,
"shared_buffers": 7,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 0.476,
"p95_ms": 0.899,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.054,
"shared_buffers": 9,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.153,
"p95_ms": 0.317,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.034,
"shared_buffers": 6,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.245,
"p95_ms": 0.556,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.033,
"shared_buffers": 9,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 38.956,
"p95_ms": 53.771,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 97.936,
"shared_buffers": 6124,
"rows": 51
}
}
}
},
"C3_covering_include": {
"ddl": "CREATE INDEX hist_idx ON messages (chat_id, created_at, id) INCLUDE (sender_id, text)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.752,
1.604,
1.581
],
"median": 1.604
},
"single_insert_ms": {
"n": 2000,
"mean": 0.51,
"p50": 0.457,
"p95": 0.844,
"p99": 1.189
},
"history_index_bytes": 41484288,
"table_bytes": 49446912,
"pk_index_bytes": 4644864
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 0.482,
"p95_ms": 0.591,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.029,
"shared_buffers": 6,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 0.253,
"p95_ms": 0.484,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.031,
"shared_buffers": 6,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 0.08,
"p95_ms": 0.163,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.017,
"shared_buffers": 4,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.238,
"p95_ms": 0.433,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 0.03,
"shared_buffers": 7,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 4.709,
"p95_ms": 7.598,
"plan": {
"nodes": [
"Index Only Scan",
"Limit"
],
"execution_ms": 7.275,
"shared_buffers": 1472,
"rows": 51
}
}
}
},
"C4_global_created_id": {
"ddl": "CREATE INDEX hist_idx ON messages (created_at, id)",
"writes": {
"bulk_insert_100k_seconds": {
"runs": [
1.459,
1.53,
1.405
],
"median": 1.459
},
"single_insert_ms": {
"n": 2000,
"mean": 0.481,
"p50": 0.411,
"p95": 0.898,
"p99": 1.397
},
"history_index_bytes": 5177344,
"table_bytes": 49446912,
"pk_index_bytes": 4644864
},
"reads": {
"Q1_first_page_giant_50k": {
"p50_ms": 1.572,
"p95_ms": 2.733,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 2.349,
"shared_buffers": 5491,
"rows": 51
}
},
"Q2_deep_keyset_giant_at_40k": {
"p50_ms": 0.479,
"p95_ms": 0.685,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.05,
"shared_buffers": 8,
"rows": 51
}
},
"Q3_first_page_tiny_10": {
"p50_ms": 33.156,
"p95_ms": 51.981,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Limit"
],
"execution_ms": 16.027,
"shared_buffers": 6036,
"rows": 10
}
},
"Q4_keyset_mid_1k_at_500": {
"p50_ms": 0.418,
"p95_ms": 0.688,
"plan": {
"nodes": [
"Index Scan",
"Limit"
],
"execution_ms": 0.148,
"shared_buffers": 669,
"rows": 51
}
},
"Q5_OFFSET_40000_giant": {
"p50_ms": 42.816,
"p95_ms": 60.392,
"plan": {
"nodes": [
"Seq Scan",
"Sort",
"Gather Merge",
"Limit"
],
"execution_ms": 84.868,
"shared_buffers": 6124,
"rows": 51
}
}
}
}
}
}
Binary file not shown.
+61
View File
@@ -0,0 +1,61 @@
{
"snapshot_consistent_with_restore": true,
"checks": {
"counts": true,
"messages_md5": true,
"per_chat_counts_md5": true,
"indexes_md5": true,
"constraints_md5": true,
"migrations": true,
"selected_messages": {
"first_overall": true,
"last_overall": true,
"giant_chat_item_15000": true,
"longest_text": true,
"shortest_text": true,
"pseudo_random_by_md5": true
}
},
"rpo_window_observed": {
"messages_lost_in_restore": 500,
"revoked_session_resurrected_in_restore": true
},
"timing_seconds": {
"pg_dump": 0.76,
"pg_restore": 1.34,
"analyze_after_restore": 0.21,
"rto_dump_free_restore_plus_analyze": 1.56
},
"sizes_bytes": {
"source_database": 68688919,
"dump_file": 3615536
},
"counts_at_dump": {
"users": 1,
"chats": 563,
"chat_members": 563,
"messages": 102000,
"sessions": 1
},
"counts_restored": {
"users": 1,
"chats": 563,
"chat_members": 563,
"messages": 102000,
"sessions": 1
},
"counts_source_after_extra_writes": {
"users": 1,
"chats": 563,
"chat_members": 563,
"messages": 102500,
"sessions": 0
},
"restored_plan": {
"first_page_giant": {
"node": "Index Scan",
"index": "messages_chat_created_id_idx",
"execution_ms": 0.066
}
}
}
+8
View File
@@ -0,0 +1,8 @@
# Восстановленная БД (новый сервер :5434) обслуживает приложение
$ python -m app.migrate (на восстановленной БД)
2026-10-15 10:08:21,788 migrate applied: nothing to do (schema is up to date)
$ make test BASE_URL=http://localhost:8082 (API подключён к восстановленной БД, без Valkey)
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
$ python3 tests_student/test_integration.py (против восстановленной БД)
11/11 passed
+23
View File
@@ -0,0 +1,23 @@
# Трек 2: сводка (медианы двух проходов; p50 клиентской латентности, мс)
Данные: 100 000 сообщений + 2 000 одиночных вставок = ~102 000; 563 чата (50k/20k/10k/10×1k/50×100/500×10); PostgreSQL 16.15, 1 CPU, fsync=on.
## Чтение (p50, мс; проход 1 / проход 2)
| Конфигурация | Q1 first_page_giant_50k | Q2 deep_keyset_giant_at_40k | Q3 first_page_tiny_10 | Q4 keyset_mid_1k_at_500 | Q5 OFFSET_40000_giant |
|---|---|---|---|---|---|
| C0_pk_only | 19.01 / 26.85 (Seq, 6124 buf) | 36.20 / 33.11 (Seq, 6066 buf) | 14.85 / 16.60 (Seq, 6036 buf) | 36.26 / 21.05 (Seq, 6036 buf) | 47.97 / 45.41 (Seq, 6124 buf) |
| C1_chat_id | 16.09 / 8.12 (Seq, 6124 buf) | 11.78 / 8.10 (Bitmap Index, 3140 buf) | 0.16 / 0.14 (Index, 5 buf) | 0.68 / 0.64 (Bitmap Index, 88 buf) | 37.92 / 36.04 (Seq, 6124 buf) |
| C2_chat_created_id | 0.45 / 0.21 (Index, 7 buf) | 0.48 / 0.33 (Index, 9 buf) | 0.15 / 0.12 (Index, 6 buf) | 0.24 / 0.30 (Index, 9 buf) | 38.96 / 40.25 (Seq, 6124 buf) |
| C3_covering_include | 0.48 / 0.21 (IdxOnly, 6 buf) | 0.25 / 0.33 (IdxOnly, 6 buf) | 0.08 / 0.08 (IdxOnly, 4 buf) | 0.24 / 0.33 (IdxOnly, 7 buf) | 4.71 / 4.34 (IdxOnly, 1472 buf) |
| C4_global_created_id | 1.57 / 2.97 (Index, 5491 buf) | 0.48 / 0.38 (Index, 8 buf) | 33.16 / 25.69 (Seq, 6036 buf) | 0.42 / 0.51 (Index, 669 buf) | 42.82 / 41.86 (Seq, 6124 buf) |
## Запись и размер
| Конфигурация | bulk 100k, с (п1 / п2) | одиночный INSERT p50, мс (п1 / п2) | p95, мс (п1 / п2) | индекс истории, MiB |
|---|---|---|---|---|
| C0_pk_only | 1.18 / 1.10 | 0.70 / 0.85 | 1.62 / 1.62 | 0.0 |
| C1_chat_id | 1.34 / 1.34 | 0.94 / 0.57 | 2.86 / 0.95 | 0.9 |
| C2_chat_created_id | 1.25 / 1.20 | 0.71 / 0.76 | 1.22 / 1.32 | 7.7 |
| C3_covering_include | 1.60 / 1.42 | 0.46 / 0.51 | 0.84 / 0.92 | 39.6 |
| C4_global_created_id | 1.46 / 1.15 | 0.41 / 0.63 | 0.90 / 1.13 | 4.9 |