forked from mtusi2026/mtusi2026lab2
Исправление по замечанию: кэш сессий наполняется после промаха
This commit is contained in:
+36
-36
@@ -7,7 +7,7 @@ valkey valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682f
|
||||
=== Засев 10000 сообщений с неравномерными чатами ===
|
||||
seed_duration | seeded_rows | target_total | messages_total
|
||||
-----------------+-------------+--------------+----------------
|
||||
00:00:00.001309 | 0 | 10000 | 53764
|
||||
00:00:00.000975 | 0 | 10000 | 52887
|
||||
(1 row)
|
||||
|
||||
|
||||
@@ -19,70 +19,70 @@ valkey valkey/valkey:8.1-alpine@sha256:081c2f5cb575efc901aa80ff9cdbd1ec6a301682f
|
||||
|
||||
messages_total | chats_with_messages | table_size | indexes_size
|
||||
----------------+---------------------+------------+--------------
|
||||
53764 | 14 | 5368 kB | 6320 kB
|
||||
52887 | 14 | 5280 kB | 7024 kB
|
||||
(1 row)
|
||||
|
||||
--- распределение истории по чатам: 5 самых больших и 5 самых маленьких ---
|
||||
chat_id | rows
|
||||
--------------------------------------+-------
|
||||
e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32 | 32944
|
||||
c995246c-35ed-422d-b097-c71f8829a0e0 | 20775
|
||||
d73dc509-7b93-4fc3-b6de-b7079bcc294f | 25
|
||||
7485e75e-455e-4a7b-b164-3dbc84099fc0 | 5
|
||||
63d536a7-78d4-4502-92fa-9bbac4e7c5c4 | 3
|
||||
174a0477-1fd5-47a9-ab90-ee8b7ef903af | 36305
|
||||
fb87d20c-528a-4bb7-9cd5-e1d4486bdfca | 16537
|
||||
3e751b33-08b7-4433-a2be-bb355af7bf62 | 25
|
||||
11bd8f2b-db27-4c63-89f0-469ee53c6cad | 5
|
||||
30e5554f-e2e0-411e-b5bd-ab86e1fd9c5f | 3
|
||||
(5 rows)
|
||||
|
||||
chat_id | rows
|
||||
--------------------------------------+------
|
||||
143b0ced-4c1a-4742-a4ad-02c4b606ba0f | 1
|
||||
b4faa937-91fc-4f41-b25e-f3f692878c1f | 1
|
||||
84d473db-544b-4a24-995b-43a4852c68ab | 1
|
||||
574fc146-1610-484a-85a9-cb084afa7d28 | 1
|
||||
836ed5bf-8ccb-419e-96d5-2c4fe7342292 | 1
|
||||
b490286c-39b8-4940-92cf-23817def915a | 1
|
||||
6fc32369-98df-4387-b07f-00dfa6e0b391 | 1
|
||||
f4c1fdcc-0ddd-4fb5-a962-c8901deac9e2 | 1
|
||||
903d0035-1bda-4ac6-9fbf-52f28fe0b94c | 1
|
||||
fb6df905-d5d2-4300-b74f-1f0196f9e2b0 | 1
|
||||
(5 rows)
|
||||
|
||||
--- A. keyset, первая страница самого большого чата ---
|
||||
QUERY PLAN
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.41..6.89 rows=50 width=67) (actual time=0.006..0.016 rows=50 loops=1)
|
||||
Buffers: shared hit=24
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..4269.16 rows=32968 width=67) (actual time=0.006..0.014 rows=50 loops=1)
|
||||
Index Cond: (chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid)
|
||||
Buffers: shared hit=24
|
||||
Limit (cost=0.41..5.46 rows=50 width=67) (actual time=0.005..0.011 rows=50 loops=1)
|
||||
Buffers: shared hit=21
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3662.26 rows=36288 width=67) (actual time=0.005..0.009 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Buffers: shared hit=21
|
||||
Planning:
|
||||
Buffers: shared hit=6
|
||||
Planning Time: 0.046 ms
|
||||
Execution Time: 0.026 ms
|
||||
Buffers: shared hit=8
|
||||
Planning Time: 0.049 ms
|
||||
Execution Time: 0.018 ms
|
||||
(9 rows)
|
||||
|
||||
--- B. keyset, страница на глубине 90% истории (так работает cursor API) ---
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.41..11.51 rows=50 width=67) (actual time=0.017..0.025 rows=50 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3272.65 rows=14746 width=67) (actual time=0.017..0.023 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid) AND (ROW(created_at, id) > ROW('2026-10-19 15:51:38.025965+00'::timestamp with time zone, '0375fd16-e024-4391-93a5-0d5a1a21786d'::uuid)))
|
||||
Buffers: shared hit=53
|
||||
Planning Time: 0.027 ms
|
||||
Execution Time: 0.063 ms
|
||||
Limit (cost=0.41..8.17 rows=50 width=67) (actual time=0.006..0.014 rows=50 loops=1)
|
||||
Buffers: shared hit=54
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..2148.72 rows=13857 width=67) (actual time=0.005..0.012 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid) AND (ROW(created_at, id) > ROW('2026-10-23 14:37:21.481035+00'::timestamp with time zone, 'b34cffc1-608f-4281-89b6-d598a0000a8d'::uuid)))
|
||||
Buffers: shared hit=54
|
||||
Planning Time: 0.022 ms
|
||||
Execution Time: 0.034 ms
|
||||
(7 rows)
|
||||
|
||||
--- C. OFFSET на той же глубине (так API не делает: цена растёт со страницей) ---
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=3839.41..3845.89 rows=50 width=67) (actual time=4.152..4.159 rows=50 loops=1)
|
||||
Buffers: shared hit=29813
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..4269.16 rows=32968 width=67) (actual time=0.008..3.474 rows=29699 loops=1)
|
||||
Index Cond: (chat_id = 'e8b55eec-ce6b-4cc4-9003-e6f1f33ddd32'::uuid)
|
||||
Buffers: shared hit=29813
|
||||
Planning Time: 0.018 ms
|
||||
Execution Time: 4.172 ms
|
||||
Limit (cost=3297.57..3302.61 rows=50 width=67) (actual time=4.132..4.139 rows=50 loops=1)
|
||||
Buffers: shared hit=33082
|
||||
-> Index Scan using messages_history_idx on messages (cost=0.41..3662.26 rows=36288 width=67) (actual time=0.012..3.519 rows=32724 loops=1)
|
||||
Index Cond: (chat_id = '174a0477-1fd5-47a9-ab90-ee8b7ef903af'::uuid)
|
||||
Buffers: shared hit=33082
|
||||
Planning Time: 0.020 ms
|
||||
Execution Time: 4.146 ms
|
||||
(7 rows)
|
||||
|
||||
--- индексы таблицы messages ---
|
||||
index | size | scans
|
||||
----------------------+---------+-------
|
||||
messages_history_idx | 4072 kB | 12
|
||||
messages_pkey | 2248 kB | 0
|
||||
messages_history_idx | 4720 kB | 12
|
||||
messages_pkey | 2304 kB | 0
|
||||
(2 rows)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user