Spaces:
Sleeping
Sleeping
Download scripts/performance/locustfile.py from fmbishu/image-search-api: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/fmbishu/image-search-api/resolve/main/scripts/performance/locustfile.py
- Command line
-
hf download hf://spaces/fmbishu/image-search-api/scripts/performance/locustfile.py
-
curl -L -o locustfile.py https://huggingface.co/spaces/fmbishu/image-search-api/resolve/main/scripts/performance/locustfile.py
1.08 kB
| from __future__ import annotations | |
| from locust import HttpUser, between, task | |
| class EcommerceUser(HttpUser): | |
| wait_time = between(0.5, 1.5) | |
| def search_products(self) -> None: | |
| payload = {"query": "red running shoes", "top_k": "10"} | |
| headers = {"Content-Type": "application/x-www-form-urlencoded"} | |
| with self.client.post("/search", data=payload, headers=headers, catch_response=True) as response: | |
| if response.status_code != 200: | |
| response.failure(f"Unexpected status: {response.status_code} - {response.text}") | |
| elif len(response.json().get("results", [])) == 0: | |
| response.failure("Empty search results") | |
| def list_products(self) -> None: | |
| with self.client.get("/products?limit=20&offset=0", catch_response=True) as response: | |
| if response.status_code != 200: | |
| response.failure(f"Unexpected status: {response.status_code}") | |
| # Usage: | |
| # locust -f scripts/performance/locustfile.py --host=http://localhost:8000 --users 50 --spawn-rate 5 | |