Реализация лабораторной 2: PostgreSQL, сессии, Valkey-кэш
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
Timing is on.
|
||||
INSERT 0 1
|
||||
Time: 11.593 ms
|
||||
INSERT 0 1
|
||||
Time: 3.779 ms
|
||||
INSERT 0 1
|
||||
Time: 8.619 ms
|
||||
DO
|
||||
Time: 1353.910 ms (00:01.354)
|
||||
ANALYZE
|
||||
Time: 77.416 ms
|
||||
=== dataset ===
|
||||
messages_in_chat
|
||||
------------------
|
||||
12000
|
||||
(1 row)
|
||||
|
||||
Time: 4.243 ms
|
||||
=== index used by the history query ===
|
||||
indexname | indexdef
|
||||
-------------------------+-----------------------------------------------------------------------------------------------
|
||||
messages_pkey | CREATE UNIQUE INDEX messages_pkey ON public.messages USING btree (id)
|
||||
messages_chat_order_idx | CREATE INDEX messages_chat_order_idx ON public.messages USING btree (chat_id, created_at, id)
|
||||
(2 rows)
|
||||
|
||||
Time: 13.962 ms
|
||||
=== plan: first page (no cursor) ===
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.29..6.36 rows=50 width=73) (actual time=0.025..0.061 rows=50 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_chat_order_idx on messages (cost=0.29..1459.39 rows=12000 width=73) (actual time=0.022..0.048 rows=50 loops=1)
|
||||
Index Cond: (chat_id = '22222222-2222-4222-8222-222222222222'::uuid)
|
||||
Buffers: shared hit=4
|
||||
Planning:
|
||||
Buffers: shared hit=22
|
||||
Planning Time: 0.474 ms
|
||||
Execution Time: 0.165 ms
|
||||
(9 rows)
|
||||
|
||||
Time: 5.762 ms
|
||||
Time: 11.210 ms
|
||||
=== plan: deep keyset page after 10 000 records (what the API sends) ===
|
||||
QUERY PLAN
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.29..15.60 rows=50 width=73) (actual time=0.097..0.133 rows=50 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_chat_order_idx on messages (cost=0.29..769.32 rows=2510 width=73) (actual time=0.095..0.121 rows=50 loops=1)
|
||||
Index Cond: ((chat_id = '22222222-2222-4222-8222-222222222222'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:10.001+00'::timestamp with time zone, 'eab21e64-f0cb-4070-9044-c8c3a2daac6d'::uuid)))
|
||||
Buffers: shared hit=4
|
||||
Planning Time: 0.270 ms
|
||||
Execution Time: 0.208 ms
|
||||
(7 rows)
|
||||
|
||||
Time: 2.785 ms
|
||||
=== comparison: the OFFSET form this API does not use ===
|
||||
QUERY PLAN
|
||||
-------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=1201.12..1201.24 rows=50 width=73) (actual time=13.641..13.660 rows=50 loops=1)
|
||||
Buffers: shared hit=205
|
||||
-> Sort (cost=1176.12..1206.12 rows=12000 width=73) (actual time=11.589..12.757 rows=10050 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: quicksort Memory: 1978kB
|
||||
Buffers: shared hit=205
|
||||
-> Seq Scan on messages (cost=0.00..363.08 rows=12000 width=73) (actual time=0.188..5.317 rows=12000 loops=1)
|
||||
Filter: (chat_id = '22222222-2222-4222-8222-222222222222'::uuid)
|
||||
Rows Removed by Filter: 646
|
||||
Buffers: shared hit=205
|
||||
Planning Time: 0.106 ms
|
||||
Execution Time: 14.005 ms
|
||||
(12 rows)
|
||||
|
||||
Time: 14.848 ms
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 20.0,
|
||||
"elapsed_seconds": 20.5,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 523,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 25.512,
|
||||
"successful_latency_ms": {
|
||||
"p50": 125.0,
|
||||
"p95": 328.0,
|
||||
"p99": 484.0
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
$ python tests/load.py --base-url http://127.0.0.1:8080 --duration 20 --concurrency 4
|
||||
{
|
||||
"lab": 2,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 20.0,
|
||||
"elapsed_seconds": 20.5,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 523,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 25.512,
|
||||
"successful_latency_ms": {
|
||||
"p50": 125.0,
|
||||
"p95": 328.0,
|
||||
"p99": 484.0
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
$ python tests/resilience.py --mode persistence --action-script scripts/restart.cmd --base-url http://127.0.0.1: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.
|
||||
@@ -0,0 +1,2 @@
|
||||
$ python tests/smoke.py --base-url http://127.0.0.1:8080
|
||||
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,34 @@
|
||||
$ BASE_URL=http://127.0.0.1:8080 python -B -m unittest -v test_api test_race
|
||||
test_basic_is_not_accepted_outside_session_creation (test_api.Authentication.test_basic_is_not_accepted_outside_session_creation) ... ok
|
||||
test_logout_revokes_only_that_session (test_api.Authentication.test_logout_revokes_only_that_session) ... ok
|
||||
test_missing_and_unknown_tokens (test_api.Authentication.test_missing_and_unknown_tokens) ... ok
|
||||
test_session_endpoint_rejects_json_body_and_bad_basic (test_api.Authentication.test_session_endpoint_rejects_json_body_and_bad_basic) ... ok
|
||||
test_session_payload_and_expiry (test_api.Authentication.test_session_payload_and_expiry) ... ok
|
||||
test_wrong_password_and_unknown_user_are_indistinguishable (test_api.Authentication.test_wrong_password_and_unknown_user_are_indistinguishable) ... ok
|
||||
test_x_user_id_is_ignored (test_api.Authentication.test_x_user_id_is_ignored) ... ok
|
||||
test_foreign_chat_is_hidden_everywhere (test_api.Chats.test_foreign_chat_is_hidden_everywhere) ... ok
|
||||
test_membership_validation (test_api.Chats.test_membership_validation) ... ok
|
||||
test_messages_are_validated_and_unicode_preserved (test_api.Chats.test_messages_are_validated_and_unicode_preserved) ... ok
|
||||
test_health_endpoints_and_request_id (test_api.HealthAndEnvelope.test_health_endpoints_and_request_id) ... ok
|
||||
test_query_parameters_rejected_where_not_supported (test_api.HealthAndEnvelope.test_query_parameters_rejected_where_not_supported) ... ok
|
||||
test_unknown_route_uses_same_error_envelope (test_api.HealthAndEnvelope.test_unknown_route_uses_same_error_envelope) ... ok
|
||||
test_cursor_is_bound_to_its_chat (test_api.Pagination.test_cursor_is_bound_to_its_chat) ... ok
|
||||
test_limit_and_cursor_validation (test_api.Pagination.test_limit_and_cursor_validation) ... ok
|
||||
test_walks_every_page_without_loss_or_duplicates (test_api.Pagination.test_walks_every_page_without_loss_or_duplicates) ... ok
|
||||
test_duplicate_username_conflict (test_api.Registration.test_duplicate_username_conflict) ... ok
|
||||
test_malformed_json_extra_fields_and_wrong_types (test_api.Registration.test_malformed_json_extra_fields_and_wrong_types) ... ok
|
||||
test_password_rules (test_api.Registration.test_password_rules) ... ok
|
||||
test_response_has_no_secret_fields (test_api.Registration.test_response_has_no_secret_fields) ... ok
|
||||
test_unsupported_media_type (test_api.Registration.test_unsupported_media_type) ... ok
|
||||
test_username_rules (test_api.Registration.test_username_rules) ... ok
|
||||
test_100_messages_from_10_clients_are_exactly_100 (test_race.ConcurrentWrites.test_100_messages_from_10_clients_are_exactly_100) ...
|
||||
concurrent writes: 100 messages from 10 clients in 3.08s
|
||||
ok
|
||||
test_bounded_pool_serves_parallel_reads (test_race.ConcurrentWrites.test_bounded_pool_serves_parallel_reads) ... ok
|
||||
test_chat_creation_rolls_back_on_unknown_member (test_race.ConcurrentWrites.test_chat_creation_rolls_back_on_unknown_member) ... ok
|
||||
test_duplicate_username_race_creates_one_user (test_race.ConcurrentWrites.test_duplicate_username_race_creates_one_user) ... ok
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 26 tests in 14.846s
|
||||
|
||||
OK
|
||||
@@ -0,0 +1,9 @@
|
||||
$ BASE_URL=http://127.0.0.1:8080 STUDENT_DOCKER_TESTS=1 python -B -m unittest -v test_degradation
|
||||
test_valkey_loss_degrades_then_postgres_loss_is_bounded (test_degradation.DependencyOutages.test_valkey_loss_degrades_then_postgres_loss_is_bounded) ...
|
||||
outage summary: {"cached_p50_ms": 16.0, "cache_down_p50_ms": 39.0, "cache_down_p95_ms": 78.0, "db_down_write_seconds": 2.05, "recovery_seconds": 0.58}
|
||||
ok
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 1 test in 21.384s
|
||||
|
||||
OK
|
||||
@@ -0,0 +1,66 @@
|
||||
$ PYTHON=python sh scripts/test-ttl.sh
|
||||
Volume mtusi-lab2-ttl_pgdata Creating
|
||||
Network mtusi-lab2-ttl_backend Creating
|
||||
Volume mtusi-lab2-ttl_valkeydata Creating
|
||||
Volume mtusi-lab2-ttl_pgdata Creating
|
||||
Network mtusi-lab2-ttl_backend Creating
|
||||
Volume mtusi-lab2-ttl_valkeydata Creating
|
||||
Volume mtusi-lab2-ttl_valkeydata Created
|
||||
Volume mtusi-lab2-ttl_valkeydata Created
|
||||
Volume mtusi-lab2-ttl_pgdata Created
|
||||
Volume mtusi-lab2-ttl_pgdata Created
|
||||
Network mtusi-lab2-ttl_backend Created
|
||||
Network mtusi-lab2-ttl_backend Created
|
||||
Container mtusi-lab2-ttl-valkey-1 Creating
|
||||
Container mtusi-lab2-ttl-postgres-1 Creating
|
||||
Container mtusi-lab2-ttl-valkey-1 Created
|
||||
Container mtusi-lab2-ttl-postgres-1 Created
|
||||
Container mtusi-lab2-ttl-api-1 Creating
|
||||
Container mtusi-lab2-ttl-api-1 Created
|
||||
Container mtusi-lab2-ttl-postgres-1 Starting
|
||||
Container mtusi-lab2-ttl-valkey-1 Starting
|
||||
Container mtusi-lab2-ttl-postgres-1 Started
|
||||
Container mtusi-lab2-ttl-valkey-1 Started
|
||||
Container mtusi-lab2-ttl-valkey-1 Waiting
|
||||
Container mtusi-lab2-ttl-postgres-1 Waiting
|
||||
Container mtusi-lab2-ttl-valkey-1 Healthy
|
||||
Container mtusi-lab2-ttl-postgres-1 Healthy
|
||||
Container mtusi-lab2-ttl-api-1 Starting
|
||||
Container mtusi-lab2-ttl-api-1 Started
|
||||
Container mtusi-lab2-ttl-api-1 Waiting
|
||||
Container mtusi-lab2-ttl-postgres-1 Waiting
|
||||
Container mtusi-lab2-ttl-valkey-1 Waiting
|
||||
Container mtusi-lab2-ttl-postgres-1 Healthy
|
||||
Container mtusi-lab2-ttl-valkey-1 Healthy
|
||||
Container mtusi-lab2-ttl-api-1 Healthy
|
||||
ttl_stack_ready base_url=http://127.0.0.1:8081 session_ttl_seconds=2
|
||||
test_expiry_is_enforced_and_cache_does_not_extend_it (test_expiry.ShortTtlSessions.test_expiry_is_enforced_and_cache_does_not_extend_it) ... ok
|
||||
test_logout_is_immediate_even_when_the_session_is_cached (test_expiry.ShortTtlSessions.test_logout_is_immediate_even_when_the_session_is_cached) ... ok
|
||||
test_session_lookup_latency_is_bounded (test_expiry.ShortTtlSessions.test_session_lookup_latency_is_bounded) ... ok
|
||||
test_wrong_password_issues_no_session (test_expiry.ShortTtlSessions.test_wrong_password_issues_no_session) ... ok
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 4 tests in 6.121s
|
||||
|
||||
OK
|
||||
|
||||
/users/me warm cache p50=16.0ms p95=16.0ms
|
||||
Container mtusi-lab2-ttl-api-1 Stopping
|
||||
Container mtusi-lab2-ttl-api-1 Stopped
|
||||
Container mtusi-lab2-ttl-api-1 Removing
|
||||
Container mtusi-lab2-ttl-api-1 Removed
|
||||
Container mtusi-lab2-ttl-valkey-1 Stopping
|
||||
Container mtusi-lab2-ttl-postgres-1 Stopping
|
||||
Container mtusi-lab2-ttl-valkey-1 Stopped
|
||||
Container mtusi-lab2-ttl-valkey-1 Removing
|
||||
Container mtusi-lab2-ttl-valkey-1 Removed
|
||||
Container mtusi-lab2-ttl-postgres-1 Stopped
|
||||
Container mtusi-lab2-ttl-postgres-1 Removing
|
||||
Container mtusi-lab2-ttl-postgres-1 Removed
|
||||
Network mtusi-lab2-ttl_backend Removing
|
||||
Volume mtusi-lab2-ttl_pgdata Removing
|
||||
Volume mtusi-lab2-ttl_valkeydata Removing
|
||||
Volume mtusi-lab2-ttl_valkeydata Removed
|
||||
Volume mtusi-lab2-ttl_pgdata Removed
|
||||
Network mtusi-lab2-ttl_backend Removed
|
||||
ttl_stack_removed
|
||||
Reference in New Issue
Block a user