Spaces:
Sleeping
Sleeping
Download load_test_sync.py from Sathvik-kota/proto: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/Sathvik-kota/proto/resolve/main/load_test_sync.py
- Command line
-
hf download hf://spaces/Sathvik-kota/proto/load_test_sync.py
-
curl -L -o load_test_sync.py https://huggingface.co/spaces/Sathvik-kota/proto/resolve/main/load_test_sync.py
1.48 kB
| import asyncio | |
| import aiohttp | |
| import time | |
| import random | |
| # ๐น Replace with your Hugging Face Space URL | |
| ORCHESTRATOR_URL = "http://127.0.0.1:8000/ticket" | |
| # If running locally: | |
| # ORCHESTRATOR_URL = "http://127.0.0.1:8000/ticket" | |
| # 25 random payloads to simulate user tickets | |
| payloads = [ | |
| { | |
| "channel": "web", | |
| "severity": "high", | |
| "summary": f"Test orchestrator ticket #{i}" | |
| } | |
| for i in range(10) | |
| ] | |
| async def send_request(session, idx, payload): | |
| start = time.time() | |
| try: | |
| async with session.post(ORCHESTRATOR_URL, json=payload) as resp: | |
| elapsed = time.time() - start | |
| print(f"#{idx} โ Status: {resp.status}, Time: {elapsed:.2f}s") | |
| return resp.status, elapsed | |
| except Exception as e: | |
| print(f"#{idx} โ Failed: {e}") | |
| return None, 0 | |
| async def main(): | |
| print("๐ Sending 16 concurrent requests to ORCHESTRATOR...\n") | |
| start_time = time.time() | |
| async with aiohttp.ClientSession() as session: | |
| tasks = [send_request(session, i, payloads[i]) for i in range(len(payloads))] | |
| results = await asyncio.gather(*tasks) | |
| total_time = time.time() - start_time | |
| success = sum(1 for s, _ in results if s == 200) | |
| avg_time = sum(t for _, t in results if t > 0) / len(results) | |
| print(f"\nโ Done! Success: {success}/{len(results)} | Avg Time: {avg_time:.2f}s | Total Duration: {total_time:.2f}s") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |