Балансировка, реплики, идемпотентность

This commit is contained in:
Queenfish
2026-10-16 01:07:34 +03:00
parent 0ab3a341aa
commit cb11011869
59 changed files with 3916 additions and 27 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
import threading
import time
import uuid
from collections import Counter
import httpx
BASE = "http://localhost:8080"
def main():
counter = Counter()
lock = threading.Lock()
def worker():
with httpx.Client(timeout=5) as c:
for _ in range(20):
try:
r = c.get(f"{BASE}/health/live")
if r.status_code == 200:
with lock:
counter[r.headers.get("x-instance-id")] += 1
except Exception:
pass
time.sleep(0.05)
threads = [threading.Thread(target=worker) for _ in range(20)]
for t in threads:
t.start()
for t in threads:
t.join()
print(counter)
if __name__ == "__main__":
main()