forked from mtusi2026/mtusi2026lab4
38 lines
827 B
Python
38 lines
827 B
Python
#!/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() |