This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Доказывает корректное чтение после restart Redis."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
||||
from client import Client, check, run # noqa: E402
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
client = Client()
|
||||
alice, _bob, _eve, chat = client.bootstrap()
|
||||
message = client.message(alice, chat, "survives Redis restart")["json"]
|
||||
path = "/api/v1/chats/" + chat["id"] + "/messages?limit=100"
|
||||
before = client.call("GET", path, actor=alice, schema="MessagePage")["json"]
|
||||
check(before["items"] == [message], "initial cache fill failed")
|
||||
subprocess.run(["docker", "compose", "restart", "redis"], cwd=ROOT, check=True)
|
||||
time.sleep(1)
|
||||
after = client.call("GET", path, actor=alice, schema="MessagePage")["json"]
|
||||
check(after["items"] == [message], "history changed after Redis restart")
|
||||
print("PASS: history remains correct after Redis restart")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Одновременное чтение холодной первой страницы истории."""
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
import json
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
||||
from client import Client, check, run # noqa: E402
|
||||
|
||||
|
||||
def main() -> None:
|
||||
concurrency = 20
|
||||
client = Client()
|
||||
alice, _bob, _eve, chat = client.bootstrap()
|
||||
created = client.message(alice, chat, "cold-cache message")["json"]
|
||||
path = "/api/v1/chats/" + chat["id"] + "/messages?limit=1"
|
||||
barrier = threading.Barrier(concurrency)
|
||||
|
||||
def read_page(_worker: int) -> float:
|
||||
local = Client()
|
||||
barrier.wait()
|
||||
started = time.monotonic()
|
||||
response = local.call("GET", path, actor=alice, schema="MessagePage")["json"]
|
||||
check(response["items"] == [created], "cold-page response differs")
|
||||
return time.monotonic() - started
|
||||
|
||||
with ThreadPoolExecutor(max_workers=concurrency) as pool:
|
||||
latencies = list(pool.map(read_page, range(concurrency)))
|
||||
ordered = sorted(latencies)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"chat_id": chat["id"],
|
||||
"concurrency": concurrency,
|
||||
"successful_reads": len(latencies),
|
||||
"latency_ms": {
|
||||
"p50": round(1000 * ordered[(concurrency - 1) // 2], 3),
|
||||
"p95": round(1000 * ordered[18], 3),
|
||||
"max": round(1000 * ordered[-1], 3),
|
||||
},
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
Reference in New Issue
Block a user